changeset 2276:d7f0254f7d1e

GTK4: Attempt fixing box and item padding using gtk_widget_set_margin_*().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 02 Feb 2021 03:52:56 +0000
parents 51cb73faab6e
children ba81894924cb
files gtk4/dw.c
diffstat 1 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gtk4/dw.c	Mon Feb 01 21:22:31 2021 +0000
+++ b/gtk4/dw.c	Tue Feb 02 03:52:56 2021 +0000
@@ -1021,6 +1021,16 @@
    }
 }
 
+/* Internal function to add padding to boxes or other widgets */
+static void _dw_widget_set_pad(GtkWidget *widget, int pad)
+{
+   /* Set pad for each margin direction on the widget */
+   gtk_widget_set_margin_start(widget, pad);
+   gtk_widget_set_margin_end(widget, pad);
+   gtk_widget_set_margin_top(widget, pad);
+   gtk_widget_set_margin_bottom(widget, pad);
+}
+
 static void _dw_app_activate(GApplication *app, gpointer user_data)
 {
    /* Not sure why this signal is required, but GLib gives warnings
@@ -2011,7 +2021,7 @@
 
    tmp = gtk_grid_new();
    g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type));
-   g_object_set_data(G_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad));
+   _dw_widget_set_pad(tmp, pad);
    gtk_widget_show(tmp);
    return tmp;
 }
@@ -2032,9 +2042,9 @@
    box = gtk_grid_new();
 
    g_object_set_data(G_OBJECT(box), "_dw_boxtype", GINT_TO_POINTER(type));
-   g_object_set_data(G_OBJECT(box), "_dw_boxpad", GINT_TO_POINTER(pad));
    g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box);
-
+   _dw_widget_set_pad(box, pad);
+   
    gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(tmp), box);
    g_object_set_data(G_OBJECT(tmp), "_dw_user", box);
    gtk_widget_show(box);
@@ -2104,12 +2114,11 @@
 
    frame = gtk_frame_new(NULL);
    gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL);
-
+   
    tmp = gtk_grid_new();
-   /* TODO: Fix this! gtk_container_set_border_width(GTK_CONTAINER(tmp), pad); */
    g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type));
-   g_object_set_data(G_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad));
    g_object_set_data(G_OBJECT(frame), "_dw_boxhandle", (gpointer)tmp);
+   _dw_widget_set_pad(tmp, pad);
    gtk_frame_set_child(GTK_FRAME(frame), tmp);
    gtk_widget_show(tmp);
    gtk_widget_show(frame);
@@ -7238,7 +7247,6 @@
           *       this eliminates that by forcing the size to 0.
           */
          height = width = 0;
-         /* TODO: Might need to add "_dw_boxpad" to item here */
       }
 
       /* Do some sanity bounds checking */
@@ -7253,8 +7261,8 @@
       gtk_widget_set_valign(item, vsize ? GTK_ALIGN_FILL : GTK_ALIGN_START);
       gtk_widget_set_hexpand(item, hsize);
       gtk_widget_set_halign(item, hsize ? GTK_ALIGN_FILL : GTK_ALIGN_START);
-      /* TODO: Use the margin property as padding
-      g_object_set(G_OBJECT(item), "margin", pad, NULL);*/
+      /* Set pad for each margin direction on the widget */
+      _dw_widget_set_pad(item, pad);
       /* Add to the grid using insert...
        * rows for vertical boxes and columns for horizontal.
        */
@@ -7910,7 +7918,7 @@
 {
    GtkWidget *label, *child, *oldlabel, **pagearray;
    const gchar *text = NULL;
-   int num, z, realpage = -1, pad;
+   int num, z, realpage = -1;
    char ptext[101] = {0};
 
    snprintf(ptext, 100, "_dw_page%d", (int)pageid);
@@ -7943,13 +7951,6 @@
 
    label = gtk_label_new(text ? text : "");
 
-   if(GTK_IS_GRID(page))
-   {
-      pad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "_dw_boxpad"));
-      /* TODO: Add padding to page with no GtkContainer in GTK4 */
-      pad = pad;
-   }
-
    if(realpage != -1)
       gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage);
    else if(num & ~(0xFF))