Phase 3: ToggleButton type, window-level Project fields (border-style, icon, position, window-state), root Inspector rows

This commit is contained in:
cnmcdee committed 2026-11-30 12:07:33 +00:00
1 parent bffb69b18f
commit bef3233260
5 files changed
+107 -6

No files matched your search

+8
View File
@@ -97,6 +97,14 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
kind: K::Simple,
builtin: false,
}],
"ToggleButton" => &[EventDef {
signal: "toggled",
handler: "on_toggled",
label: "Toggled",
lazarus: "OnClick",
kind: K::Simple,
builtin: false,
}],
"Radiobutton" => &[EventDef {
signal: "toggled",
handler: "on_toggled",
+23 -2
View File
@@ -70,6 +70,15 @@ pub struct Project {
/// Menu bar spec, one menu per line: `"File: New | Open | - | Quit"`
/// (`"-"` is a separator). Empty = no menu bar.
pub menubar: String,
/// Window border style (0 = default, 1 = none, 2 = single, 3 = dialog).
pub border_style: i32,
/// Window icon file (model-only: the generator emits it as a NOTE).
pub icon: String,
/// Window position (0 = default, 1 = center, 2 = screen center,
/// 3 = main form center, 4 = designed).
pub position: i32,
/// Window state (0 = normal, 1 = minimized, 2 = maximized, 3 = fullscreen).
pub window_state: i32,
pub widgets: Vec<Widget>,
}
@@ -82,6 +91,10 @@ impl Default for Project {
win_height: 600,
background: String::new(),
menubar: String::new(),
border_style: 0,
icon: String::new(),
position: 0,
window_state: 0,
widgets: Vec::new(),
}
}
@@ -129,6 +142,13 @@ pub const KTYPES: &[TypeInfo] = &[
def_height: 26,
phase1: true,
},
TypeInfo {
key: "ToggleButton",
palette_id: "pal_togglebutton",
def_width: 110,
def_height: 30,
phase1: true,
},
TypeInfo {
key: "Radiobutton",
palette_id: "pal_radiobutton",
@@ -410,7 +430,8 @@ pub fn class_kind(class: &str) -> Option<&'static str> {
"GtkTreeView" => "TreeView",
"XGraph" => "Plot",
"GtkImage" => "Image",
"GtkToggleButton" => "Checkbutton",
"GtkToggleButton" => "ToggleButton",
"TSpeedButton" => "ToggleButton",
"GtkPasswordEntry" => "Entry",
"GtkSearchEntry" => "Entry",
"TCheckListBox" => "CheckListBox",
@@ -438,7 +459,7 @@ mod tests {
#[test]
fn types_count_and_lookup() {
assert_eq!(KTYPES.len(), 37);
assert_eq!(KTYPES.len(), 38);
assert_eq!(find_type("Button").unwrap().def_width, 100);
assert_eq!(find_type("StockChart").unwrap().def_height, 200);
assert!(find_type("Nope").is_none());
+14 -3
View File
@@ -4,7 +4,7 @@
//!
//! ```json
//! { "format": "lightgui", "version": 1,
//! "window": { "title", "class_name", "width", "height", "background", "menubar" },
//! "window": { "title", "class_name", "width", "height", "background", "menubar", "border_style", "icon", "position", "window_state" },
//! "widgets": [ { "name", "type", "x", "y", "width", "height",
//! "props": { name: value, ... }, "signals": [...] } ] }
//! ```
@@ -63,9 +63,16 @@ pub fn save_to_string(p: &Project) -> String {
json_escape(&p.background)
));
o.push_str(&format!(
" \"menubar\": \"{}\"\n",
" \"menubar\": \"{}\",\n",
json_escape(&p.menubar)
));
o.push_str(&format!(" \"border_style\": {},\n", p.border_style));
o.push_str(&format!(
" \"icon\": \"{}\",\n",
json_escape(&p.icon)
));
o.push_str(&format!(" \"position\": {},\n", p.position));
o.push_str(&format!(" \"window_state\": {}\n", p.window_state));
o.push_str(" },\n");
o.push_str(" \"widgets\": [");
for (i, w) in p.widgets.iter().enumerate() {
@@ -144,6 +151,10 @@ pub fn load_from_str(text: &str, path: &str) -> Result<Project, String> {
p.win_height = jint(win.get("height"), p.win_height);
p.background = jstr(win.get("background"), "");
p.menubar = jstr(win.get("menubar"), "");
p.border_style = jint(win.get("border_style"), 0).clamp(0, 3);
p.icon = jstr(win.get("icon"), "");
p.position = jint(win.get("position"), 0).clamp(0, 4);
p.window_state = jint(win.get("window_state"), 0).clamp(0, 3);
}
if !(50..=20000).contains(&p.win_width) {
p.win_width = 800;
@@ -224,7 +235,7 @@ mod tests {
#[test]
fn empty_project_saves_like_cpp() {
let want = "{\n \"format\": \"lightgui\",\n \"version\": 1,\n \"window\": {\n \"title\": \"Main Window\",\n \"class_name\": \"MyWindow\",\n \"width\": 800,\n \"height\": 600,\n \"background\": \"\",\n \"menubar\": \"\"\n },\n \"widgets\": []\n}\n";
let want = "{\n \"format\": \"lightgui\",\n \"version\": 1,\n \"window\": {\n \"title\": \"Main Window\",\n \"class_name\": \"MyWindow\",\n \"width\": 800,\n \"height\": 600,\n \"background\": \"\",\n \"menubar\": \"\",\n \"border_style\": 0,\n \"icon\": \"\",\n \"position\": 0,\n \"window_state\": 0\n },\n \"widgets\": []\n}\n";
assert_eq!(save_to_string(&Project::default()), want);
}
+58 -1
View File
@@ -295,7 +295,7 @@ pub fn refresh_props(app: &Shared) {
match sel {
None => {
selected_label.set_text("Window (Root)");
let (title, class_name, w, h, bg, menubar) = {
let (title, class_name, w, h, bg, menubar, border_style, icon, position, window_state) = {
let a = app.borrow();
(
a.project.title.clone(),
@@ -304,6 +304,10 @@ pub fn refresh_props(app: &Shared) {
a.project.win_height,
a.project.background.clone(),
a.project.menubar.clone(),
a.project.border_style,
a.project.icon.clone(),
a.project.position,
a.project.window_state,
)
};
let mk_entry = |app: &Shared, text: &str, which: &'static str| {
@@ -322,6 +326,7 @@ pub fn refresh_props(app: &Shared) {
// "background" is handled by its own changed
// handler (set_project_background, validated).
"menubar" => a.project.menubar = text,
"icon" => a.project.icon = text,
_ => {}
}
});
@@ -417,6 +422,58 @@ pub fn refresh_props(app: &Shared) {
edit_menus_dialog(&app_menus, &menubar_text);
});
add_row(&grid, row, "menu bar", &menus_btn.upcast());
row += 1;
// Window-level props (§2.20): border style, icon, position,
// window state — mirrors the C++ root Inspector.
let mk_win_combo = |app: &Shared, labels: &[&str], active: i32, which: &'static str| {
let c = gtk::ComboBoxText::new();
for l in labels {
c.append_text(l);
}
c.set_active(Some(active as u32));
let app2 = app.clone();
c.connect_changed(move |combo| {
if app2.borrow().syncing_props {
return;
}
let Some(active) = combo.active() else { return };
let mut a = app2.borrow_mut();
match which {
"border-style" => a.project.border_style = active as i32,
"position" => a.project.position = active as i32,
"window-state" => a.project.window_state = active as i32,
_ => {}
}
});
c
};
add_row(
&grid,
row,
"border-style",
&mk_win_combo(app, &["Default", "None", "Single", "Dialog"], border_style, "border-style").upcast(),
);
row += 1;
add_row(
&grid,
row,
"icon",
&mk_entry(app, &icon, "icon").upcast(),
);
row += 1;
add_row(
&grid,
row,
"position",
&mk_win_combo(app, &["Default", "Center", "ScreenCenter", "MainFormCenter", "Designed"], position, "position").upcast(),
);
row += 1;
add_row(
&grid,
row,
"window-state",
&mk_win_combo(app, &["Normal", "Minimized", "Maximized", "Fullscreen"], window_state, "window-state").upcast(),
);
}
Some((id, name, wtype, x, y, w, h, signals)) => {
selected_label.set_text(&format!("{name} ({wtype})"));
+4
View File
@@ -129,6 +129,10 @@ pub fn convert(entries: &[LayoutEntry], class_name: &str, title: &str) -> Conver
win_height: 600.max(max_bottom + 20),
background: String::new(),
menubar: String::new(),
border_style: 0,
icon: String::new(),
position: 0,
window_state: 0,
widgets,
},
mapped,