Add a font picker button beside the font-name property

The font-name entry gets a Pick button (same pattern as the Color
Pick button) that opens a font chooser listing the available system
fonts. Choosing one sets font-name to the picked family; setting the
entry text fires the existing changed handler, so the pick
live-applies exactly like typing the name. Only the family is stored
(size/bold/italic stay separate properties). The dialog is hidden,
not closed, after run() (close() leaves it mapped in this gtk-rs
build).
This commit is contained in:
cnmcdee committed 2026-12-01 02:01:55 +00:00
1 parent 1eabec03f5
commit 6a7c4c7197
1 file changed
+39 -1
+39 -1
View File
@@ -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 => {