[gtk+/touch-selection-improvements: 10/17] textview: make magnifier size dependent on text size



commit 2d7fe86c7ec933d34304921910aea54f7f995dd4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Nov 21 15:21:49 2014 +0100

    textview: make magnifier size dependent on text size
    
    The magnifier is now set enough height to show the line being currently
    manipulated, and the shown coordinates are made relative to the iter
    position on the Y axis so it always guarantees to show the full line.
    
    The popover positioning (and the X axis of the shown content) are made
    relative to the touch position, with an extra margin accounting for the
    finger, similarly to how it was done previously.

 gtk/gtktextview.c |   35 +++++++++++++++++++++++++++--------
 1 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index eeb4ae6..a268b38 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,48 @@ 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;
 
+  priv = text_view->priv;
   _gtk_text_view_ensure_magnifier (text_view);
-  gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation);
 
-  priv = text_view->priv;
+  /* Set size/content depending on iter rect */
   gtk_text_view_get_iter_location (text_view, iter,
                                    (GdkRectangle *) &rect);
+  rect.x = x;
   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 *
+    _gtk_magnifier_get_magnification (GTK_MAGNIFIER (priv->magnifier));
+  req.width = (req.height * 4) / 3;
+  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);
+
+#define RECT_WIDTH 40
+
+  gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation);
+  x = CLAMP (x, 0, allocation.width);
+  y = CLAMP (y, 0, allocation.height);
+  rect.x = x - (RECT_WIDTH / 2);
+  rect.y = y - (RECT_WIDTH / 2);
+  rect.width = rect.height = RECT_WIDTH;
+  _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover),
                                &rect);
+
   gtk_widget_show (priv->magnifier_popover);
+
+#undef RECT_WIDTH
 }
 
 static void
@@ -4832,9 +4851,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
@@ -7219,7 +7238,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);
     }
 }
 


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