[gnome-shell/wip/carlosg/appgrid-navigation: 18/29] st/viewport: Add clip-to-view property




commit 13b2ce24f9296ed7ac73fb83459339f9b678e459
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Feb 3 12:03:11 2021 +0100

    st/viewport: Add clip-to-view property
    
    This property controls whether the viewport clips the content to its own
    allocation or not. This will be necessary in special modes that we want to
    render past the viewport inside a scrollview.

 src/st/st-viewport.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/st/st-viewport.c b/src/st/st-viewport.c
index c663ae4cd3..e2593196e8 100644
--- a/src/st/st-viewport.c
+++ b/src/st/st-viewport.c
@@ -55,6 +55,7 @@ static void st_viewport_scrollable_interface_init (StScrollableInterface *iface)
 
 enum {
   PROP_0,
+  PROP_CLIP_TO_VIEW,
   PROP_HADJUST,
   PROP_VADJUST
 };
@@ -63,6 +64,7 @@ typedef struct
 {
   StAdjustment *hadjustment;
   StAdjustment *vadjustment;
+  gboolean clip_to_view;
 } StViewportPrivate;
 
 G_DEFINE_TYPE_WITH_CODE (StViewport, st_viewport, ST_TYPE_WIDGET,
@@ -163,12 +165,28 @@ st_viewport_scrollable_interface_init (StScrollableInterface *iface)
   iface->get_adjustments = scrollable_get_adjustments;
 }
 
+static void
+st_viewport_set_clip_to_view (StViewport *viewport,
+                              gboolean    clip_to_view)
+{
+  StViewportPrivate *priv =
+    st_viewport_get_instance_private (viewport);
+
+  if (!!priv->clip_to_view != !!clip_to_view)
+    {
+      priv->clip_to_view = clip_to_view;
+      clutter_actor_queue_redraw (CLUTTER_ACTOR (viewport));
+    }
+}
+
 static void
 st_viewport_get_property (GObject    *object,
                           guint       property_id,
                           GValue     *value,
                           GParamSpec *pspec)
 {
+  StViewportPrivate *priv =
+    st_viewport_get_instance_private (ST_VIEWPORT (object));
   StAdjustment *adjustment;
 
   switch (property_id)
@@ -183,6 +201,10 @@ st_viewport_get_property (GObject    *object,
       g_value_set_object (value, adjustment);
       break;
 
+    case PROP_CLIP_TO_VIEW:
+      g_value_set_boolean (value, priv->clip_to_view);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -212,6 +234,10 @@ st_viewport_set_property (GObject      *object,
                                   g_value_get_object (value));
       break;
 
+    case PROP_CLIP_TO_VIEW:
+      st_viewport_set_clip_to_view (viewport, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -405,7 +431,7 @@ st_viewport_paint (ClutterActor        *actor,
   /* The content area forms the viewport into the scrolled contents, while
    * the borders and background stay in place; after drawing the borders and
    * background, we clip to the content area */
-  if (priv->hadjustment || priv->vadjustment)
+  if (priv->clip_to_view && (priv->hadjustment || priv->vadjustment))
     {
       cogl_framebuffer_push_rectangle_clip (fb,
                                             (int)content_box.x1,
@@ -419,7 +445,7 @@ st_viewport_paint (ClutterActor        *actor,
        child = clutter_actor_get_next_sibling (child))
     clutter_actor_paint (child, paint_context);
 
-  if (priv->hadjustment || priv->vadjustment)
+  if (priv->clip_to_view && (priv->hadjustment || priv->vadjustment))
     cogl_framebuffer_pop_clip (fb);
 }
 
@@ -478,6 +504,9 @@ st_viewport_get_paint_volume (ClutterActor       *actor,
   if (!clutter_actor_has_allocation (actor))
     return FALSE;
 
+  if (!priv->clip_to_view)
+    return CLUTTER_ACTOR_CLASS (st_viewport_parent_class)->get_paint_volume (actor, volume);
+
   /* When have an adjustment we are clipped to the content box, so base
    * our paint volume on that. */
   if (priv->hadjustment || priv->vadjustment)
@@ -558,6 +587,14 @@ st_viewport_class_init (StViewportClass *klass)
   actor_class->get_paint_volume = st_viewport_get_paint_volume;
   actor_class->pick = st_viewport_pick;
 
+  g_object_class_install_property (object_class,
+                                   PROP_CLIP_TO_VIEW,
+                                   g_param_spec_boolean ("clip-to-view",
+                                                         "Clip to view",
+                                                         "Clip to view",
+                                                         TRUE,
+                                                         ST_PARAM_READWRITE));
+
   /* StScrollable properties */
   g_object_class_override_property (object_class,
                                     PROP_HADJUST,
@@ -566,10 +603,13 @@ st_viewport_class_init (StViewportClass *klass)
   g_object_class_override_property (object_class,
                                     PROP_VADJUST,
                                     "vadjustment");
-
 }
 
 static void
 st_viewport_init (StViewport *self)
 {
+  StViewportPrivate *priv =
+    st_viewport_get_instance_private (self);
+
+  priv->clip_to_view = TRUE;
 }


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