[gtk+] color editor: Improve popup positioning



commit d345a7a60ef944f3f06769f9a9fc8822400e1307
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 11 22:44:17 2016 -0500

    color editor: Improve popup positioning
    
    Don't make the popup follow the slider while it is open; that
    makes interaction with it unnecessarily hard. Also move all the
    popups inwards a little bit, so they are not flush with the
    scales, which looks untidy.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763380

 gtk/gtkcoloreditor.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c
index fa80b35..6e37fce 100644
--- a/gtk/gtkcoloreditor.c
+++ b/gtk/gtkcoloreditor.c
@@ -61,6 +61,8 @@ struct _GtkColorEditorPrivate
   GtkAdjustment *v_adj;
   GtkAdjustment *a_adj;
 
+  gint popup_position;
+
   guint text_changed : 1;
   guint use_alpha    : 1;
 };
@@ -170,6 +172,7 @@ dismiss_current_popup (GtkColorEditor *editor)
     {
       gtk_widget_hide (editor->priv->current_popup);
       editor->priv->current_popup = NULL;
+      editor->priv->popup_position = 0;
       if (editor->priv->popdown_focus)
         {
           gtk_widget_grab_focus (editor->priv->popdown_focus);
@@ -185,21 +188,28 @@ popup_edit (GtkWidget      *widget,
   GtkWidget *popup = NULL;
   GtkWidget *toplevel;
   GtkWidget *focus;
+  gint position;
+  gint s, e;
 
   if (widget == editor->priv->sv_plane)
     {
       popup = editor->priv->sv_popup;
       focus = editor->priv->s_entry;
+      position = 0;
     }
   else if (widget == editor->priv->h_slider)
     {
       popup = editor->priv->h_popup;
       focus = editor->priv->h_entry;
+      gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e);
+      position = (s + e) / 2;
     }
   else if (widget == editor->priv->a_slider)
     {
       popup = editor->priv->a_popup;
       focus = editor->priv->a_entry;
+      gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e);
+      position = (s + e) / 2;
     }
 
   if (popup == editor->priv->current_popup)
@@ -210,6 +220,7 @@ popup_edit (GtkWidget      *widget,
       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
       editor->priv->popdown_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
       editor->priv->current_popup = popup;
+      editor->priv->popup_position = position;
       gtk_widget_show (popup);
       gtk_widget_grab_focus (focus);
     }
@@ -248,11 +259,14 @@ get_child_position (GtkOverlay     *overlay,
 
   if (widget == editor->priv->sv_popup)
     {
+      gtk_widget_translate_coordinates (editor->priv->sv_plane,
+                                        gtk_widget_get_parent (editor->priv->grid),
+                                        0, -6,
+                                        &allocation->x, &allocation->y);
       if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
         allocation->x = 0;
       else
         allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width;
-      allocation->y = req.height / 3;
     }
   else if (widget == editor->priv->h_popup)
     {
@@ -262,12 +276,12 @@ get_child_position (GtkOverlay     *overlay,
       if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
         gtk_widget_translate_coordinates (editor->priv->h_slider,
                                           gtk_widget_get_parent (editor->priv->grid),
-                                          - req.width, (s + e - req.height) / 2,
+                                          - req.width - 6, editor->priv->popup_position - req.height / 2,
                                           &allocation->x, &allocation->y);
       else
         gtk_widget_translate_coordinates (editor->priv->h_slider,
                                           gtk_widget_get_parent (editor->priv->grid),
-                                          alloc.width, (s + e - req.height) / 2,
+                                          alloc.width + 6, editor->priv->popup_position - req.height / 2,
                                           &allocation->x, &allocation->y);
     }
   else if (widget == editor->priv->a_popup)
@@ -277,7 +291,7 @@ get_child_position (GtkOverlay     *overlay,
 
       gtk_widget_translate_coordinates (editor->priv->a_slider,
                                         gtk_widget_get_parent (editor->priv->grid),
-                                        (s + e - req.width) / 2, - req.height,
+                                        editor->priv->popup_position - req.width / 2, - req.height - 6,
                                         &allocation->x, &allocation->y);
     }
   else


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