Creating and using your own MoveableScreen class
This page talks about creating your own screen class by extending the AbstractMoveableScreen class
You first need to create a new class and extend AbstractMoveableScreen
. This will allow you to use the functionality provided by the AbstractMoveableScreen
class, such as handling mouse dragging, mouse release, and mouse clicks, as well as rendering widgets on the screen.
Here’s an example of a new screen class that extends AbstractMoveableScreen
:
In this example, we create a new class called MyScreen
that extends AbstractMoveableScreen
. We override the handleRightClickOnWidget
and menu
methods to provide custom behavior for handling right-clicks on widgets and displaying context menus for widgets.
Once you have created your new screen class, you can use it in your Minecraft Fabric mod's main class by creating an instance of it and displaying it on the screen. For example:
This code creates a new instance of the MyScreen
class with the title “My Screen” and the given dynamicutil instance, and displays it on the screen.
You can also use the different methods provided by the AbstractMoveableScreen
class in your new screen class. For example, you can override the render
method to provide custom rendering behavior for your screen:
In this example, we override the render
method and call the superclass’s implementation of this method to render the widgets on the screen. Then, we add custom rendering code to draw additional content on the screen.