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
This commit is contained in:
Matthias Clasen
2016-03-11 22:44:17 -05:00
parent 5f00a9b4ec
commit d345a7a60e

View File

@ -61,6 +61,8 @@ struct _GtkColorEditorPrivate
GtkAdjustment *v_adj; GtkAdjustment *v_adj;
GtkAdjustment *a_adj; GtkAdjustment *a_adj;
gint popup_position;
guint text_changed : 1; guint text_changed : 1;
guint use_alpha : 1; guint use_alpha : 1;
}; };
@ -170,6 +172,7 @@ dismiss_current_popup (GtkColorEditor *editor)
{ {
gtk_widget_hide (editor->priv->current_popup); gtk_widget_hide (editor->priv->current_popup);
editor->priv->current_popup = NULL; editor->priv->current_popup = NULL;
editor->priv->popup_position = 0;
if (editor->priv->popdown_focus) if (editor->priv->popdown_focus)
{ {
gtk_widget_grab_focus (editor->priv->popdown_focus); gtk_widget_grab_focus (editor->priv->popdown_focus);
@ -185,21 +188,28 @@ popup_edit (GtkWidget *widget,
GtkWidget *popup = NULL; GtkWidget *popup = NULL;
GtkWidget *toplevel; GtkWidget *toplevel;
GtkWidget *focus; GtkWidget *focus;
gint position;
gint s, e;
if (widget == editor->priv->sv_plane) if (widget == editor->priv->sv_plane)
{ {
popup = editor->priv->sv_popup; popup = editor->priv->sv_popup;
focus = editor->priv->s_entry; focus = editor->priv->s_entry;
position = 0;
} }
else if (widget == editor->priv->h_slider) else if (widget == editor->priv->h_slider)
{ {
popup = editor->priv->h_popup; popup = editor->priv->h_popup;
focus = editor->priv->h_entry; 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) else if (widget == editor->priv->a_slider)
{ {
popup = editor->priv->a_popup; popup = editor->priv->a_popup;
focus = editor->priv->a_entry; 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) if (popup == editor->priv->current_popup)
@ -210,6 +220,7 @@ popup_edit (GtkWidget *widget,
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor)); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
editor->priv->popdown_focus = gtk_window_get_focus (GTK_WINDOW (toplevel)); editor->priv->popdown_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
editor->priv->current_popup = popup; editor->priv->current_popup = popup;
editor->priv->popup_position = position;
gtk_widget_show (popup); gtk_widget_show (popup);
gtk_widget_grab_focus (focus); gtk_widget_grab_focus (focus);
} }
@ -248,11 +259,14 @@ get_child_position (GtkOverlay *overlay,
if (widget == editor->priv->sv_popup) 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) if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
allocation->x = 0; allocation->x = 0;
else else
allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width; allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width;
allocation->y = req.height / 3;
} }
else if (widget == editor->priv->h_popup) 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) if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
gtk_widget_translate_coordinates (editor->priv->h_slider, gtk_widget_translate_coordinates (editor->priv->h_slider,
gtk_widget_get_parent (editor->priv->grid), 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); &allocation->x, &allocation->y);
else else
gtk_widget_translate_coordinates (editor->priv->h_slider, gtk_widget_translate_coordinates (editor->priv->h_slider,
gtk_widget_get_parent (editor->priv->grid), 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); &allocation->x, &allocation->y);
} }
else if (widget == editor->priv->a_popup) 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_translate_coordinates (editor->priv->a_slider,
gtk_widget_get_parent (editor->priv->grid), 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); &allocation->x, &allocation->y);
} }
else else