Home /Modules/user-interface/SLGuiHandler.sleela

SLGuiHandler.sleela

lib/user-interface/SLGuiHandler.sleela · 118 line(s) · sleela

<< lib/user-interface/SLGuiHandler.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLGuiHandler — one registered event callback: the triple
     (event type, target node id, SLeeLa operation). It is the /lib/gui
     generalisation of SLGuiAction from a single click to any SLGuiEventType, and
     it is what addEventListener(target, type, operation) and the onClick/onInput
     shorthands create. When the dispatcher matches a raised SLGuiEvent to this
     handler it invokes the bound operation; the handler latches each fire so a
     host that polls (rather than calls back) still observes each activation
     exactly once, the same take-the-latch discipline as SLGuiAction.
   
   Family: user-interface. The host raises activations; this binding maps them to a SLeeLa
   operation whose meaning SLeeLa owns. >>
#sleela 2.5
material;
class SLGuiHandler {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11046;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-13";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < SLGuiEventType ordinal this handler listens for >
  int type;
  < node id it is bound to ("*" matches any target) >
  String targetId;
  < the SLeeLa operation invoked when it fires >
  String operation;
  < 1 = auto-remove after the first fire >
  int once;
  < 1 = fire during capture phase, 0 = bubble phase >
  int capture;
  < 1 while active >
  int enabled;
  < activation latch (set on fire, cleared on take) >
  int pending;
  < total times fired >
  int fired;
  < the value carried by the most recent matching event >
  String lastValue;

  void configure(int eventType, String target, String op) {
    type = eventType; targetId = target; operation = op;
    once = 0; capture = 0; enabled = 1; pending = 0; fired = 0; lastValue = "";
  }

  int getType() { return type; }
  String getTarget() { return targetId; }
  String getOperation() { return operation; }
  boolean bound() { return targetId != null && operation != null; }

  void setOnce(boolean on) { once = on ? 1 : 0; }
  boolean isOnce() { return once == 1; }
  void setCapture(boolean on) { capture = on ? 1 : 0; }
  boolean isCapture() { return capture == 1; }
  void setEnabled(boolean on) { enabled = on ? 1 : 0; }
  boolean isEnabled() { return enabled == 1; }

  < Does this handler match the given event? "*" target is a wildcard. >
  boolean matches(SLGuiEvent event) {
    if (enabled == 0 || event == null) { return false; }
    if (event.getType() != type) { return false; }
    return targetId == "*" || targetId == event.target();
  }

  < Fire against a matching event: record it and raise the latch. The >
  < dispatcher calls this; a host that polls then reads it with take(). >
  void fire(SLGuiEvent event) {
    if (event != null) { lastValue = event.getValue(); }
    pending = 1;
    fired = fired + 1;
  }

  < Take-the-latch read: true once per fire, then cleared. >
  boolean take() {
    if (pending == 1) { pending = 0; return true; }
    return false;
  }

  int activations() { return fired; }
  String value() { return lastValue; }
}