Phase 3: designer selftest Phase 3 block (containers + remaining families, window fields, generated setters)
This commit is contained in:
1 parent
f59303ed28
commit
24f077769e
1 file changed
+223
@@ -482,6 +482,229 @@ pub fn selftest_step(app: &Shared) {
|
||||
check(app.borrow().items.len() == 1, "canvas back to 1 widget (Phase 2)");
|
||||
}
|
||||
|
||||
// Phase 3 (§2.11–§2.22 + Flag 9 inventory): containers and the
|
||||
// remaining families — one widget of each type, live-apply through
|
||||
// the same set_prop the Inspector uses, then generator emission of
|
||||
// the new setters and the window-level project fields.
|
||||
{
|
||||
let mprop = |id: u64, name: &str| -> Option<String> {
|
||||
let a = app.borrow();
|
||||
a.find_index(id)
|
||||
.and_then(|i| a.items[i].model.props.get(name).cloned())
|
||||
};
|
||||
let wval = |id: u64| -> f64 {
|
||||
let a = app.borrow();
|
||||
a.find_index(id).map(|i| a.items[i].wdg.value()).unwrap_or(-1.0)
|
||||
};
|
||||
let wmin = |id: u64| -> f64 {
|
||||
let a = app.borrow();
|
||||
a.find_index(id).map(|i| a.items[i].wdg.min()).unwrap_or(-1.0)
|
||||
};
|
||||
let wmax = |id: u64| -> f64 {
|
||||
let a = app.borrow();
|
||||
a.find_index(id).map(|i| a.items[i].wdg.max()).unwrap_or(-1.0)
|
||||
};
|
||||
macro_rules! add3 {
|
||||
($what:expr) => {{
|
||||
let id = add_widget(app, $what);
|
||||
check(id.is_some(), &format!("add {} (Phase 3)", $what));
|
||||
id
|
||||
}};
|
||||
}
|
||||
let mut p3: Vec<u64> = Vec::new();
|
||||
|
||||
// Frame / GroupBox / Panel (§2.11).
|
||||
let frame_id = add3!("GtkFrame").unwrap();
|
||||
p3.push(frame_id);
|
||||
check(set_prop(app, frame_id, "label-xalign", "0.5").is_ok(), "Frame label-xalign set");
|
||||
check(mprop(frame_id, "label-xalign").as_deref() == Some("0.5"), "Frame label-xalign stored");
|
||||
check(set_prop(app, frame_id, "inset", "12").is_ok(), "Frame inset set");
|
||||
check(mprop(frame_id, "inset").as_deref() == Some("12"), "Frame inset stored");
|
||||
|
||||
// Image (§2.12).
|
||||
let image_id = add3!("GtkImage").unwrap();
|
||||
p3.push(image_id);
|
||||
check(set_prop(app, image_id, "stretch", "true").is_ok(), "Image stretch set");
|
||||
check(mprop(image_id, "stretch").as_deref() == Some("true"), "Image stretch stored");
|
||||
check(set_prop(app, image_id, "pixel-size", "64").is_ok(), "Image pixel-size set");
|
||||
check(mprop(image_id, "pixel-size").as_deref() == Some("64"), "Image pixel-size stored");
|
||||
|
||||
// ProgressBar (§2.13).
|
||||
let pb_id = add3!("GtkProgressBar").unwrap();
|
||||
p3.push(pb_id);
|
||||
check(set_prop(app, pb_id, "minimum", "10").is_ok(), "ProgressBar minimum set");
|
||||
check(set_prop(app, pb_id, "maximum", "100").is_ok(), "ProgressBar maximum set");
|
||||
check(set_prop(app, pb_id, "position", "60").is_ok(), "ProgressBar position set");
|
||||
check(wmin(pb_id) == 10.0, "ProgressBar minimum live");
|
||||
check(wmax(pb_id) == 100.0, "ProgressBar maximum live");
|
||||
check(wval(pb_id) == 60.0, "ProgressBar position live");
|
||||
check(set_prop(app, pb_id, "pulsing", "true").is_ok(), "ProgressBar pulsing set");
|
||||
check(mprop(pb_id, "pulsing").as_deref() == Some("true"), "ProgressBar pulsing stored");
|
||||
|
||||
// SpinEdit (§2.14).
|
||||
let spin_id = add3!("GtkSpinButton").unwrap();
|
||||
p3.push(spin_id);
|
||||
check(set_prop(app, spin_id, "editor-enabled", "false").is_ok(), "SpinEdit editor-enabled set");
|
||||
check(mprop(spin_id, "editor-enabled").as_deref() == Some("false"), "SpinEdit editor-enabled stored");
|
||||
|
||||
// Calendar / DateTimePicker (§2.15).
|
||||
let cal_id = add3!("GtkCalendar").unwrap();
|
||||
p3.push(cal_id);
|
||||
check(set_prop(app, cal_id, "date", "2026-11-30").is_ok(), "Calendar date set");
|
||||
check(mprop(cal_id, "date").as_deref() == Some("2026-11-30"), "Calendar date stored");
|
||||
check(set_prop(app, cal_id, "show-week-numbers", "true").is_ok(), "Calendar show-week-numbers set");
|
||||
check(mprop(cal_id, "show-week-numbers").as_deref() == Some("true"), "Calendar show-week-numbers stored");
|
||||
|
||||
// Colour picker (§2.16).
|
||||
let col_id = add3!("GtkColorButton").unwrap();
|
||||
p3.push(col_id);
|
||||
check(set_prop(app, col_id, "style", "2").is_ok(), "ColorBox style set");
|
||||
check(mprop(col_id, "style").as_deref() == Some("2"), "ColorBox style stored");
|
||||
check(set_prop(app, col_id, "default-color", "#112233").is_ok(), "ColorBox default-color set");
|
||||
|
||||
// ListView / TreeView (§2.17).
|
||||
let lv_id = add3!("GtkListView").unwrap();
|
||||
p3.push(lv_id);
|
||||
check(set_prop(app, lv_id, "view-style", "1").is_ok(), "ListView view-style set");
|
||||
check(mprop(lv_id, "view-style").as_deref() == Some("1"), "ListView view-style stored");
|
||||
check(set_prop(app, lv_id, "sort-type", "2").is_ok(), "ListView sort-type set");
|
||||
check(mprop(lv_id, "sort-type").as_deref() == Some("2"), "ListView sort-type stored");
|
||||
let tv_id = add3!("GtkTreeView").unwrap();
|
||||
p3.push(tv_id);
|
||||
check(set_prop(app, tv_id, "indent", "24").is_ok(), "TreeView indent set");
|
||||
check(mprop(tv_id, "indent").as_deref() == Some("24"), "TreeView indent stored");
|
||||
check(set_prop(app, tv_id, "show-root", "false").is_ok(), "TreeView show-root set");
|
||||
check(mprop(tv_id, "show-root").as_deref() == Some("false"), "TreeView show-root stored");
|
||||
|
||||
// Notebook (§2.18).
|
||||
let nb_id = add3!("GtkNotebook").unwrap();
|
||||
p3.push(nb_id);
|
||||
check(set_prop(app, nb_id, "tab-position", "1").is_ok(), "Notebook tab-position set");
|
||||
check(mprop(nb_id, "tab-position").as_deref() == Some("1"), "Notebook tab-position stored");
|
||||
check(set_prop(app, nb_id, "tab-width", "80").is_ok(), "Notebook tab-width set");
|
||||
check(mprop(nb_id, "tab-width").as_deref() == Some("80"), "Notebook tab-width stored");
|
||||
|
||||
// ToggleButton / SpeedButton (§2.21).
|
||||
let tog_id = add3!("GtkToggleButton").unwrap();
|
||||
p3.push(tog_id);
|
||||
check(set_prop(app, tog_id, "group-index", "3").is_ok(), "ToggleButton group-index set");
|
||||
check(mprop(tog_id, "group-index").as_deref() == Some("3"), "ToggleButton group-index stored");
|
||||
check(set_prop(app, tog_id, "flat", "true").is_ok(), "ToggleButton flat set");
|
||||
check(mprop(tog_id, "flat").as_deref() == Some("true"), "ToggleButton flat stored");
|
||||
|
||||
// Splitter (§2.19).
|
||||
let paned_id = add3!("GtkPaned").unwrap();
|
||||
p3.push(paned_id);
|
||||
check(set_prop(app, paned_id, "position", "150").is_ok(), "Splitter position set");
|
||||
check(mprop(paned_id, "position").as_deref() == Some("150"), "Splitter position stored");
|
||||
check(set_prop(app, paned_id, "min-size", "60").is_ok(), "Splitter min-size set");
|
||||
check(mprop(paned_id, "min-size").as_deref() == Some("60"), "Splitter min-size stored");
|
||||
|
||||
// StatusBar (§2.19).
|
||||
let sb_id = add3!("GtkStatusbar").unwrap();
|
||||
p3.push(sb_id);
|
||||
check(set_prop(app, sb_id, "panels", "One|Two").is_ok(), "StatusBar panels set");
|
||||
check(mprop(sb_id, "panels").as_deref() == Some("One|Two"), "StatusBar panels stored");
|
||||
check(set_prop(app, sb_id, "size-grip", "false").is_ok(), "StatusBar size-grip set");
|
||||
check(mprop(sb_id, "size-grip").as_deref() == Some("false"), "StatusBar size-grip stored");
|
||||
|
||||
// ToolBar (§2.19).
|
||||
let tb_id = add3!("GtkToolbar").unwrap();
|
||||
p3.push(tb_id);
|
||||
check(set_prop(app, tb_id, "show-captions", "false").is_ok(), "ToolBar show-captions set");
|
||||
check(mprop(tb_id, "show-captions").as_deref() == Some("false"), "ToolBar show-captions stored");
|
||||
check(set_prop(app, tb_id, "button-width", "48").is_ok(), "ToolBar button-width set");
|
||||
check(mprop(tb_id, "button-width").as_deref() == Some("48"), "ToolBar button-width stored");
|
||||
|
||||
// MenuBar (§2.19).
|
||||
let mb_id = add3!("GtkMenuBar").unwrap();
|
||||
p3.push(mb_id);
|
||||
check(set_prop(app, mb_id, "menus", "File|Edit").is_ok(), "MenuBar menus set");
|
||||
check(mprop(mb_id, "menus").as_deref() == Some("File|Edit"), "MenuBar menus stored");
|
||||
|
||||
// Shape (§2.19).
|
||||
let shape_id = add3!("TShape").unwrap();
|
||||
p3.push(shape_id);
|
||||
check(set_prop(app, shape_id, "shape", "6").is_ok(), "Shape shape set");
|
||||
check(mprop(shape_id, "shape").as_deref() == Some("6"), "Shape shape stored");
|
||||
check(set_prop(app, shape_id, "fill-color", "#336699").is_ok(), "Shape fill-color set");
|
||||
check(set_prop(app, shape_id, "pen-width", "3").is_ok(), "Shape pen-width set");
|
||||
check(mprop(shape_id, "pen-width").as_deref() == Some("3"), "Shape pen-width stored");
|
||||
|
||||
// StringGrid / Spreadsheet (§2.19).
|
||||
let grid_id = add3!("XSpreadsheet").unwrap();
|
||||
p3.push(grid_id);
|
||||
check(set_prop(app, grid_id, "columns", "2").is_ok(), "Spreadsheet columns set");
|
||||
check(set_prop(app, grid_id, "rows", "3").is_ok(), "Spreadsheet rows set");
|
||||
check(set_prop(app, grid_id, "grid-line-width", "2").is_ok(), "Spreadsheet grid-line-width set");
|
||||
check(mprop(grid_id, "grid-line-width").as_deref() == Some("2"), "Spreadsheet grid-line-width stored");
|
||||
|
||||
// Window-level project fields (§2.20).
|
||||
{
|
||||
let mut a = app.borrow_mut();
|
||||
a.project.border_style = 1;
|
||||
a.project.position = 1;
|
||||
a.project.window_state = 3;
|
||||
}
|
||||
let tmp3 = std::env::temp_dir()
|
||||
.join(format!("lightgui-designer-selftest-p3-{}", std::process::id()));
|
||||
let _ = std::fs::create_dir_all(&tmp3);
|
||||
{
|
||||
let (project, widgets) = {
|
||||
let a = app.borrow();
|
||||
(a.project.clone(), a.model_widgets())
|
||||
};
|
||||
let mut project = project;
|
||||
project.widgets = widgets;
|
||||
let gen_dir = tmp3.join("gen");
|
||||
let res = lightgui_gen::generate_project(&project, &project.widgets, &gen_dir);
|
||||
check(res.ok, &format!("Phase 3 generate ok ({})", res.error));
|
||||
match std::fs::read_to_string(gen_dir.join("main.cpp")) {
|
||||
Ok(main) => {
|
||||
for want in [
|
||||
"set_label_xalign(0.5)",
|
||||
"set_min(10",
|
||||
"set_position(60",
|
||||
"set_date(2026, 11, 30)",
|
||||
"set_shape(6)",
|
||||
"set_fill_color(Srgb{51, 102, 153})",
|
||||
"set_size(2, 3)",
|
||||
"set_grid_line_width(2)",
|
||||
"set_view_style(1)",
|
||||
"set_sort_type(2)",
|
||||
"set_indent(24)",
|
||||
"set_tab_position(1)",
|
||||
"set_tab_width(80)",
|
||||
"set_group_index(3)",
|
||||
"set_min_size(60)",
|
||||
"set_size_grip(false)",
|
||||
"set_show_captions(false)",
|
||||
"set_button_width(48)",
|
||||
"set_items({\"File\", \"Edit\"})",
|
||||
"win_x, win_y",
|
||||
"override_redirect",
|
||||
"_NET_WM_STATE_FULLSCREEN",
|
||||
] {
|
||||
check(main.contains(want), &format!("generated main.cpp has {want}"));
|
||||
}
|
||||
}
|
||||
Err(e) => check(false, &format!("read generated main.cpp: {e}")),
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut a = app.borrow_mut();
|
||||
a.project.border_style = 0;
|
||||
a.project.position = 0;
|
||||
a.project.window_state = 0;
|
||||
}
|
||||
|
||||
// Leave the canvas as the later checks expect it: one Button.
|
||||
for id in p3 {
|
||||
delete_item(app, id);
|
||||
}
|
||||
check(app.borrow().items.len() == 1, "canvas back to 1 widget (Phase 3)");
|
||||
}
|
||||
|
||||
// Save / load round-trip (string + file), through lightgui-core.
|
||||
let tmp =
|
||||
std::env::temp_dir().join(format!("lightgui-designer-selftest-{}", std::process::id()));
|
||||
|
||||
Reference in new issue
Block a user