[gimp] app: properly resize the GimpFgBgEditor when changing icon size.



commit 624493af4b87661766af9b7bf53b5f26d7770e1e
Author: Jehan <jehan girinstud io>
Date:   Mon Sep 26 21:53:13 2022 +0200

    app: properly resize the GimpFgBgEditor when changing icon size.
    
    This is the needed improvements I was talking about in commit 00fbcbea0b. Right
    now, when changing the icon size, the FG/BG color widget was not immediately
    resizing. It needed a restart of GIMP.
    
    Now it will properly react to "style-updated" signal, but also to "theme"
    property of GimpGuiConfig.
    The reset of the color icon pixbufs is also needed when GimpFgBgEditor size is
    re-allocated.

 app/widgets/gimpfgbgeditor.c | 12 ++++++++++++
 app/widgets/gimptoolbox.c    | 46 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 4cf08f21f3..900a9833b1 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -83,6 +83,8 @@ static void
                                                      gint             *minimum_width,
                                                      gint             *natural_width);
 
+static void     gimp_fg_bg_editor_size_allocate     (GtkWidget        *editor,
+                                                     GtkAllocation    *allocation);
 static void     gimp_fg_bg_editor_style_updated     (GtkWidget        *widget);
 static gboolean gimp_fg_bg_editor_draw              (GtkWidget        *widget,
                                                      cairo_t          *cr);
@@ -190,6 +192,7 @@ gimp_fg_bg_editor_class_init (GimpFgBgEditorClass *klass)
 
   widget_class->get_request_mode               = gimp_fg_bg_editor_get_request_mode;
   widget_class->get_preferred_width_for_height = gimp_fg_bg_editor_get_preferred_width_for_height;
+  widget_class->size_allocate                  = gimp_fg_bg_editor_size_allocate;
   widget_class->style_updated                  = gimp_fg_bg_editor_style_updated;
   widget_class->draw                           = gimp_fg_bg_editor_draw;
   widget_class->button_press_event             = gimp_fg_bg_editor_button_press;
@@ -311,6 +314,15 @@ gimp_fg_bg_editor_get_preferred_width_for_height (GtkWidget *widget,
   *natural_width = height;
 }
 
+static void
+gimp_fg_bg_editor_size_allocate (GtkWidget      *widget,
+                                 GtkAllocation  *allocation)
+{
+  GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
+
+  gimp_fg_bg_editor_style_updated (widget);
+}
+
 static void
 gimp_fg_bg_editor_style_updated (GtkWidget *widget)
 {
diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c
index de82aabd58..9fabdd11bc 100644
--- a/app/widgets/gimptoolbox.c
+++ b/app/widgets/gimptoolbox.c
@@ -121,10 +121,18 @@ static void        gimp_toolbox_book_added              (GimpDock       *dock,
                                                          GimpDockbook   *dockbook);
 static void        gimp_toolbox_book_removed            (GimpDock       *dock,
                                                          GimpDockbook   *dockbook);
+
+static void        gimp_toolbox_notify_theme            (GimpGuiConfig  *config,
+                                                         GParamSpec     *pspec,
+                                                         GimpToolbox    *toolbox);
+
+static void        gimp_toolbox_palette_style_updated   (GtkWidget      *palette,
+                                                         GimpToolbox    *toolbox);
+
 static void        gimp_toolbox_wilber_style_updated    (GtkWidget      *widget,
                                                          GimpToolbox    *toolbox);
-static gboolean    gimp_toolbox_draw_wilber             (GtkWidget             *widget,
-                                                         cairo_t               *cr);
+static gboolean    gimp_toolbox_draw_wilber             (GtkWidget      *widget,
+                                                         cairo_t        *cr);
 static GtkWidget * toolbox_create_color_area            (GimpToolbox    *toolbox,
                                                          GimpContext    *context);
 static GtkWidget * toolbox_create_foo_area              (GimpToolbox    *toolbox,
@@ -564,6 +572,33 @@ gimp_toolbox_set_drag_handler (GimpToolbox  *toolbox,
 
 /*  private functions  */
 
+static void
+gimp_toolbox_notify_theme (GimpGuiConfig *config,
+                           GParamSpec    *pspec,
+                           GimpToolbox   *toolbox)
+{
+  gimp_toolbox_palette_style_updated (GTK_WIDGET (toolbox->p->tool_palette), toolbox);
+}
+
+static void
+gimp_toolbox_palette_style_updated (GtkWidget   *widget,
+                                    GimpToolbox *toolbox)
+{
+  GtkIconSize  tool_icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+  gint         icon_width     = 40;
+  gint         icon_height    = 38;
+
+  gtk_widget_style_get (widget,
+                        "tool-icon-size", &tool_icon_size,
+                        NULL);
+  gtk_icon_size_lookup (tool_icon_size, &icon_width, &icon_height);
+
+  gtk_widget_set_size_request (toolbox->p->color_area,
+                               (gint) (icon_width * 1.75),
+                               (gint) (icon_height * 1.75));
+  gtk_widget_queue_resize (toolbox->p->color_area);
+}
+
 static void
 gimp_toolbox_wilber_style_updated (GtkWidget   *widget,
                                    GimpToolbox *toolbox)
@@ -614,6 +649,13 @@ toolbox_create_color_area (GimpToolbox *toolbox,
                 "margin-bottom", 2,
                 NULL);
 
+  g_signal_connect (toolbox->p->tool_palette, "style-updated",
+                    G_CALLBACK (gimp_toolbox_palette_style_updated),
+                    toolbox);
+  g_signal_connect_after (GIMP_GUI_CONFIG (toolbox->p->context->gimp->config),
+                          "notify::theme",
+                          G_CALLBACK (gimp_toolbox_notify_theme),
+                          toolbox);
   return col_area;
 }
 


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