[gnome-games] display-bin: Use a slightly less hacky way to offset the game
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] display-bin: Use a slightly less hacky way to offset the game
- Date: Tue, 29 Dec 2020 14:31:21 +0000 (UTC)
commit 560a880d39b27148de07d1e8e1f14a88fb41eadd
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Dec 29 19:26:38 2020 +0500
display-bin: Use a slightly less hacky way to offset the game
src/ui/display-bin.vala | 43 ++++++++++++++++++++-----------------------
src/ui/display-view.ui | 26 +++++++++++++++-----------
src/ui/display-view.vala | 11 ++++++-----
3 files changed, 41 insertions(+), 39 deletions(-)
---
diff --git a/src/ui/display-bin.vala b/src/ui/display-bin.vala
index e43c1d26..373d0355 100644
--- a/src/ui/display-bin.vala
+++ b/src/ui/display-bin.vala
@@ -1,38 +1,35 @@
// 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; }
+public class Games.DisplayBin : Gtk.EventBox {
+ private int _child_width;
+ public int child_width {
+ get { return _child_width; }
set {
- if (horizontal_offset == value)
+ if (child_width == value)
return;
- _horizontal_offset = value;
- queue_draw ();
+ _child_width = value;
+ queue_allocate ();
}
}
- private int _vertical_offset;
- public int vertical_offset {
- get { return _vertical_offset; }
- set {
- if (vertical_offset == value)
- return;
+ public override void get_preferred_width (out int minimum, out int natural) {
+ var child = get_child ();
- _vertical_offset = value;
- queue_draw ();
- }
- }
+ minimum = 0;
- public override bool draw (Cairo.Context cr) {
- if (get_direction () == Gtk.TextDirection.RTL)
- cr.translate (-horizontal_offset, vertical_offset);
+ if (child != null)
+ child.get_preferred_width (null, out natural);
else
- cr.translate (horizontal_offset, vertical_offset);
+ natural = 0;
+ }
- base.draw (cr);
+ public override void size_allocate (Gtk.Allocation alloc) {
+ base.size_allocate (alloc);
- return true;
+ int delta = alloc.width - child_width;
+ var child = get_child ();
+ if (child != null)
+ child.size_allocate ({ delta / 2, 0, child_width, alloc.height });
}
}
diff --git a/src/ui/display-view.ui b/src/ui/display-view.ui
index 7d98f8a6..344d51c9 100644
--- a/src/ui/display-view.ui
+++ b/src/ui/display-view.ui
@@ -204,26 +204,30 @@
</object>
</child>
<child>
- <object class="GtkOverlay" id="display_overlay">
+ <object class="GtkBox" id="display_box">
<property name="visible">True</property>
<child>
- <object class="GamesDisplayBin" id="display_bin">
+ <object class="GtkOverlay">
<property name="visible">True</property>
- <property name="hexpand">True</property>
+ <child>
+ <object class="GamesDisplayBin" id="display_bin">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GamesFlashBox" id="flash_box"/>
+ <packing>
+ <property name="pass-through">True</property>
+ </packing>
+ </child>
</object>
</child>
- <child type="overlay">
- <object class="GamesFlashBox" id="flash_box"/>
- <packing>
- <property name="pass-through">True</property>
- </packing>
- </child>
- <child type="overlay">
+ <child>
<object class="GamesSnapshotsList" id="snapshots_list">
<property name="visible">True</property>
<property name="halign">end</property>
<property name="is-revealed" bind-source="GamesDisplayView"
bind-property="is-showing-snapshots" bind-flags="bidirectional"/>
- <signal name="size-allocate" handler="on_snapshots_list_size_allocate"/>
<signal name="hidden" handler="on_snapshots_hidden"/>
</object>
</child>
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index a2bc5049..571e90eb 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -29,7 +29,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
[GtkChild]
private Gtk.Button restart_btn;
[GtkChild]
- private Gtk.Overlay display_overlay;
+ private Gtk.Box display_box;
[GtkChild]
private DisplayBin display_bin;
[GtkChild]
@@ -82,7 +82,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
if (runner == null)
return;
- stack.visible_child = display_overlay;
+ stack.visible_child = display_box;
var display = runner.get_display ();
set_display (display);
@@ -746,9 +746,10 @@ private class Games.DisplayView : Gtk.Box, UiView {
display_bin.remove (child);
}
- [GtkCallback]
- private void on_snapshots_list_size_allocate (Gtk.Allocation allocation) {
- display_bin.horizontal_offset = -allocation.width / 2;
+ protected override void size_allocate (Gtk.Allocation allocation) {
+ display_bin.child_width = allocation.width;
+
+ base.size_allocate (allocation);
}
[GtkCallback]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]