[gnome-sudoku] Responsive aspect ratio
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Responsive aspect ratio
- Date: Thu, 26 Nov 2020 18:22:49 +0000 (UTC)
commit 7788aa1641687429b00e6feeaced8fa785e669af
Author: lajonss <l3n1 dupaw eu>
Date: Fri Nov 13 04:56:19 2020 +0100
Responsive aspect ratio
data/gnome-sudoku.ui | 4 ++--
src/gnome-sudoku.vala | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 0fe02e9f..f42dd387 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -235,7 +235,7 @@
</packing>
</child>
<child>
- <object class="GtkAspectFrame"> <!-- frame -->
+ <object class="GtkAspectFrame" id="frame">
<property name="visible">True</property>
<property name="shadow-type">GTK_SHADOW_NONE</property>
<property name="obey-child">False</property>
@@ -245,7 +245,7 @@
<property name="visible">True</property>
<property name="spacing">25</property>
<child>
- <object class="GtkButtonBox"> <!-- controls_box -->
+ <object class="GtkButtonBox" id="controls_box">
<property name="visible">True</property>
<property name="halign">end</property>
<property name="valign">end</property>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 1d2538b0..08e0c9d3 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -43,6 +43,8 @@ public class Sudoku : Gtk.Application
private HeaderBar headerbar;
private Stack main_stack;
private Box game_box; // Holds the view
+ private AspectFrame frame;
+ private ButtonBox controls_box;
private Box undo_redo_box;
private Button back_button;
@@ -58,6 +60,8 @@ public class Sudoku : Gtk.Application
private SimpleAction play_custom_game_action;
private SimpleAction new_game_action;
+ private Orientation current_layout;
+
private bool show_possibilities = false;
private GameMode current_game_mode = GameMode.PLAY;
@@ -158,6 +162,7 @@ public class Sudoku : Gtk.Application
window.size_allocate.connect (size_allocate_cb);
window.window_state_event.connect (window_state_event_cb);
window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
+ window.configure_event.connect (configure_event_cb);
if (settings.get_boolean ("window-is-maximized"))
window.maximize ();
@@ -166,6 +171,9 @@ public class Sudoku : Gtk.Application
headerbar = (HeaderBar) builder.get_object ("headerbar");
main_stack = (Stack) builder.get_object ("main_stack");
game_box = (Box) builder.get_object ("game_box");
+ frame = (AspectFrame) builder.get_object ("frame");
+ controls_box = (ButtonBox) builder.get_object ("controls_box");
+
undo_redo_box = (Box) builder.get_object ("undo_redo_box");
back_button = (Button) builder.get_object ("back_button");
clock_label = (Label) builder.get_object ("clock_label");
@@ -361,6 +369,7 @@ public class Sudoku : Gtk.Application
if (view != null)
game_box.remove (view);
+ check_initial_layout_ratio ();
show_game_view ();
game = new SudokuGame (board);
game.mode = current_game_mode;
@@ -633,6 +642,43 @@ public class Sudoku : Gtk.Application
);
}
+ private void check_initial_layout_ratio ()
+ {
+ apply_layout_ratio (get_window_orientation ());
+ }
+
+ private bool configure_event_cb ()
+ {
+ var layout = get_window_orientation ();
+ if (layout == current_layout)
+ return false;
+
+ apply_layout_ratio (layout);
+ return false;
+ }
+
+ private Orientation get_window_orientation ()
+ {
+ int width, height;
+ window.get_size(out width, out height);
+ return width > height ? Orientation.HORIZONTAL : Orientation.VERTICAL;
+ }
+
+ private void apply_layout_ratio (Orientation layout)
+ {
+ if(layout == Orientation.HORIZONTAL) {
+ frame.ratio = 1.4f;
+ controls_box.halign = Align.END;
+ controls_box.orientation = Orientation.VERTICAL;
+ } else {
+ frame.ratio = 0.8f;
+ controls_box.halign = Align.CENTER;
+ controls_box.orientation = Orientation.HORIZONTAL;
+ }
+ game_box.orientation = layout;
+ current_layout = layout;
+ }
+
public static int main (string[] args)
{
return new Sudoku ().run (args);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]