From 51e1e3b416862774ee87151326fd3bb8e436da4d Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 21 Nov 2014 15:21:49 +0100 Subject: [PATCH] textview: make magnifier size dependent on text size The magnifier is now set enough height to show the line being currently manipulated, which makes it just big enough to show the layout height at that size and magnification. --- gtk/gtktextview.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 28c8411706..b619ab0998 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -1639,7 +1639,6 @@ _gtk_text_view_ensure_magnifier (GtkTextView *text_view) return; priv->magnifier = _gtk_magnifier_new (GTK_WIDGET (text_view)); - gtk_widget_set_size_request (priv->magnifier, 100, 60); _gtk_magnifier_set_magnification (GTK_MAGNIFIER (priv->magnifier), 2.0); priv->magnifier_popover = gtk_popover_new (GTK_WIDGET (text_view)); gtk_style_context_add_class (gtk_widget_get_style_context (priv->magnifier_popover), @@ -4720,28 +4719,41 @@ gtk_text_view_set_handle_position (GtkTextView *text_view, static void gtk_text_view_show_magnifier (GtkTextView *text_view, GtkTextIter *iter, - gint x) + gint x, + gint y) { cairo_rectangle_int_t rect; GtkTextViewPrivate *priv; - GtkAllocation allocation; + GtkRequisition req; - _gtk_text_view_ensure_magnifier (text_view); - gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation); +#define N_LINES 1 priv = text_view->priv; + _gtk_text_view_ensure_magnifier (text_view); + + /* Set size/content depending on iter rect */ gtk_text_view_get_iter_location (text_view, iter, (GdkRectangle *) &rect); + rect.x = x + priv->xoffset; gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_TEXT, rect.x, rect.y, &rect.x, &rect.y); _text_window_to_widget_coords (text_view, &rect.x, &rect.y); - rect.x = x; + req.height = rect.height * N_LINES * + _gtk_magnifier_get_magnification (GTK_MAGNIFIER (priv->magnifier)); + req.width = MAX ((req.height * 4) / 3, 80); + gtk_widget_set_size_request (priv->magnifier, req.width, req.height); _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), rect.x, rect.y + rect.height / 2); + + rect.y += rect.height / 4; + rect.height -= rect.height / 4; gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover), &rect); + gtk_widget_show (priv->magnifier_popover); + +#undef N_LINES } static void @@ -4832,9 +4844,9 @@ gtk_text_view_handle_dragged (GtkTextHandle *handle, } if (_gtk_text_handle_get_is_dragged (priv->text_handle, cursor_pos)) - gtk_text_view_show_magnifier (text_view, &cursor, x); + gtk_text_view_show_magnifier (text_view, &cursor, x, y); else - gtk_text_view_show_magnifier (text_view, &bound, x); + gtk_text_view_show_magnifier (text_view, &bound, x, y); } static void @@ -7224,7 +7236,7 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture, { _gtk_text_view_ensure_text_handles (text_view); gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_SELECTION); - gtk_text_view_show_magnifier (text_view, &cursor, x); + gtk_text_view_show_magnifier (text_view, &cursor, x, y); } }