ZoneManager class
Zone manager for tracking clickable regions in TUI output.
BubbleZone allows you to wrap components in zero-printable-width identifiers that don't affect layout calculations. When the output is scanned, these markers are detected and their screen positions are stored.
This enables easy mouse event hit testing - simply check if a mouse event is within the bounds of a zone by its ID.
Usage
-
Create or use the global zone manager:
initGlobalZone(); // or final myZone = ZoneManager(); -
In your view method, wrap clickable content with mark:
String view() { return zone.mark('my-button', style.render('Click Me')); } -
In your root model, wrap the entire view output with scan:
String view() { return zone.scan(renderAllChildren()); } -
In update, check if mouse events are within zones:
(Model, Cmd?) update(Msg msg) { if (msg is MouseMsg && msg.action == MouseAction.release) { if (zone.get('my-button')?.inBounds(msg) ?? false) { return (handleButtonClick(), null); } } return (this, null); }
Tips
Constructors
- ZoneManager()
- Creates a new zone manager.
Properties
Methods
-
anyInBounds(
Model model, MouseMsg mouse) → void - Sends a ZoneInBoundsMsg to the model for each zone that contains the mouse position, discarding the results.
-
anyInBoundsAndUpdate(
Model model, MouseMsg mouse) → (Model, Cmd?) - Sends a ZoneInBoundsMsg to the model for each zone that contains the mouse position.
-
clear(
String id) → void - Clears all registered zones.
-
close(
) → void - Closes the zone manager and releases resources.
-
findInBounds(
MouseMsg msg) → List< ZoneInfo> - Returns all zones that contain the given mouse position.
-
get(
String id) → ZoneInfo? - Gets the zone info for the given ID.
-
mark(
String id, String content) → String - Wraps content with zone markers.
-
newPrefix(
) → String - Generates a unique prefix for zone IDs.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
scan(
String view) → String - Scans view output for zone markers and returns the output with markers removed.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited