diff --git a/crates/lightgui-designer/src/inspector.rs b/crates/lightgui-designer/src/inspector.rs index b94cf12..58f242a 100644 --- a/crates/lightgui-designer/src/inspector.rs +++ b/crates/lightgui-designer/src/inspector.rs @@ -104,19 +104,57 @@ fn make_prop_editor(app: &Shared, name: &str, def: PropDef) -> gtk::Widget { let e = gtk::Entry::new(); e.set_text(&cur); let app2 = app.clone(); + let name2 = name.clone(); e.connect_changed(move |entry| { if app2.borrow().syncing_props { return; } let id = { let a = app2.borrow(); - a.find_by_name(&name).map(|i| a.items[i].id) + a.find_by_name(&name2).map(|i| a.items[i].id) }; if let Some(id) = id { let text = entry.text().to_string(); let _ = set_prop(&app2, id, def.name, &text); } }); + // The font-name property gets a picker button beside the + // entry (same pattern as the Color "Pick…" button): the + // user picks from the available system fonts instead of + // having to know a family name. Only the family is stored. + if def.name == "font-name" { + let bx = gtk::Box::new(gtk::Orientation::Horizontal, 4); + let pick = gtk::Button::with_label("Pick…"); + let app3 = app.clone(); + let entry_clone = e.clone(); + let cur2 = cur.clone(); + pick.connect_clicked(move |_| { + let parent = app3.borrow().main_window.clone(); + let dlg = gtk::FontChooserDialog::new( + Some("Pick a font"), + Some(&parent), + ); + if !cur2.is_empty() { + dlg.set_font(&cur2); + } + if dlg.run() == gtk::ResponseType::Ok { + if let Some(desc) = dlg.font_desc() { + if let Some(fam) = desc.family() { + // Fires "changed" -> set_prop, so the + // pick live-applies like typing. + entry_clone.set_text(&fam); + } + } + } + // hide(), not close(): close() leaves the dialog + // mapped in this gtk-rs build (see Install + // Libraries). + dlg.hide(); + }); + bx.pack_start(&e, true, true, 0); + bx.pack_start(&pick, false, false, 0); + return bx.upcast(); + } e.upcast() } PropKind::Color => {