Widgets Overview
Widgets (IWidget) are the interactive elements of your GUI. While Components handle visuals and layout, Widgets handle User Input (clicks, typing, focus, and narration).
In UI Lib, standard Minecraft widgets (like Button, EditBox, CycleButton) are fully compatible, but they are enhanced via the IWidget interface.
The IWidget Interface
This interface combines four key vanilla interfaces into one:
Renderable: Can be drawn to the screen.GuiEventListener: Receives mouse and keyboard events.LayoutElement: Has a position and size (ScreenRectangle).NarratableEntry: Supports the text-to-speech narrator for accessibility.
Relative Positioning Magic
Standard Minecraft widgets usually rely on absolute X/Y coordinates (e.g., x=100, y=50). This makes nesting them inside other components difficult.
UI Lib uses a Mixin (AbstractWidgetMixin) to inject relative positioning logic into every widget class that implements IWidget (or extends AbstractWidget).
uilib$getParentX(): The absolute X position of the container holding this widget.getX()(Modified): Returnsthis.x + parentX.
You don't need to manually calculate screen coordinates. If you add a button at x=10, y=10 inside a Component located at x=50, y=50, the button will automatically render and detect clicks at 60, 60.
Adding Widgets
Always use the addWidget(...) method provided by AbstractScreen or AbstractComponent.
// Correct
this.addWidget(new ButtonWidget(...));
// Incorrect - Input listeners won't be registered!
this.renderables.add(new ButtonWidget(...));
This ensures the widget is added to the screen's event listener list, narration list, and render list simultaneously.