[gtkmm] Box: pack_start/pack_end(): Adapt to new GTK+ API.



commit b07a05bba3a2e1df8778683a47e50d8c8f3fb26b
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Apr 27 10:51:00 2017 +0200

    Box: pack_start/pack_end(): Adapt to new GTK+ API.
    
    pack_start(Widget& child, bool expand, bool fill) and
    pack_end(Widget& child, bool expand, bool fill):
    Remove the expand and fill parameters, as in the C API:
    https://git.gnome.org/browse/gtk+/commit/?id=5729ea7744c2a41ae8fb833db6690a6aa5ad7a84
    https://git.gnome.org/browse/gtk+/commit/?id=c92b7d4224b9cef1d08373fcc28f7fbd96c64e6d
    (They want us to use the GtkWidget halign and hexpand properties
    instead.)
    
    pack_start(Gtk::Widget& child, Gtk::PackOptions options) and
    pack_start(Gtk::Widget& child, Gtk::PackOptions options):
    Reimplement these using the GtkWidget halign and hexpand properties.
    These still seem useful, because it still doesn't seem useful to fill
    while not expanding, so having a 3-value enum seems to make it clearer.
    It also still seems useful to specify this in one method call when
    adding the widget, instead of having separate code to set the widget
    properties. Hopefully this works.
    
    However, we now need to remove the default options value, to avoid
    ambiguity with the standard pack_start()/pack_end(). And unfortunately,
    the default GtkWidget halign and hexpand property values do not
    correspond to our previous options value (PACK_EXPAND_WIDGET), which
    fills and expands the widget. So some application code will now change
    its behaviour without any warning from the compiler.
    
    It might be better to just remove these pack_start()/pack_end()
    overrides, as they don't quite correspond to the new halign/hexpand
    system anyway.

 gtk/src/box.ccg |   14 ++++++++++----
 gtk/src/box.hg  |   12 ++++++------
 2 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/gtk/src/box.ccg b/gtk/src/box.ccg
index 5d6824e..c2902fa 100644
--- a/gtk/src/box.ccg
+++ b/gtk/src/box.ccg
@@ -25,10 +25,13 @@ namespace Gtk
 
 void Box::pack_start(Widget& child, PackOptions options)
 {
-  bool expand = (options == PACK_EXPAND_PADDING) || (options == PACK_EXPAND_WIDGET);
-  bool fill = (options == PACK_EXPAND_WIDGET);
+  const bool expand = (options == PACK_EXPAND_PADDING) || (options == PACK_EXPAND_WIDGET);
+  const bool fill = (options == PACK_EXPAND_WIDGET);
 
-  gtk_box_pack_start(gobj(), child.gobj(), (gboolean)expand, (gboolean)fill);
+  child.property_hexpand() = expand;
+  child.property_halign() = fill ? Gtk::Align::FILL : Gtk::Align::START;
+
+  gtk_box_pack_start(gobj(), child.gobj());
 }
 
 void Box::pack_end(Widget& child, PackOptions options)
@@ -36,7 +39,10 @@ void Box::pack_end(Widget& child, PackOptions options)
   bool expand = (options == PACK_EXPAND_PADDING) || (options == PACK_EXPAND_WIDGET);
   bool fill = (options == PACK_EXPAND_WIDGET);
 
-  gtk_box_pack_end(gobj(), child.gobj(), (gboolean)expand, (gboolean)fill);
+  child.property_hexpand() = expand;
+  child.property_halign() = fill ? Gtk::Align::FILL : Gtk::Align::END;
+
+  gtk_box_pack_end(gobj(), child.gobj());
 }
 
 } //namespace Gtk
diff --git a/gtk/src/box.hg b/gtk/src/box.hg
index d83eb1c..4efcfc9 100644
--- a/gtk/src/box.hg
+++ b/gtk/src/box.hg
@@ -90,21 +90,23 @@ public:
    */
   _WRAP_CTOR(Box(Orientation orientation = Orientation::HORIZONTAL, int spacing = 0), gtk_box_new)
 
-  _WRAP_METHOD(void pack_start(Widget& child, bool expand, bool fill), gtk_box_pack_start)
+  // 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)
 
   /** 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.
    */
-  void pack_start(Widget& child, PackOptions options = PACK_EXPAND_WIDGET);
+  void pack_start(Widget& child, PackOptions options);
 
-  _WRAP_METHOD(void pack_end(Widget& child, bool expand, bool fill), gtk_box_pack_end)
+  // 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)
 
   /** 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.
    */
-  void pack_end(Widget& child, PackOptions options = PACK_EXPAND_WIDGET);
+  void pack_end(Widget& child, PackOptions options);
 
   _WRAP_METHOD(void set_homogeneous(bool homogeneous = true), gtk_box_set_homogeneous)
   _WRAP_METHOD(bool get_homogeneous() const, gtk_box_get_homogeneous)
@@ -121,8 +123,6 @@ public:
   _WRAP_PROPERTY("homogeneous", bool)
   _WRAP_PROPERTY("baseline-position", BaselinePosition)
 
-  _WRAP_CHILD_PROPERTY("expand", bool)
-  _WRAP_CHILD_PROPERTY("fill", bool)
   _WRAP_CHILD_PROPERTY("pack-type", PackType)
   _WRAP_CHILD_PROPERTY("position", int)
 };


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