[balsa/gtk4: 89/294] libbalsa-misc: Install libbalsa_button_box_button




commit d3929008d4c198fdd49602c1b407793ec1f3ec17
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Aug 28 17:15:13 2020 -0400

    libbalsa-misc: Install libbalsa_button_box_button
    
    Create a button widget that can be added to a GtkBox with the same
    look as a GtkButton in a GtkButtonBox
    
    modified:   libbalsa/misc.c
    modified:   libbalsa/misc.h

 libbalsa/misc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 libbalsa/misc.h |  4 ++++
 2 files changed, 52 insertions(+)
---
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 3474a2169..ae143d4e7 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -1252,3 +1252,51 @@ libbalsa_parser_options(void)
 {
     return parser_options;
 }
+
+/*
+ * libbalsa_button_box_button
+ *
+ * Create a button widget that can be added to a GtkBox with the same
+ * look as a regular button in a GtkButtonBox
+ *
+ * markup:     mnemonic text for the button;
+ * size_group: managed by the caller, to make buttons the same size;
+               could be created as gtk_size_group_new(GTK_SIZE_GROUP_BOTH),
+               to ensure common widths and heights;
+ * align:      how to align the button in its allocated space.
+ *
+ * To replace a GtkButtonBox with the default GTK_BUTTONBOX_EDGE style,
+ * align should be GTK_ALIGN_START for the first button, GTK_ALIGN_END
+ * for the last button, and GTK_ALIGN_CENTER for other buttons.
+ * To replace a GtkButtonBox with style GTK_BUTTONBOX_SPREAD,
+ * align should be GTK_ALIGN_CENTER for all buttons;
+ * To replace a GtkButtonBox with style GTK_BUTTONBOX_EXPAND,
+ * align should be GTK_ALIGN_FILL for all buttons.
+ */
+
+/* Margin to increase the width of the button, to approximate the look
+ * of a GtkButtonBox; may be a pixel or two too small: */
+#define LIBBALSA_LABEL_MARGIN 12
+
+GtkWidget *
+libbalsa_button_box_button(const gchar  *markup,
+                           GtkSizeGroup *size_group,
+                           GtkAlign      align)
+{
+    GtkWidget *label;
+    GtkWidget *button;
+
+    label = gtk_label_new(NULL);
+    gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), markup);
+    gtk_widget_set_margin_start(label, LIBBALSA_LABEL_MARGIN);
+    gtk_widget_set_margin_end(label, LIBBALSA_LABEL_MARGIN);
+    gtk_widget_show(label);
+    gtk_size_group_add_widget(size_group, label);
+
+    button = gtk_button_new();
+    gtk_container_add(GTK_CONTAINER(button), label);
+    gtk_widget_set_hexpand(button, TRUE);
+    gtk_widget_set_halign(button, align);
+
+    return button;
+}
diff --git a/libbalsa/misc.h b/libbalsa/misc.h
index bbc7f9dbe..e8d3e6491 100644
--- a/libbalsa/misc.h
+++ b/libbalsa/misc.h
@@ -163,5 +163,9 @@ gchar *libbalsa_font_string_to_css(const gchar * font_string, const gchar * name
 void libbalsa_parser_options_init(void);
 GMimeParserOptions *libbalsa_parser_options(void);
 
+GtkWidget * libbalsa_button_box_button(const gchar  *markup,
+                                       GtkSizeGroup *size_group,
+                                       GtkAlign      align);
+
 
 #endif                         /* __LIBBALSA_MISC_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]