[libdazzle] three-grid: improve margin support



commit 20c1fb6023e5e35235418fc68534bb1395665ecf
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 19 20:11:27 2018 -0800

    three-grid: improve margin support

 src/widgets/dzl-three-grid.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/widgets/dzl-three-grid.c b/src/widgets/dzl-three-grid.c
index 72ee0f2..22dee1d 100644
--- a/src/widgets/dzl-three-grid.c
+++ b/src/widgets/dzl-three-grid.c
@@ -219,8 +219,8 @@ dzl_three_grid_get_preferred_width (GtkWidget *widget,
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (self));
 
-  *min_width = MAX (min_widths[0], min_widths[2]) * 2 + min_widths[1] + margin.left + margin.right + 
(border_width * 2) + (priv->column_spacing * 2);
-  *nat_width = MAX (nat_widths[0], nat_widths[2]) * 2 + nat_widths[1] + margin.left + margin.right + 
(border_width * 2) + (priv->column_spacing * 2);
+  *min_width = MAX (min_widths[0], min_widths[2]) * 2 + min_widths[1] + margin.left + margin.right + 
(border_width * 2) + (priv->column_spacing * 2) + 1;
+  *nat_width = MAX (nat_widths[0], nat_widths[2]) * 2 + nat_widths[1] + margin.left + margin.right + 
(border_width * 2) + (priv->column_spacing * 2) + 1;
 }
 
 static void
@@ -300,7 +300,10 @@ dzl_three_grid_get_preferred_height_for_width (GtkWidget *widget,
   DzlThreeGridPrivate *priv = dzl_three_grid_get_instance_private (self);
   g_autoptr(GHashTable) row_infos = NULL;
   DzlThreeGridRowInfo *row_info;
+  GtkStyleContext *style_context;
   GHashTableIter iter;
+  GtkStateFlags state;
+  GtkBorder margin;
   gint real_min_height = 0;
   gint real_nat_height = 0;
   gint column_min_widths[3];
@@ -317,11 +320,16 @@ dzl_three_grid_get_preferred_height_for_width (GtkWidget *widget,
   width -= border_width * 2;
   width -= priv->column_spacing * 2;
 
+  style_context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (style_context);
+  gtk_style_context_get_margin (style_context, state, &margin);
+  width -= margin.left + margin.right;
+
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_LEFT, &column_min_widths[0], 
&column_nat_widths[0]);
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_CENTER, &column_min_widths[1], 
&column_nat_widths[1]);
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_RIGHT, &column_min_widths[2], 
&column_nat_widths[2]);
 
-  if ((MAX (column_min_widths[0], column_min_widths[2]) * 2 + column_nat_widths[1]) >= width)
+  if ((MAX (column_min_widths[0], column_min_widths[2]) * 2 + column_nat_widths[1]) > width)
     {
       widths[0] = column_min_widths[0];
       widths[2] = column_min_widths[2];
@@ -373,6 +381,9 @@ dzl_three_grid_get_preferred_height_for_width (GtkWidget *widget,
   real_min_height += border_width * 2;
   real_nat_height += border_width * 2;
 
+  real_min_height += margin.top + margin.bottom;
+  real_nat_height += margin.top + margin.bottom;
+
   n_rows = g_hash_table_size (row_infos);
 
   if (n_rows > 1)
@@ -437,9 +448,12 @@ dzl_three_grid_size_allocate (GtkWidget     *widget,
   DzlThreeGridPrivate *priv = dzl_three_grid_get_instance_private (self);
   g_autofree GtkRequestedSize *rows = NULL;
   const GList *iter;
+  GtkStyleContext *style_context;
   GtkAllocation area;
   GtkTextDirection dir;
   GList *values;
+  GtkStateFlags state;
+  GtkBorder margin;
   guint i;
   guint n_rows;
   gint min_height;
@@ -482,6 +496,15 @@ dzl_three_grid_size_allocate (GtkWidget     *widget,
   area.width -= border_width * 2;
   area.height -= border_width * 2;
 
+  style_context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (style_context);
+  gtk_style_context_get_margin (style_context, state, &margin);
+
+  area.x += margin.left;
+  area.width -= margin.left + margin.right;
+  area.y += margin.top;
+  area.height -= margin.top + margin.bottom;
+
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_LEFT, &left_min_width, &left_nat_width);
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_CENTER, &center_min_width, &center_nat_width);
   dzl_three_grid_get_column_width (self, DZL_THREE_GRID_COLUMN_RIGHT, &right_min_width, &right_nat_width);
@@ -539,7 +562,7 @@ dzl_three_grid_size_allocate (GtkWidget     *widget,
       GtkAllocation child_alloc;
       gint baseline;
 
-      if (row_info->nat_above_baseline + row_info->nat_below_baseline <= size->minimum_size)
+      if (row_info->nat_above_baseline + row_info->nat_below_baseline < size->minimum_size)
         baseline = row_info->nat_above_baseline;
       else
         baseline = row_info->min_above_baseline;


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