Package com.ultikits.ultitools.abstracts.gui.declarative
Built on Flutter's design philosophy, this framework provides a declarative way to build UI. Core idea: UI = f(state)
Status (6.3.0)
This package and its subpackages are still marked @ApiStatus.Experimental; the API
may change incompatibly in a future release.
Three rendering seams were fixed in 6.3.0 — UI = f(state) now holds:
GuiRenderer re-derives the Widget tree from a Supplier<Widget> on every
performBuild() call, not just once from open(); Element.update()
marks itself dirty unconditionally; and State.setState() — including a call on a
nested StatefulWidget — now reliably reaches a scheduled repaint. The
setState triggers a partial rebuild bullet below now holds, and the navigation
subsystem that depends on it (Navigator.push / pop) is usable. Click
dispatch uses actions carried by immutable GridItems; UiService dispatches
only actions belonging to the displayed grid, without an engine-owned inventory-event map.
GridView writes its computed slot onto any
widget type's render node(s) at render time (previously only ItemDisplay positioned
correctly).
Why the marker stays. As of this release, none of these three changes has real-server feedback from a downstream module — zero adoption is no more grounds for declaring the API stable than it would be for deleting it. The marker is retained for at least one more release pending that feedback.
The three seams are tracked by issue #200.
Main Features:
- Widget tree describes the UI structure
- Element tree manages Widget instances and their lifecycle
- RenderNode tree describes immutable Grid snapshots; the backend diffs slots
- Supports both StatelessWidget and StatefulWidget
- setState triggers a partial rebuild
- State mutations run on the calling thread; rebuilds run in the viewer's entity context. Hand off background results with the module's scheduler before mutating state.
- UiService owns screen sessions, actions and close results
Quick Start:
// 1. Create your GUI page
public class ShopPage extends DeclarativeGui {
private final List<ItemSpec> items;
public ShopPage(UiService ui, Scheduler scheduler, Player player, List<ItemSpec> items) {
super(ui, scheduler, player, "shop", Text.plain("Item Shop"), 6);
this.items = items;
}
@Override
public Widget build(BuildContext context) {
return Container.builder()
.children(
// Title
TextButton.builder()
.text(Text.plain("Item Shop"))
.slot(4)
.build(),
// Item grid
GridView.<ItemSpec>builder()
.startSlot(10)
.columns(7)
.items(items, item -> ItemDisplay.builder(item)
.onClick(() -> buyItem(item))
.build())
.build(),
// Close button
TextButton.builder()
.text(Text.plain("Close"))
.color("RED")
.slot(49)
.onClick(click -> click.session().close())
.build()
)
.build();
}
private void buyItem(ItemSpec item) {
// Handle purchase logic
}
}
// 2. Use the module's injected UiService and Scheduler on the viewer's entity thread.
new ShopPage(ui, scheduler, player, items).open();
// 3. Bind an item area. The last page may contain fewer than nine indexes.
ItemSlotArea.builder(container).firstIndex(page * 9).count(9).build(); // VIEW by default
ItemSlotArea.builder(container).firstIndex(page * 9).count(9)
.mode(BindingMode.EDITABLE).build(); // Moving items requires explicit opt-in
StatefulWidget Example:
public class CounterPage extends DeclarativeGui {
private int count = 0;
public CounterPage(UiService ui, Scheduler scheduler, Player player) {
super(ui, scheduler, player, "counter", Text.plain("Counter"), 3);
}
@Override
public Widget build(BuildContext context) {
return Container.builder()
.child(TextButton.builder()
.text(Text.plain("Count: " + count))
.slot(13)
.onClick(() -> {
// Mutate state and trigger a rebuild
count++;
markNeedsBuild();
})
.build())
.build();
}
}
Package Structure:
com.ultikits.ultitools.abstracts.gui.declarative.core- core abstract classescom.ultikits.ultitools.abstracts.gui.declarative.engine- rendering enginecom.ultikits.ultitools.abstracts.gui.declarative.widgets- built-in widget librarycom.ultikits.ultitools.abstracts.gui.declarative.util- utility classes
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- qianmo
- See Also: