Theme.sleela
lib/alphabet/Theme.sleela · 144 line(s) · sleela
<< lib/alphabet/Theme.sleela
SLeeLa Standard Library Definition.
Definition: Defines Theme, the base Master Class that binds the three things
this package is about โ a Palette of Colors, role colors (background,
foreground, accent), and an Alphabet โ into one coherent, user-facing look.
A Theme is what a user of Sleela actually sees.
A concrete theme is created by subclassing Theme and overriding dress(),
which fills in the palette and role colors. The base owns the role plumbing,
contrast checking, and the loadable-module contract, mirroring the
base/subclass pattern used by Alphabet and the lib/compiler front ends.
Theme is a NATURAL / LOADABLE MODULE sharing the common module contract
(load / loaded / moduleName / describe).
Family: alphabet. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Theme {
< ---- 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 = 10412;
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-07";
< 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; }
static final String MODULE = "Theme";
int loadedFlag;
String themeName;
< the colors this theme draws from >
Palette palette;
< the canvas >
Color background;
< the text >
Color foreground;
< the one color that gets to be loud >
Color accent;
< the writing system this theme presents >
Alphabet script;
< --- loadable-module contract ------------------------------------------ >
void load() {
loadedFlag = 1;
themeName = "Unnamed";
palette = new Palette();
palette.load();
background = new Color();
background.load();
foreground = new Color();
foreground.load();
accent = new Color();
accent.load();
script = null;
}
boolean loaded() { return loadedFlag == 1; }
String moduleName() { return MODULE; }
< A subclass calls this to build the theme: name it, dress it, done. Mirrors >
< Alphabet.begin() / compose(). >
void begin(String name) {
load();
if (name != null) { themeName = name; }
palette.name(themeName);
dress();
}
< Overridable: a concrete theme fills palette + role colors here. The base >
< leaves everything black-on-black, which is honestly unusable on purpose. >
void dress() { }
< Helpers a subclass uses from dress() to set the three role colors. >
void setBackground(int r, int g, int b) { background.set(r, g, b); }
void setForeground(int r, int g, int b) { foreground.set(r, g, b); }
void setAccent(int r, int g, int b) { accent.set(r, g, b); }
< Attach the writing system this theme presents. >
void useAlphabet(Alphabet a) { script = a; }
Color bg() { return background; }
Color fg() { return foreground; }
Color highlight() { return accent; }
Palette colors() { return palette; }
Alphabet alphabet() { return script; }
String name() { return themeName; }
< A theme is "dark" when its canvas is dark. All users of Sleela will have >
< opinions about this. >
boolean isDark() { return background.isDark(); }
< Readable means the text and the canvas disagree about darkness โ a crude >
< but effective contrast check. >
boolean readable() { return background.isDark() != foreground.isDark(); }
int letterCount() { if (script == null) { return 0; } return script.size(); }
String yn(boolean v) { if (v) { return "yes"; } return "no"; }
String describe() {
String scriptName = "none";
if (script != null) { scriptName = script.script(); }
return MODULE + "/" + themeName + " bg=" + background.hex()
+ " fg=" + foreground.hex() + " accent=" + accent.hex()
+ " dark=" + yn(isDark()) + " readable=" + yn(readable())
+ " script=" + scriptName;
}
}