[gnome-text-editor] page: improve positioning of search box



commit 55611a2193b5efd8b9a7aeefb8cc4ac9a7b64f43
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 30 14:02:57 2021 -0700

    page: improve positioning of search box
    
    But only when the overview map is present.

 src/editor-page.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 src/editor-page.ui |  1 +
 2 files changed, 42 insertions(+)
---
diff --git a/src/editor-page.c b/src/editor-page.c
index b697193..49175be 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -333,6 +333,46 @@ editor_page_drop_target_drop (EditorPage     *self,
   return FALSE;
 }
 
+static gboolean
+get_child_position_cb (GtkOverlay    *overlay,
+                       GtkWidget     *child,
+                       GtkAllocation *alloc,
+                       EditorPage    *self)
+{
+  GtkRequisition min, nat, map_min;
+
+  g_assert (GTK_IS_OVERLAY (overlay));
+  g_assert (GTK_IS_WIDGET (child));
+  g_assert (alloc != NULL);
+  g_assert (EDITOR_IS_PAGE (self));
+
+  if (child != GTK_WIDGET (self->search_revealer) ||
+      !gtk_widget_get_visible (GTK_WIDGET (self->map)))
+    return FALSE;
+
+  gtk_widget_get_preferred_size (child, &min, &nat);
+  gtk_widget_get_preferred_size (GTK_WIDGET (self->map), &map_min, NULL);
+
+  if (nat.width + map_min.width <= alloc->width)
+    {
+      alloc->x += alloc->width;
+      alloc->x -= map_min.width;
+      alloc->x -= nat.width;
+      alloc->width = nat.width;
+      alloc->y = 0;
+      alloc->height = min.height;
+    }
+  else
+    {
+      alloc->x = 0;
+      alloc->width -= map_min.width;
+      alloc->y = 0;
+      alloc->height = min.height;
+    }
+
+  return TRUE;
+}
+
 static void
 editor_page_dispose (GObject *object)
 {
@@ -499,6 +539,7 @@ editor_page_class_init (EditorPageClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorPage, search_bar);
   gtk_widget_class_bind_template_child (widget_class, EditorPage, search_revealer);
   gtk_widget_class_bind_template_child (widget_class, EditorPage, view);
+  gtk_widget_class_bind_template_callback (widget_class, get_child_position_cb);
 
   gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "search.hide", NULL);
 
diff --git a/src/editor-page.ui b/src/editor-page.ui
index 8d7c38d..c187f4a 100644
--- a/src/editor-page.ui
+++ b/src/editor-page.ui
@@ -12,6 +12,7 @@
         <child>
           <object class="GtkOverlay" id="overlay">
             <property name="vexpand">true</property>
+            <signal name="get-child-position" handler="get_child_position_cb"/>
             <child>
               <object class="GtkBox">
                 <property name="orientation">horizontal</property>


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