Class StatelessWidget
java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.Widget
com.ultikits.ultitools.abstracts.gui.declarative.core.StatelessWidget
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 Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new StatelessWidget.protectedStatelessWidget(SlotKey key) Creates a new StatelessWidget with the given key. -
Method Summary
Modifier and TypeMethodDescriptionabstract @NotNull Widgetbuild(@NotNull BuildContext context) Builds this Widget's subtree.@NotNull ElementCreates the Element corresponding to this Widget.
-
Constructor Details
-
StatelessWidget
protected StatelessWidget()Creates a new StatelessWidget. -
StatelessWidget
Creates a new StatelessWidget with the given key.- Parameters:
key- the key used to stably identify this Widget
-
-
Method Details
-
build
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
Description copied from class:WidgetCreates the Element corresponding to this Widget.This is a framework-internal method; subclasses should return the Element implementation appropriate to the Widget type.
- StatelessWidget returns a
StatelessElement - StatefulWidget returns a
StatefulElement - RenderObjectWidget returns a
RenderObjectElement
- Specified by:
createElementin classWidget- Returns:
- the corresponding Element instance
- StatelessWidget returns a
-