[gimp] app: make GimpFgBgEditor a width-for-height widget.



commit 41e27a8428bbd2615cf113d1cc662790f784ae23
Author: Jehan <jehan girinstud io>
Date:   Tue Feb 12 14:32:43 2019 +0100

    app: make GimpFgBgEditor a width-for-height widget.
    
    This widget was not working well without setting a size request. In
    particular, in the color editor, if we were not packing with expand and
    fill to TRUE, then it ended up as an invisible widget (too small to be
    seen). On the other hand, with expand/fill, it ended up taking as much
    place as possible, and in particular expanding horizontally in an ugly
    way.
    
    First of all, I make it a width-for-height widget, so that it keeps by
    default a pretty ratio (the width must be a bit bigger than the height).
    Then I give it a default size request because this widget makes no sense
    if it is too small (it packs quite a lot of elements with fg and bg
    colors, swap and default colors icons).
    Finally I can remove the expand/fill request in the GimpColorEditor. And
    now the fg/bg widget appears with a nice ratio.
    
    Note: this is GTK+3 only commit as the size request mode didn't exist
    back in GTK+2.

 app/widgets/gimpcoloreditor.c |  2 +-
 app/widgets/gimpfgbgeditor.c  | 40 ++++++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/app/widgets/gimpcoloreditor.c b/app/widgets/gimpcoloreditor.c
index acb93b87c2..4e28fd6744 100644
--- a/app/widgets/gimpcoloreditor.c
+++ b/app/widgets/gimpcoloreditor.c
@@ -240,7 +240,7 @@ gimp_color_editor_init (GimpColorEditor *editor)
 
   /*  FG/BG editor  */
   editor->fg_bg = gimp_fg_bg_editor_new (NULL);
-  gtk_box_pack_start (GTK_BOX (hbox), editor->fg_bg, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), editor->fg_bg, FALSE, FALSE, 0);
   gtk_widget_show (editor->fg_bg);
 
   g_signal_connect (editor->fg_bg, "notify::active-color",
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 424ccb6376..70681764c8 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -67,6 +67,14 @@ static void     gimp_fg_bg_editor_get_property      (GObject          *object,
                                                      GValue           *value,
                                                      GParamSpec       *pspec);
 
+static GtkSizeRequestMode
+                gimp_fg_bg_editor_get_request_mode  (GtkWidget        *widget);
+static void
+   gimp_fg_bg_editor_get_preferred_width_for_height (GtkWidget        *widget,
+                                                     gint              height,
+                                                     gint             *minimum_width,
+                                                     gint             *natural_width);
+
 static void     gimp_fg_bg_editor_style_updated     (GtkWidget        *widget);
 static gboolean gimp_fg_bg_editor_draw              (GtkWidget        *widget,
                                                      cairo_t          *cr);
@@ -136,12 +144,14 @@ gimp_fg_bg_editor_class_init (GimpFgBgEditorClass *klass)
   object_class->set_property         = gimp_fg_bg_editor_set_property;
   object_class->get_property         = gimp_fg_bg_editor_get_property;
 
-  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;
-  widget_class->button_release_event = gimp_fg_bg_editor_button_release;
-  widget_class->drag_motion          = gimp_fg_bg_editor_drag_motion;
-  widget_class->query_tooltip        = gimp_fg_bg_editor_query_tooltip;
+  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->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;
+  widget_class->button_release_event           = gimp_fg_bg_editor_button_release;
+  widget_class->drag_motion                    = gimp_fg_bg_editor_drag_motion;
+  widget_class->query_tooltip                  = gimp_fg_bg_editor_query_tooltip;
 
   g_object_class_install_property (object_class, PROP_CONTEXT,
                                    g_param_spec_object ("context",
@@ -179,6 +189,8 @@ gimp_fg_bg_editor_init (GimpFgBgEditor *editor)
   gimp_widget_track_monitor (GTK_WIDGET (editor),
                              G_CALLBACK (gimp_fg_bg_editor_destroy_transform),
                              NULL);
+
+  gtk_widget_set_size_request (GTK_WIDGET (editor), 32, 24);
 }
 
 static void
@@ -239,6 +251,22 @@ gimp_fg_bg_editor_get_property (GObject    *object,
     }
 }
 
+static GtkSizeRequestMode
+gimp_fg_bg_editor_get_request_mode (GtkWidget *widget)
+{
+  return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
+static void
+gimp_fg_bg_editor_get_preferred_width_for_height (GtkWidget *widget,
+                                                  gint       height,
+                                                  gint      *minimum_width,
+                                                  gint      *natural_width)
+{
+  *minimum_width = height * 4/3;
+  *natural_width = height * 4/3;
+}
+
 static void
 gimp_fg_bg_editor_style_updated (GtkWidget *widget)
 {


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