Phase 4: add caps_rs/bg_rs modes to the prop-table generator

The Rust generator needs the same capability/background tables in Rust
syntax (PHASE4_CAPS / PHASE4_BG_COLOR in crates/lightgui-gen/src/
gen.rs); the C++ modes emit C++ syntax, so add Rust-syntax modes.
This commit is contained in:
cnmcdee committed 2026-11-30 15:13:30 +00:00
1 parent 780ab0353f
commit 9681fbae94
1 file changed
+49 -1
+49 -1
View File
@@ -20,6 +20,12 @@ def fmt_num(v):
s = ("%.10f" % v).rstrip("0").rstrip(".")
return s if s else "0"
def fmt_f64(v):
# Rust float literal: in a const context an integer literal does NOT
# infer as f64 (E0308), so always emit a '.' (e.g. 100000.0, 0.01).
s = fmt_num(v)
return s if ("." in s or "e" in s) else s + ".0"
def srgb_to_rgb(init):
m = re.match(r"(?:Srgb)?\{([^}]*)\}", init)
if not m: return None
@@ -370,7 +376,7 @@ def main():
out.append(' PropDef::n("%s", K::%s, "%s"),' % (prop, kind, default))
else:
out.append(' PropDef::r("%s", K::%s, "%s", %s, %s),' % (
prop, kind, default, fmt_num(lo), fmt_num(hi)))
prop, kind, default, fmt_f64(lo), fmt_f64(hi)))
out.append("];")
out.append("// Dispatch arms (exact XFrame class names) for props_for's match.")
for w in sorted(all_props):
@@ -395,6 +401,33 @@ def main():
out.append(' {"%s", {%s}},' % (w, ", ".join(rows)))
print("\n".join(out))
return
if mode == "caps_rs":
# Same capability table as "caps", in Rust syntax for
# crates/lightgui-gen/src/gen.rs (PHASE4_CAPS).
out = []
out.append("// Phase 4 capability table (generated by tools/gen_phase4_props.py).")
out.append("// (prop, setter) rows the generator may emit for a class; the arg")
out.append("// form comes from the Inspector table's kind for that prop.")
for w in sorted(all_props):
rows = []
for (prop, kind, lo, hi, default, setter) in all_props[w]:
if prop == "text":
continue # text is emitted by the shared path, not here
rows.append('("%s", "%s")' % (prop, setter))
out.append(' ("%s", &[%s]),' % (w, ", ".join(rows)))
print("\n".join(out))
return
if mode == "bg_rs":
# Same bg list as "bg", in Rust syntax (PHASE4_BG_COLOR).
out = []
out.append("// Phase 4: classes with set_bg_color(Srgb) (generated by")
out.append("// tools/gen_phase4_props.py). The common \"background\"")
out.append("// prop is emitted through set_bg_color for these.")
for w in sorted(widgets):
if "set_bg_color" in widgets[w]["setters"]:
out.append(' "%s",' % w)
print("\n".join(out))
return
if mode == "registry":
# Named dispatch for the C++ live-apply path (widgets/common/registry.h):
# 8 IWidget virtuals + one SFINAE trait per distinct Phase-4 setter +
@@ -511,6 +544,21 @@ def main():
out.append(" }")
print("\n".join(out))
return
if mode == "bg":
# Classes whose widget has set_bg_color(Srgb): the generator (and
# the canvas background path) fall back to it for the common
# "background" prop instead of a style clone.
out = []
out.append("// Phase 4: classes with set_bg_color(Srgb) (generated by")
out.append("// tools/gen_phase4_props.py). The common \"background\"")
out.append("// prop is emitted through set_bg_color for these.")
out.append("static const std::vector<std::string> kPhase4BgColor = {")
for w in sorted(widgets):
if "set_bg_color" in widgets[w]["setters"]:
out.append(' "%s",' % w)
out.append("};")
print("\n".join(out))
return
print("unknown mode: " + mode, file=sys.stderr)
sys.exit(2)