[gnome-software/1392-unify-lozenge-styling: 2/13] gs-summary-tile: Replace GsSummaryTileLayout with GsLayoutManager




commit 9a479c0245c8dccaed72d3e42d18681380cf4276
Author: Milan Crha <mcrha redhat com>
Date:   Tue May 3 15:40:17 2022 +0200

    gs-summary-tile: Replace GsSummaryTileLayout with GsLayoutManager
    
    To avoid code duplication.

 src/gs-summary-tile-layout.c | 114 -------------------------------------------
 src/gs-summary-tile-layout.h |  25 ----------
 src/gs-summary-tile.c        |  32 ++++++++++--
 src/meson.build              |   1 -
 4 files changed, 28 insertions(+), 144 deletions(-)
---
diff --git a/src/gs-summary-tile.c b/src/gs-summary-tile.c
index c447eb617..bf259fd2d 100644
--- a/src/gs-summary-tile.c
+++ b/src/gs-summary-tile.c
@@ -12,7 +12,7 @@
 #include <glib/gi18n.h>
 
 #include "gs-summary-tile.h"
-#include "gs-summary-tile-layout.h"
+#include "gs-layout-manager.h"
 #include "gs-common.h"
 
 struct _GsSummaryTile
@@ -100,11 +100,36 @@ gs_summary_tile_refresh (GsAppTile *self)
        }
 }
 
+static void
+gs_summary_tile_layout_measure_cb (GtkLayoutManager *layout_manager,
+                                  GtkWidget        *widget,
+                                  GtkOrientation    orientation,
+                                  gint              for_size,
+                                  gint             *minimum,
+                                  gint             *natural,
+                                  gint             *minimum_baseline,
+                                  gint             *natural_baseline,
+                                  gpointer          user_data)
+{
+       GsSummaryTile *self = user_data;
+
+       /* Limit the natural width */
+       if (self->preferred_width > 0 && orientation == GTK_ORIENTATION_HORIZONTAL)
+               *natural = MAX (*minimum, self->preferred_width);
+}
+
 static void
 gs_summary_tile_init (GsSummaryTile *tile)
 {
+       GtkLayoutManager *layout_manager;
+
        tile->preferred_width = -1;
        gtk_widget_init_template (GTK_WIDGET (tile));
+
+       layout_manager = gtk_widget_get_layout_manager (GTK_WIDGET (tile));
+       g_warn_if_fail (layout_manager != NULL);
+       g_signal_connect_object (layout_manager, "measure",
+               G_CALLBACK (gs_summary_tile_layout_measure_cb), tile, 0);
 }
 
 static void
@@ -138,8 +163,7 @@ gs_summary_tile_set_property (GObject *object,
        case PROP_PREFERRED_WIDTH:
                app_tile->preferred_width = g_value_get_int (value);
                layout_manager = gtk_widget_get_layout_manager (GTK_WIDGET (app_tile));
-               gs_summary_tile_layout_set_preferred_width (GS_SUMMARY_TILE_LAYOUT (layout_manager),
-                                                           g_value_get_int (value));
+               gtk_layout_manager_layout_changed (layout_manager);
                g_object_notify_by_pspec (object, obj_props[PROP_PREFERRED_WIDTH]);
                break;
        default:
@@ -182,7 +206,7 @@ gs_summary_tile_class_init (GsSummaryTileClass *klass)
        g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
 
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-summary-tile.ui");
-       gtk_widget_class_set_layout_manager_type (widget_class, GS_TYPE_SUMMARY_TILE_LAYOUT);
+       gtk_widget_class_set_layout_manager_type (widget_class, GS_TYPE_LAYOUT_MANAGER);
        /* Override the 'button' class name, to be able to turn off hover states */
        gtk_widget_class_set_css_name (widget_class, "gs-summary-tile");
 
diff --git a/src/meson.build b/src/meson.build
index d945ba83c..4b40abdb8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -80,7 +80,6 @@ gnome_software_sources = [
   'gs-star-widget.c',
   'gs-storage-context-dialog.c',
   'gs-summary-tile.c',
-  'gs-summary-tile-layout.c',
   'gs-update-dialog.c',
   'gs-update-list.c',
   'gs-update-monitor.c',


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