From 0347d25fc929330e0eace01b837bd4e748ed5582 Mon Sep 17 00:00:00 2001 From: "Geoffrey D. Bennett" Date: Fri, 1 Dec 2023 00:18:38 +1030 Subject: [PATCH] Center-align text in combo boxes --- src/widget-combo.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/widget-combo.c b/src/widget-combo.c index ed3f619..127709a 100644 --- a/src/widget-combo.c +++ b/src/widget-combo.c @@ -14,8 +14,24 @@ static void combo_box_updated(struct alsa_elem *elem) { gtk_combo_box_set_active(GTK_COMBO_BOX(elem->widget), value); } +// Center-align text in the combo box +static void combo_box_center_text(GtkComboBoxText *widget) { + GList *renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(widget)); + + // Assuming there's only one renderer, which is the case with GtkComboBoxText + GtkCellRenderer *renderer = (GtkCellRenderer *)g_list_nth_data(renderers, 0); + + // Set the "xalign" property of the renderer to center-align text + g_object_set(renderer, "xalign", (gfloat)0.5, NULL); + + // Free the GList when done + g_list_free(renderers); +} + GtkWidget *make_combo_box_alsa_elem(struct alsa_elem *elem) { GtkWidget *combo_box = gtk_combo_box_text_new(); + combo_box_center_text(GTK_COMBO_BOX_TEXT(combo_box)); + int count = alsa_get_item_count(elem); for (int i = 0; i < count; i++) {