Archived Legacy DynamicHUD
  • Dynamic HUD
  • Import using Gradle
  • Widgets
    • Adding Widgets
      • TextWidget
      • ItemWidget
      • ArmorWidget
    • Creating your own Widget class
    • Widget class
    • WidgetManager
    • WidgetBox
  • Saving and Loading
    • Saving and Loading
    • Changing save file name and directory
  • Moveable Screen
    • AbstractMoveableScreen
    • Default Moveable Screen
    • Using the default Moveable Screen
    • Creating and using your own MoveableScreen class
  • ContextMenu
    • ContextMenu class
    • ContextMenuOptionsProvider interface
    • DoubleInputScreen
    • DataInputScreen
  • Slider Widget
    • Slider
  • SliderWidgetBuilder
  • ColorPicker
    • ColorGradientPicker
      • ColorPickerButton
      • GradientBox
      • GradientSlider
  • Helpers
    • ColorHelper
    • DrawHelper
    • TextureHelper
Powered by GitBook
On this page
  1. Moveable Screen

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:

public class MyScreen extends AbstractMoveableScreen {
    public MyScreen(Text title, DynamicUtil dynamicutil) {
        super(title, dynamicutil);
    }

    @Override
    protected boolean handleRightClickOnWidget(Widget widget) {
        // Handle right-clicks on widgets here such as opening the menu
        /*
        Example:
        int x=widget.getX();
        int y=widget.getY();
        menu(widget,x,y);
        */
        return false;
    }

    @Override
    protected void menu(Widget widget, int x, int y) {
        // Display a context menu for the widget here

    }
}

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:

DynamicHUD.setAbstractScreen(new MyScreen(text,dynamicutil));

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:

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    super.render(matrices, mouseX, mouseY, delta);

    // Add custom rendering code here
}

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.

PreviousUsing the default Moveable ScreenNextContextMenu class