gui-scroll-screenfit-demo.sleela
lib/gui/version-thual/gui-scroll-screenfit-demo.sleela · 124 line(s) · sleela
<< lib/gui/version-thual/gui-scroll-screenfit-demo.sleela
A runnable walkthrough of the two new version-thual sizing/scrolling helpers:
- SLGuiScreenFit โ sizes a window from the ACTUAL screen size / resolution
at three support tiers (basic / moderate / advanced).
- SLGuiScrollbar โ an IMPLIED scrollbar for a scrolled surface in BOTH
axes (vertical and horizontal), computing the [0,1]
value/page the drawn uiScrollBar needs.
SLeeLa owns the geometry + policy; the host feeds in the real screen (from
the native uiScreenWidth / uiScreenHeight built-ins) and the viewport/content
extents, and reads the resolved sizes back out. Tier/axis/policy ordinals are
passed as small ints (documented in each class) โ the house style for callers. >>
#sleela 2.5
material;
< Select the GUI 5.0 military source line so SLPackage, SLGuiScreenFit, and >
< SLGuiScrollbar resolve to this line's classes through the library index. >
import gui.version-thual;
class GuiScrollScreenFitDemo {
< ---- 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 = 11363;
String metaAuthor = "Kiro Agent";
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; }
void main() {
SLPackage pkg = new SLPackage(); pkg.configure("gui");
print("gui package " + pkg.version() + " (featureLevel " + pkg.featureLevel() + ")");
< ---- Screen-based window sizing, three tiers -------------------------- >
< In a live program the host passes uiScreenWidth(app)/uiScreenHeight(app) >
< here; a headless host passes 0 and the model falls back to 1920x1080. >
int screenW = 2560; int screenH = 1440;
SLGuiScreenFit basic = new SLGuiScreenFit();
< 0 = TIER_BASIC >
basic.configure(0);
basic.setScreen(screenW, screenH); basic.fit();
print("BASIC -> " + basic.report() + " honored=" + basic.honored());
SLGuiScreenFit moderate = new SLGuiScreenFit();
< 1 = TIER_MODERATE >
moderate.configure(1);
moderate.setScreen(screenW, screenH); moderate.setMargin(64); moderate.fit();
print("MODERATE -> " + moderate.report() + " honored=" + moderate.honored());
SLGuiScreenFit advanced = new SLGuiScreenFit();
< 2 = TIER_ADVANCED >
advanced.configure(2);
advanced.setScreen(screenW, screenH); advanced.fit();
print("ADVANCED -> " + advanced.report() + " honored=" + advanced.honored());
print(" (advanced buckets the screen by class: " + advanced.resolutionClassName() + ")");
< ---- Implied scrollbars, both axes ------------------------------------ >
< Use the advanced window as the viewport; pretend the content is larger. >
int viewW = advanced.width(); int viewH = advanced.height();
< wider than the viewport -> h-scroll >
int contentW = viewW + 600;
< three screens tall -> v-scroll >
int contentH = viewH * 3;
SLGuiScrollbar vbar = new SLGuiScrollbar();
< 0 = AXIS_VERTICAL >
vbar.configure(0, viewH, contentH);
< page down once >
vbar.scrollBy(viewH);
print("V-SCROLL -> " + vbar.report());
print(" uiScrollBar(parent, " + vbar.orient() + ", "
+ (vbar.valuePermille() / 1000.0) + ", " + (vbar.pagePermille() / 1000.0) + ")");
SLGuiScrollbar hbar = new SLGuiScrollbar();
< 1 = AXIS_HORIZONTAL >
hbar.configure(1, viewW, contentW);
hbar.scrollToEnd();
print("H-SCROLL -> " + hbar.report());
print(" uiScrollBar(parent, " + hbar.orient() + ", "
+ (hbar.valuePermille() / 1000.0) + ", " + (hbar.pagePermille() / 1000.0) + ")");
< A surface that fits needs no bar (auto policy hides it). >
SLGuiScrollbar fits = new SLGuiScrollbar();
< content < viewport >
fits.configure(0, 800, 600);
print("NO-SCROLL-> implied=" + fits.implied() + " (content fits the viewport)");
print("done: screen-fit sizing + implied scrollbars, version-thual line.");
}
}