[gnome-games/wip/exalm/display-bin] ui: Add DisplayBin



commit eb7f6ae82950435625eafb336908bb3954517a5e
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Aug 14 19:15:57 2019 +0500

    ui: Add DisplayBin
    
    This bin can offset child without changing its size. This will be used in
    the next commit to ensure game never changes height when the savestates
    sidebar slides out.

 src/meson.build         |  1 +
 src/ui/display-bin.vala | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 467fb9e4..358bc8e3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -138,6 +138,7 @@ vala_sources = [
   'ui/collection-icon-view.vala',
   'ui/collection-header-bar.vala',
   'ui/collection-view.vala',
+  'ui/display-bin.vala',
   'ui/display-box.vala',
   'ui/display-header-bar.vala',
   'ui/display-view.vala',
diff --git a/src/ui/display-bin.vala b/src/ui/display-bin.vala
new file mode 100644
index 00000000..a5480283
--- /dev/null
+++ b/src/ui/display-bin.vala
@@ -0,0 +1,40 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.DisplayBin : Gtk.Bin {
+       private int _horizontal_offset;
+       public int horizontal_offset {
+               get { return _horizontal_offset; }
+               set {
+                       _horizontal_offset = value;
+                       queue_allocate ();
+               }
+       }
+
+       private int _vertical_offset;
+       public int vertical_offset {
+               get { return _vertical_offset; }
+               set {
+                       _vertical_offset = value;
+                       queue_allocate ();
+               }
+       }
+
+       public override void size_allocate (Gtk.Allocation allocation) {
+               set_allocation (allocation);
+
+               var child = get_child ();
+               if (child != null && child.visible) {
+                       Gtk.Allocation child_allocation = {};
+
+                       if (get_direction () == Gtk.TextDirection.RTL)
+                               child_allocation.x = allocation.x - horizontal_offset;
+                       else
+                               child_allocation.x = allocation.x + horizontal_offset;
+                       child_allocation.y = allocation.y + vertical_offset;
+                       child_allocation.width = allocation.width;
+                       child_allocation.height = allocation.height;
+
+                       child.size_allocate (child_allocation);
+               }
+       }
+}


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