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). Added to both the GTK
and the XFrame property editors.
This commit is contained in:
cnmcdee committed 2026-12-01 01:57:14 +00:00
1 parent 5f12f0423e
commit 55daf32bde
1 file changed
+53
+53
View File
@@ -1903,6 +1903,7 @@ static void on_event_toggled(GtkToggleButton*, gpointer binding);
static void on_prop_spin_changed(GtkSpinButton*, gpointer binding);
static void on_prop_enum_changed(GtkComboBoxText*, gpointer binding);
static void on_prop_pick_clicked(GtkButton*, gpointer binding);
static void on_prop_font_clicked(GtkButton*, gpointer binding);
static void on_xframe_selection_changed(int id);
static void on_xframe_motion();
static void on_xframe_spin_changed(GtkSpinButton*, gpointer which);
@@ -1978,6 +1979,21 @@ static GtkWidget* make_prop_editor(Item* it, const PropDef& def) {
gtk_entry_set_text(GTK_ENTRY(e), value.c_str());
g_signal_connect(e, "changed", G_CALLBACK(on_prop_entry_changed),
b);
// 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.
if (std::strcmp(def.name, "font-name") == 0) {
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
GtkWidget* pick = gtk_button_new_with_label("Pick…");
PickBinding* pb = new PickBinding{GTK_ENTRY(e)};
g_pick_bindings.push_back(pb);
g_signal_connect(pick, "clicked",
G_CALLBACK(on_prop_font_clicked), pb);
gtk_box_pack_start(GTK_BOX(box), e, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), pick, FALSE, FALSE, 0);
return box;
}
return e;
}
case PropKind::Color: {
@@ -2067,6 +2083,19 @@ static GtkWidget* make_xframe_prop_editor(int id, const Widget& model,
gtk_entry_set_text(GTK_ENTRY(e), value.c_str());
g_signal_connect(e, "changed",
G_CALLBACK(on_xframe_entry_changed), b);
// Font picker beside the font-name entry (same pattern as
// the Color "Pick…" button).
if (std::strcmp(def.name, "font-name") == 0) {
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
GtkWidget* pick = gtk_button_new_with_label("Pick…");
PickBinding* pb = new PickBinding{GTK_ENTRY(e)};
g_pick_bindings.push_back(pb);
g_signal_connect(pick, "clicked",
G_CALLBACK(on_prop_font_clicked), pb);
gtk_box_pack_start(GTK_BOX(box), e, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), pick, FALSE, FALSE, 0);
return box;
}
return e;
}
case PropKind::Color: {
@@ -2956,6 +2985,30 @@ static void run_color_pick(GtkEntry* entry) {
gtk_widget_destroy(dlg);
}
// Font picker for the font-name property (mirrors run_color_pick).
// Only the font FAMILY goes into font-name; size/bold/italic are
// separate properties. Setting the entry text fires "changed", so the
// pick live-applies exactly like typing the name.
static void run_font_pick(GtkEntry* entry) {
GtkWidget* dlg = gtk_font_chooser_dialog_new("Pick a font",
GTK_WINDOW(g_window));
const char* cur = gtk_entry_get_text(entry);
if (cur && *cur) gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dlg), cur);
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK) {
PangoFontFamily* fam =
gtk_font_chooser_get_font_family(GTK_FONT_CHOOSER(dlg));
if (fam) {
gtk_entry_set_text(entry,
pango_font_family_get_name(fam));
}
}
gtk_widget_destroy(dlg);
}
static void on_prop_font_clicked(GtkButton*, gpointer binding) {
run_font_pick(((PickBinding*)binding)->entry);
}
static void on_prop_pick_clicked(GtkButton*, gpointer binding) {
run_color_pick(((PickBinding*)binding)->entry);
}