Home /Modules/ui/SLDockLayout.sleela

SLDockLayout.sleela

lib/ui/SLDockLayout.sleela · 133 line(s) · sleela

<< lib/ui/SLDockLayout.sleela
   SLeeLa Standard Library Definition.
   Definition: SLDockLayout — dock children to the container edges (top, bottom,
     left, right) in the order added, each taking a band off the remaining
     space; a single FILL child takes whatever is left in the centre. The
     classic application-chrome layout (toolbar on top, status bar on bottom,
     sidebar on left, content filling the middle), made one call per region.
     Pure SLeeLa; fills SLLayoutBox[].

   Easy path (toolbar + status bar + content):
     SLDockLayout d = new SLDockLayout();
     d.top(32); d.bottom(24); d.fill();
     d.arrange(0, 0, 800, 600);
     SLLayoutBox content = d.boxOf(2); >>
#sleela 2.5
material;
< Family: ui. A standard, professional, beginner-friendly dock layout. >
class SLDockLayout {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs. >>
  String metaVersion = "1.0.0";
  int metaId = 11605;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-25";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-25";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 8;
  < 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; }

  static final int SIDE_TOP = 0;
  static final int SIDE_BOTTOM = 1;
  static final int SIDE_LEFT = 2;
  static final int SIDE_RIGHT = 3;
  static final int SIDE_FILL = 4;
  static final int MAX_ITEMS = 64;

  int count;
  < side per child, and the band thickness in px (ignored for FILL) >
  int[] side; int[] band;
  SLLayoutBox[] boxes;

  void create() {
    count = 0;
    side = new int[MAX_ITEMS]; band = new int[MAX_ITEMS];
    boxes = new SLLayoutBox[MAX_ITEMS];
  }

  int dockItem(int s, int thicknessPx) {
    if (count >= MAX_ITEMS) { return -1; }
    side[count] = s; band[count] = (thicknessPx < 0) ? 0 : thicknessPx;
    int idx = count; count = count + 1; return idx;
  }
  < One-call helpers per region, in the order you dock them. >
  int top(int h)    { return dockItem(SIDE_TOP, h); }
  int bottom(int h) { return dockItem(SIDE_BOTTOM, h); }
  int left(int w)   { return dockItem(SIDE_LEFT, w); }
  int right(int w)  { return dockItem(SIDE_RIGHT, w); }
  < The centre child that fills whatever remains (use at most one). >
  int fill()        { return dockItem(SIDE_FILL, 0); }
  int size() { return count; }

  void arrange(int x, int y, int w, int h) {
    int curX = x; int curY = y; int curW = w; int curH = h;
    if (curW < 0) { curW = 0; }
    if (curH < 0) { curH = 0; }
    int i = 0;
    while (i < count) {
      SLLayoutBox b = new SLLayoutBox();
      b.create();
      int s = side[i];
      int t = band[i];
      if (s == SIDE_TOP) {
        if (t > curH) { t = curH; }
        b.set(curX, curY, curW, t);
        curY = curY + t; curH = curH - t;
      } else if (s == SIDE_BOTTOM) {
        if (t > curH) { t = curH; }
        b.set(curX, curY + curH - t, curW, t);
        curH = curH - t;
      } else if (s == SIDE_LEFT) {
        if (t > curW) { t = curW; }
        b.set(curX, curY, t, curH);
        curX = curX + t; curW = curW - t;
      } else if (s == SIDE_RIGHT) {
        if (t > curW) { t = curW; }
        b.set(curX + curW - t, curY, t, curH);
        curW = curW - t;
      } else {
        < FILL: take whatever remains >
        b.set(curX, curY, curW, curH);
      }
      boxes[i] = b;
      i = i + 1;
    }
  }

  SLLayoutBox boxOf(int index) {
    if (index < 0 || index >= count) { return null; }
    return boxes[index];
  }

  boolean honored() { return count >= 0 && count <= MAX_ITEMS; }
}