[libhandy] clamp: Rename linear-growth-width into tightening-threshold



commit bc72a5b86ba8dc11d7f5292214967d582a7b739b
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Jun 9 13:09:01 2020 +0200

    clamp: Rename linear-growth-width into tightening-threshold
    
    This better reprensents the goal of the property and makes it work with
    any orientation.
    
    Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/96

 debian/libhandy-1-0.symbols   |  4 +--
 examples/hdy-demo-window.ui   | 24 +++++++-------
 glade/libhandy.xml            |  2 +-
 src/hdy-clamp.c               | 73 ++++++++++++++++++++++++-------------------
 src/hdy-clamp.h               |  6 ++--
 src/hdy-preferences-page.ui   |  2 +-
 src/hdy-preferences-window.ui |  4 +--
 7 files changed, 62 insertions(+), 53 deletions(-)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 92e50b14..a714af82 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -74,12 +74,12 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
  hdy_carousel_set_reveal_duration@LIBHANDY_1_0 0.81.0
  hdy_carousel_set_spacing@LIBHANDY_1_0 0.80.0
  hdy_centering_policy_get_type@LIBHANDY_1_0 0.0.10
- hdy_clamp_get_linear_growth_width@LIBHANDY_1_0 0.82.0
  hdy_clamp_get_maximum_size@LIBHANDY_1_0 0.82.0
+ hdy_clamp_get_tightening_threshold@LIBHANDY_1_0 0.82.0
  hdy_clamp_get_type@LIBHANDY_1_0 0.82.0
  hdy_clamp_new@LIBHANDY_1_0 0.82.0
- hdy_clamp_set_linear_growth_width@LIBHANDY_1_0 0.82.0
  hdy_clamp_set_maximum_size@LIBHANDY_1_0 0.82.0
+ hdy_clamp_set_tightening_threshold@LIBHANDY_1_0 0.82.0
  hdy_combo_row_bind_model@LIBHANDY_1_0 0.0.6
  hdy_combo_row_bind_name_model@LIBHANDY_1_0 0.0.6
  hdy_combo_row_get_model@LIBHANDY_1_0 0.0.6
diff --git a/examples/hdy-demo-window.ui b/examples/hdy-demo-window.ui
index d9bccdcf..20989fd5 100644
--- a/examples/hdy-demo-window.ui
+++ b/examples/hdy-demo-window.ui
@@ -458,7 +458,7 @@
                         <property name="margin-top">32</property>
                         <property name="expand">True</property>
                         <property name="maximum-size">400</property>
-                        <property name="linear-growth-width">300</property>
+                        <property name="tightening-threshold">300</property>
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -600,7 +600,7 @@
                             <property name="margin-top">32</property>
                             <property name="expand">True</property>
                             <property name="maximum-size">400</property>
-                            <property name="linear-growth-width">300</property>
+                            <property name="tightening-threshold">300</property>
                             <child>
                               <object class="GtkBox">
                                 <property name="visible">True</property>
@@ -798,7 +798,7 @@
                         <property name="margin-top">32</property>
                         <property name="expand">True</property>
                         <property name="maximum-size">400</property>
-                        <property name="linear-growth-width">300</property>
+                        <property name="tightening-threshold">300</property>
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -884,7 +884,7 @@
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <property name="maximum-size">300</property>
-                                <property name="linear-growth-width">300</property>
+                                <property name="tightening-threshold">300</property>
                                 <child>
                                   <object class="GtkBox" id="box_keypad">
                                     <property name="visible">True</property>
@@ -984,7 +984,7 @@
                         <property name="margin-top">32</property>
                         <property name="expand">True</property>
                         <property name="maximum-size" bind-source="clamp_maximum_size_adjustment" 
bind-property="value" bind-flags="sync-create"/>
-                        <property name="linear-growth-width" bind-source="clamp_linear_width_adjustment" 
bind-property="value" bind-flags="sync-create"/>
+                        <property name="tightening-threshold" 
bind-source="clamp_tightening_threshold_adjustment" bind-property="value" bind-flags="sync-create"/>
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -1105,11 +1105,11 @@
                                 <child>
                                   <object class="HdyActionRow">
                                     <property name="can_focus">False</property>
-                                    <property name="title" translatable="yes">Linear growth width</property>
+                                    <property name="title" translatable="yes">Tightening threshold</property>
                                     <property name="visible">True</property>
                                     <child>
                                       <object class="GtkSpinButton">
-                                        <property name="adjustment">clamp_linear_width_adjustment</property>
+                                        <property 
name="adjustment">clamp_tightening_threshold_adjustment</property>
                                         <property name="valign">center</property>
                                         <property name="visible">True</property>
                                       </object>
@@ -1138,7 +1138,7 @@
                         <property name="margin-top">32</property>
                         <property name="expand">True</property>
                         <property name="maximum-size">400</property>
-                        <property name="linear-growth-width">300</property>
+                        <property name="tightening-threshold">300</property>
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -1737,7 +1737,7 @@
                             <property name="margin-end">12</property>
                             <property name="expand">True</property>
                             <property name="maximum-size">400</property>
-                            <property name="linear-growth-width">300</property>
+                            <property name="tightening-threshold">300</property>
                             <child>
                               <object class="GtkListBox" id="carousel_listbox">
                                 <property name="visible">True</property>
@@ -1894,7 +1894,7 @@
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="maximum-size">400</property>
-                            <property name="linear-growth-width">300</property>
+                            <property name="tightening-threshold">300</property>
                             <child>
                               <object class="GtkBox">
                                 <property name="visible">True</property>
@@ -2016,7 +2016,7 @@
                         <property name="margin-top">32</property>
                         <property name="expand">True</property>
                         <property name="maximum-size">400</property>
-                        <property name="linear-growth-width">300</property>
+                        <property name="tightening-threshold">300</property>
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -2229,7 +2229,7 @@
     <property name="page-increment">100</property>
     <property name="step-increment">10</property>
   </object>
-  <object class="GtkAdjustment" id="clamp_linear_width_adjustment">
+  <object class="GtkAdjustment" id="clamp_tightening_threshold_adjustment">
     <property name="lower">0</property>
     <property name="upper">10000</property>
     <property name="value">500</property>
diff --git a/glade/libhandy.xml b/glade/libhandy.xml
index 8ec53530..73f50a47 100644
--- a/glade/libhandy.xml
+++ b/glade/libhandy.xml
@@ -78,7 +78,7 @@
     <glade-widget-class name="HdyClamp" generic-name="clamp" title="Clamp" since="1.0">
       <properties>
         <property id="maximum-size" default="650"/>
-        <property id="linear-growth-width" default="400"/>
+        <property id="tightening-threshold" default="400"/>
       </properties>
     </glade-widget-class>
     <glade-widget-class name="HdyComboRow" generic-name="comborow" title="Combo Row" since="0.0.6"/>
diff --git a/src/hdy-clamp.c b/src/hdy-clamp.c
index 64ba2926..24f0a8b6 100644
--- a/src/hdy-clamp.c
+++ b/src/hdy-clamp.c
@@ -40,12 +40,12 @@
 enum {
   PROP_0,
   PROP_MAXIMUM_SIZE,
-  PROP_LINEAR_GROWTH_WIDTH,
+  PROP_TIGHTENING_THRESHOLD,
 
   /* Overridden properties */
   PROP_ORIENTATION,
 
-  LAST_PROP = PROP_LINEAR_GROWTH_WIDTH + 1,
+  LAST_PROP = PROP_TIGHTENING_THRESHOLD + 1,
 };
 
 struct _HdyClamp
@@ -53,7 +53,7 @@ struct _HdyClamp
   GtkBin parent_instance;
 
   gint maximum_size;
-  gint linear_growth_width;
+  gint tightening_threshold;
 
   GtkOrientation orientation;
 };
@@ -87,8 +87,8 @@ hdy_clamp_get_property (GObject    *object,
   case PROP_MAXIMUM_SIZE:
     g_value_set_int (value, hdy_clamp_get_maximum_size (self));
     break;
-  case PROP_LINEAR_GROWTH_WIDTH:
-    g_value_set_int (value, hdy_clamp_get_linear_growth_width (self));
+  case PROP_TIGHTENING_THRESHOLD:
+    g_value_set_int (value, hdy_clamp_get_tightening_threshold (self));
     break;
   case PROP_ORIENTATION:
     g_value_set_enum (value, self->orientation);
@@ -110,8 +110,8 @@ hdy_clamp_set_property (GObject      *object,
   case PROP_MAXIMUM_SIZE:
     hdy_clamp_set_maximum_size (self, g_value_get_int (value));
     break;
-  case PROP_LINEAR_GROWTH_WIDTH:
-    hdy_clamp_set_linear_growth_width (self, g_value_get_int (value));
+  case PROP_TIGHTENING_THRESHOLD:
+    hdy_clamp_set_tightening_threshold (self, g_value_get_int (value));
     break;
   case PROP_ORIENTATION:
     set_orientation (self, g_value_get_enum (value));
@@ -160,7 +160,7 @@ get_child_size (HdyClamp *self,
       gtk_widget_get_preferred_height (child, &min, NULL);
   }
 
-  lower = MAX (MIN (self->linear_growth_width, self->maximum_size), min);
+  lower = MAX (MIN (self->tightening_threshold, self->maximum_size), min);
   max = MAX (lower, self->maximum_size);
   amplitude = max - lower;
   upper = HDY_EASE_OUT_TAN_CUBIC * amplitude + lower;
@@ -420,16 +420,27 @@ hdy_clamp_class_init (HdyClampClass *klass)
                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
-   * HdyClamp:linear_growth_width:
+   * HdyClamp:tightening-threshold:
    *
-   * The width up to which the child will be allocated all the width.
+   * The size starting from which the clamp will tighten its grip on the child,
+   * slowly allocating less and less of the available size up to the maximum
+   * allocated size. Below that threshold and below the maximum width, the child
+   * will be allocated all the available size.
+   *
+   * If the threshold is greater than the maximum size to allocate to the child,
+   * the child will be allocated all the width up to the maximum.
+   * If the threshold is lower than the minimum size to allocate to the child,
+   * that size will be used as the tightening threshold.
+   *
+   * Effectively, tightening the grip on the child before it reaches its maximum
+   * size makes transitions to and from the maximum size smoother when resizing.
    *
    * Since: 1.0
    */
-  props[PROP_LINEAR_GROWTH_WIDTH] =
-      g_param_spec_int ("linear-growth-width",
-                        _("Linear growth width"),
-                        _("The width up to which the child will be allocated all the width"),
+  props[PROP_TIGHTENING_THRESHOLD] =
+      g_param_spec_int ("tightening-threshold",
+                        _("Tightening threshold"),
+                        _("The size from which the clamp will tighten its grip on the child"),
                         0, G_MAXINT, 0,
                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
@@ -504,49 +515,47 @@ hdy_clamp_set_maximum_size (HdyClamp *self,
 }
 
 /**
- * hdy_clamp_get_linear_growth_width:
+ * hdy_clamp_get_tightening_threshold:
  * @self: a #HdyClamp
  *
- * Gets the width up to which the child will be allocated all the available
- * width and starting from which it will be allocated a portion of the available
- * width. In bith cases the allocated width won't exceed the declared maximum.
+ * Gets the size starting from which the clamp will tighten its grip on the
+ * child.
  *
- * Returns: the width up to which the child will be allocated all the available
- * width.
+ * Returns: the size starting from which the clamp will tighten its grip on the
+ * child.
  *
  * Since: 1.0
  */
 gint
-hdy_clamp_get_linear_growth_width (HdyClamp *self)
+hdy_clamp_get_tightening_threshold (HdyClamp *self)
 {
   g_return_val_if_fail (HDY_IS_CLAMP (self), 0);
 
-  return self->linear_growth_width;
+  return self->tightening_threshold;
 }
 
 /**
- * hdy_clamp_set_linear_growth_width:
+ * hdy_clamp_set_tightening_threshold:
  * @self: a #HdyClamp
- * @linear_growth_width: the linear growth width
+ * @tightening_threshold: the tightening threshold
  *
- * Sets the width up to which the child will be allocated all the available
- * width and starting from which it will be allocated a portion of the available
- * width. In bith cases the allocated width won't exceed the declared maximum.
+ * Sets the size starting from which the clamp will tighten its grip on the
+ * child.
  *
  * Since: 1.0
  */
 void
-hdy_clamp_set_linear_growth_width (HdyClamp *self,
-                                   gint      linear_growth_width)
+hdy_clamp_set_tightening_threshold (HdyClamp *self,
+                                    gint      tightening_threshold)
 {
   g_return_if_fail (HDY_IS_CLAMP (self));
 
-  if (self->linear_growth_width == linear_growth_width)
+  if (self->tightening_threshold == tightening_threshold)
     return;
 
-  self->linear_growth_width = linear_growth_width;
+  self->tightening_threshold = tightening_threshold;
 
   gtk_widget_queue_resize (GTK_WIDGET (self));
 
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_LINEAR_GROWTH_WIDTH]);
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TIGHTENING_THRESHOLD]);
 }
diff --git a/src/hdy-clamp.h b/src/hdy-clamp.h
index f9a30a0c..bb317769 100644
--- a/src/hdy-clamp.h
+++ b/src/hdy-clamp.h
@@ -22,8 +22,8 @@ GtkWidget *hdy_clamp_new (void);
 gint hdy_clamp_get_maximum_size (HdyClamp *self);
 void hdy_clamp_set_maximum_size (HdyClamp *self,
                                  gint      maximum_size);
-gint hdy_clamp_get_linear_growth_width (HdyClamp *self);
-void hdy_clamp_set_linear_growth_width (HdyClamp *self,
-                                        gint      linear_growth_width);
+gint hdy_clamp_get_tightening_threshold (HdyClamp *self);
+void hdy_clamp_set_tightening_threshold (HdyClamp *self,
+                                         gint      tightening_threshold);
 
 G_END_DECLS
diff --git a/src/hdy-preferences-page.ui b/src/hdy-preferences-page.ui
index d18ac061..7e5a3dfe 100644
--- a/src/hdy-preferences-page.ui
+++ b/src/hdy-preferences-page.ui
@@ -12,7 +12,7 @@
             <property name="visible">True</property>
             <child>
               <object class="HdyClamp">
-                <property name="linear-growth-width">400</property>
+                <property name="tightening-threshold">400</property>
                 <property name="margin-bottom">18</property>
                 <property name="margin-end">12</property>
                 <property name="margin-start">12</property>
diff --git a/src/hdy-preferences-window.ui b/src/hdy-preferences-window.ui
index 911b1e16..02014b3f 100644
--- a/src/hdy-preferences-window.ui
+++ b/src/hdy-preferences-window.ui
@@ -39,7 +39,7 @@
                 </child>
                 <child>
                   <object class="HdyClamp">
-                    <property name="linear-growth-width">300</property>
+                    <property name="tightening-threshold">300</property>
                     <property name="maximum-size">400</property>
                     <property name="visible">True</property>
                     <child>
@@ -129,7 +129,7 @@
                     <property name="visible">True</property>
                     <child>
                       <object class="HdyClamp">
-                        <property name="linear_growth_width">400</property>
+                        <property name="tightening_threshold">400</property>
                         <property name="margin_bottom">18</property>
                         <property name="margin_end">12</property>
                         <property name="margin_start">12</property>


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