Files
lightgui_rust/crates/xframe-common/build.rs
T
Muse 9e6f882575 Regen data tables from lightgui e474894: kTypes 36->38, EventDef lazarus
- tools/extract_palette.py: kTypes expectation 36->38 (ToggleButton and
  CheckListBox added in C); palette total 598->600
- tools/extract_events.py: parse 6th EventDef field `lazarus` (Flag 10
  Lazarus Object Inspector name); scope table/dispatch parsing to
  events_for() (raw_events_for() has its own `raw` table, deliberately
  excluded); dispatch now tests the normalised key `t`, not `type`
- data/*.json regenerated via `make regen`: registry default sizes per
  the C rule (incl. the 15 monitor widgets' hand-written sizes),
  palette Misc/X order per C xframe_palette.h, props 37 types / 270
  props / 25 enum tables / 35 common props, events 29 types with
  lazarus names; indicators provenance head only
- crates/xframe-common: palette asserts 598->600, LightGUI 36->38
- crates/xframe-widgets: *_gen.rs regenerated; gen_data.py opt_f now
  emits float literals for Option<f64> lo/hi (pre-existing latent bug:
  running it on the old data also emitted Some(0)); stale eb0b5fc /
  547 / 9 / 35 / 27 counts updated to e474894 / 562 / 25 / 37 / 29

make check: all 5 tables OK. cargo build warning-free. cargo test
--workspace --no-fail-fast: all suites green except 5 pre-existing
environmental failures, verified identical on HEAD: lightgui-debug
console (37) + gtk (7) need /usr/bin/gdb (not installed on dallas),
lightgui-support font/theme need a display (gtk::init fails), and
lightgui-gen fixtures is stale vs the Task 4 event routing in gen.rs.
2026-12-05 19:20:00 +00:00

154 lines
5.7 KiB
Rust

//! Codegen: compile data/registry.json (562 widgets) and data/palette.json
//! (600 entries) into Rust constants, mirroring the C++ generated
//! widgets/common/registry.h and src/xframe_palette.h. The registry stays
//! generated, never hand-maintained.
use serde::Deserialize;
use std::env;
use std::fs;
use std::path::PathBuf;
#[derive(Deserialize)]
struct Registry {
widget_count: usize,
section_count: usize,
sections: Vec<Section>,
families: std::collections::HashMap<String, usize>,
widgets: Vec<Widget>,
}
#[derive(Deserialize)]
struct Section {
index: usize,
name: String,
color_rgb: [u8; 3],
count: usize,
}
#[derive(Deserialize)]
struct Widget {
index: usize,
name: String,
family: String,
section_index: usize,
default_w: u16,
default_h: u16,
}
#[derive(Deserialize)]
struct Palette {
total: usize,
lightgui_count: usize,
xframe_count: usize,
}
/// Task 3 — content minimum sizes (w, h) per widget type, measured from
/// the widget's fixed content (drawn text rows, columns, grids, action bars).
/// Placement uses max(registry default, content minimum) so the outer border
/// encloses the contents at placement time. Same values as the C repo's
/// widgets/tools/gen_registry.py MIN_SIZES and gen_data.py.
fn min_size(name: &str) -> (u16, u16) {
match name {
"GtkAboutDialog" => (520, 260),
"GtkAssistant" => (320, 280),
"GtkColorChooserDialog" => (340, 240),
"GtkFileChooserDialog" => (360, 240),
"GtkFontChooserDialog" => (340, 240),
"GtkPrintUnixDialog" => (360, 300),
"GtkShortcutsWindow" => (320, 300),
"TCalendarDialog" => (320, 280),
"TColorDialog" => (520, 300),
"TFindDialog" => (380, 260),
"TFontDialog" => (320, 420),
"TOpenPictureDialog" => (480, 240),
"TPageSetupDialog" => (320, 400),
"TPrintDialog" => (320, 300),
"TReplaceDialog" => (360, 260),
"TSavePictureDialog" => (480, 240),
"TSelectDirectoryDialog" => (360, 260),
"TTaskDialog" => (340, 280),
"GtkCalendar" => (260, 200),
"TCalendar" => (260, 200),
"GtkTreeView" => (320, 200),
"TListView" => (320, 200),
"TStringGrid" => (360, 200),
"GtkAppChooserWidget" => (320, 240),
"GtkColorChooserWidget" => (340, 260),
"GtkFileChooserWidget" => (340, 260),
"GtkFontChooserWidget" => (340, 260),
_ => (0, 0),
}
}
fn main() {
let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let reg_path = manifest.join("../../data/registry.json");
let pal_path = manifest.join("../../data/palette.json");
println!("cargo:rerun-if-changed={}", reg_path.display());
println!("cargo:rerun-if-changed={}", pal_path.display());
let reg: Registry = serde_json::from_str(&fs::read_to_string(&reg_path).unwrap()).unwrap();
let pal: Palette = serde_json::from_str(&fs::read_to_string(&pal_path).unwrap()).unwrap();
assert_eq!(reg.widget_count, 562, "registry widget_count");
assert_eq!(reg.widgets.len(), 562, "registry widgets len");
assert_eq!(reg.section_count, 11, "registry section_count");
assert_eq!(pal.total, 600, "palette total");
assert_eq!(pal.xframe_count, 562, "palette xframe_count");
assert_eq!(pal.lightgui_count, 38, "palette lightgui_count");
let mut out = String::new();
out.push_str("// @generated by crates/xframe-common/build.rs from data/registry.json + data/palette.json\n");
out.push_str(&format!(
"pub const WIDGET_COUNT: usize = {};\n",
reg.widget_count
));
out.push_str(&format!(
"pub const SECTION_COUNT: usize = {};\n",
reg.section_count
));
out.push_str(&format!(
"pub const PALETTE_TOTAL: usize = {};\n",
pal.total
));
out.push_str(&format!(
"pub const LIGHTGUI_PALETTE_COUNT: usize = {};\n",
pal.lightgui_count
));
out.push_str(&format!(
"pub const XFRAME_PALETTE_COUNT: usize = {};\n",
pal.xframe_count
));
out.push_str("pub const SECTION_NAMES: [&str; SECTION_COUNT] = [");
for s in &reg.sections {
out.push_str(&format!("{:?}, ", s.name));
}
out.push_str("];\n");
out.push_str("pub const SECTION_COLORS: [(u8, u8, u8); SECTION_COUNT] = [");
for s in &reg.sections {
out.push_str(&format!(
"({}, {}, {}), ",
s.color_rgb[0], s.color_rgb[1], s.color_rgb[2]
));
}
out.push_str("];\n");
out.push_str("pub const SECTION_COUNTS: [usize; SECTION_COUNT] = [");
for s in &reg.sections {
out.push_str(&format!("{}, ", s.count));
}
out.push_str("];\n");
out.push_str("pub static WIDGETS: [WidgetMeta; WIDGET_COUNT] = [");
for w in &reg.widgets {
// Task 3: placement size is max(registry default, content minimum).
let (mw, mh) = min_size(&w.name);
let dw = w.default_w.max(mw);
let dh = w.default_h.max(mh);
out.push_str(&format!(
"WidgetMeta {{ index: {}, name: {:?}, family: {:?}, section_index: {}, default_w: {}, default_h: {} }}, ",
w.index, w.name, w.family, w.section_index, dw, dh
));
}
out.push_str("];\n");
let fam = |k: &str| reg.families.get(k).copied().unwrap_or(0);
out.push_str(&format!(
"pub const FAMILY_COUNTS: [(&str, usize); 6] = [(\"Gtk\", {}), (\"T\", {}), (\"Ind\", {}), (\"Stock\", {}), (\"Inst\", {}), (\"X\", {})];\n",
fam("Gtk"), fam("T"), fam("Ind"), fam("Stock"), fam("Inst"), fam("X")
));
let _ = reg.sections.iter().map(|s| s.index).collect::<Vec<_>>();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
fs::write(out_dir.join("registry_data.rs"), out).unwrap();
}