[gtkmm] Box::pack_start/pack_end(options): Avoid setting child properties when possible.



commit 89dd1196ac8f740437e621274e3ae1f4429f54ad
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Apr 28 14:15:25 2017 +0200

    Box::pack_start/pack_end(options): Avoid setting child properties when possible.
    
    PackOptions::SHRINK seems to correspond with the default behaviour of
    the new gtk_box_pack_start()/pack_end(), so in this case it seems wise
    to avoid the complication of setting the child properties unnecessarily.

 gtk/src/box.ccg |   10 ++++++++++
 gtk/src/box.hg  |    4 ++++
 2 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/gtk/src/box.ccg b/gtk/src/box.ccg
index 218ca43..5226e90 100644
--- a/gtk/src/box.ccg
+++ b/gtk/src/box.ccg
@@ -25,6 +25,11 @@ namespace Gtk
 
 void Box::pack_start(Widget& child, PackOptions options)
 {
+  // Avoid using our custom code in this case:
+  if (options == PackOptions::SHRINK) {
+    return pack_start(child);
+  }
+
   const bool expand = (options == PackOptions::EXPAND_PADDING) || (options == PackOptions::EXPAND_WIDGET);
   const bool fill = (options == PackOptions::EXPAND_WIDGET);
 
@@ -38,6 +43,11 @@ void Box::pack_start(Widget& child, PackOptions options)
 
 void Box::pack_end(Widget& child, PackOptions options)
 {
+  // Avoid using our custom code in this case:
+  if (options == PackOptions::SHRINK) {
+    return pack_start(child);
+  }
+
   const bool expand = (options == PackOptions::EXPAND_PADDING) || (options == PackOptions::EXPAND_WIDGET);
   const bool fill = (options == PackOptions::EXPAND_WIDGET);
 
diff --git a/gtk/src/box.hg b/gtk/src/box.hg
index 9fc1f32..7d6373e 100644
--- a/gtk/src/box.hg
+++ b/gtk/src/box.hg
@@ -93,6 +93,8 @@ public:
   // Note: GtkWidget's halign default is GTK_ALIGN_FILL, and its hexpand default is false
   _WRAP_METHOD(void pack_start(Widget& child), gtk_box_pack_start)
 
+  // TODO: Remove this. Its current implementation is not a complete replacement for the behavior in gtkmm 3.
+  // It would be best for application code to port completely to use hexpand/vexpand/halign/valign.
   /** Left side insert a widget to a box.
    * @param child A Widget to be added to box.
    * @param options Controls how the widget expands to fill space, and how the space around them is used.
@@ -102,6 +104,8 @@ public:
   // Note: GtkWidget's halign default is GTK_ALIGN_FILL, and its hexpand default is false
   _WRAP_METHOD(void pack_end(Widget& child), gtk_box_pack_end)
 
+  // TODO: Remove this. Its current implementation is not a complete replacement for the behavior in gtkmm 3.
+  // It would be best for application code to port completely to use hexpand/vexpand/halign/valign.
   /** Right side insert a widget to a box.
    * @param child A Widget to be added to box.
    * @param options Controls how the widget expands to fill space, and how the space around them is used.


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