java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.Widget
com.ultikits.ultitools.abstracts.gui.declarative.core.StatelessWidget

public abstract class StatelessWidget extends Widget
StatelessWidget is a Widget that needs no mutable state.

It builds the UI entirely from the configuration parameters supplied at construction time. When the configuration changes, a new StatelessWidget instance is created, and the framework automatically diffs and updates whatever needs to change.

When to use it:

  • purely presentational UI (e.g. titles, icons, static text)
  • UI whose state is entirely controlled by its parent Widget
  • side-effect-free, purely functional components

Usage example:


 public class ItemRow extends StatelessWidget {
     private final ItemStack item;
     private final String name;
     private final Runnable onClick;
     
     public ItemRow(ItemStack item, String name, Runnable onClick) {
         this.item = item;
         this.name = name;
         this.onClick = onClick;
     }
     
     @Override
     public Widget build(BuildContext context) {
         return Row.builder()
             .children(
                 ItemDisplay.builder(item).build(),
                 TextButton.builder()
                     .text(name)
                     .onClick(onClick)
                     .build()
             )
             .build();
     }
 }
 
Since:
6.2.0
Version:
1.0.0
Author:
UltiTools Team
See Also:
  • Constructor Details

    • StatelessWidget

      protected StatelessWidget()
      Creates a new StatelessWidget.
    • StatelessWidget

      protected StatelessWidget(SlotKey key)
      Creates a new StatelessWidget with the given key.
      Parameters:
      key - the key used to stably identify this Widget
  • Method Details

    • build

      @NotNull public abstract @NotNull Widget build(@NotNull @NotNull BuildContext context)
      Builds this Widget's subtree.

      This method is called:

      • when the Widget is first created
      • when the parent Widget rebuilds
      • when a depended-upon piece of data changes

      Important: the build method should be a pure function with no side effects. Do not mutate state, perform I/O, or register listeners inside build.

      Parameters:
      context - the build context, carrying the player, GUI configuration, and similar info
      Returns:
      the child Widget tree
    • createElement

      @NotNull public @NotNull Element createElement()
      Description copied from class: Widget
      Creates the Element corresponding to this Widget.

      This is a framework-internal method; subclasses should return the Element implementation appropriate to the Widget type.

      Specified by:
      createElement in class Widget
      Returns:
      the corresponding Element instance