Home /Modules/gui/SLGuiMenu.sleela

SLGuiMenu.sleela

lib/gui/version-gual/SLGuiMenu.sleela · 76 line(s) · sleela

<< SLeeLa Standard Library Definition: SLGuiMenu
   Menu state model with stable action names and predictable dismissal. >>
#sleela 2.5
material;
class SLGuiMenu {
  < ---- 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 = 11370;
  String metaAuthor = "Max Rupplin vs. Dr. Mrs. Elisabeth Harkins";
  String metaDate = "2026-10-19";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-19";
  < 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; }
  String id;
  String label;
  int itemCount;
  int visible;
  int opened;
  int activeIndex;

  void configure(String menuId, String menuLabel) {
    id = menuId; label = menuLabel; itemCount = 0; visible = 1; opened = 0; activeIndex = -1;
  }
  String getId() { return id; }
  String getLabel() { return label; }
  void setItemCount(int count) { itemCount = count < 0 ? 0 : count; if (activeIndex >= itemCount) { activeIndex = itemCount - 1; } }
  int count() { return itemCount; }
  void setVisible(boolean value) { visible = value ? 1 : 0; if (visible == 0) { dismiss(); } }
  boolean isVisible() { return visible == 1; }
  void open() { if (visible == 1) { opened = 1; activeIndex = itemCount > 0 ? 0 : -1; } }
  void dismiss() { opened = 0; activeIndex = -1; }
  boolean isOpen() { return opened == 1; }
  void move(int direction) {
    if (opened == 0 || itemCount <= 0) { return; }
    activeIndex = (activeIndex + direction + itemCount) % itemCount;
  }
  int selectedIndex() { return activeIndex; }
  boolean select(int index) {
    if (opened == 0 || visible == 0 || index < 0 || index >= itemCount) { return false; }
    activeIndex = index; return true;
  }
}