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

  1. Create or use the global zone manager:

    initGlobalZone();
    // or
    final myZone = ZoneManager();
    
  2. In your view method, wrap clickable content with mark:

    String view() {
      return zone.mark('my-button', style.render('Click Me'));
    }
    
  3. In your root model, wrap the entire view output with scan:

    String view() {
      return zone.scan(renderAllChildren());
    }
    
  4. 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

  • Use newPrefix to prevent ID collisions between component instances
  • Only call scan at the root model level
  • Use lipgloss.width() equivalent for width calculations, not String.length
  • Zones are bounding boxes - organic shapes will include corner areas

Constructors

ZoneManager()
Creates a new zone manager.

Properties

enabled bool
Whether the zone manager is enabled.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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