[gnome-sudoku] Responsive layout: start_box dynamic squeezing



commit b4e39ec9d23d3c856f31e8b5537cc99bd344a122
Author: lajonss <l3n1 dupaw eu>
Date:   Thu Nov 26 05:34:48 2020 +0100

    Responsive layout: start_box dynamic squeezing

 data/gnome-sudoku.ui  |  1 +
 src/gnome-sudoku.vala | 24 +++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 1f688a23..88b2fb9d 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -170,6 +170,7 @@
             <property name="margin">25</property>
             <property name="homogeneous">False</property>
             <property name="transition-type">crossfade</property>
+            <property name="interpolate-size">True</property>
             <child>
               <object class="GtkBox" id="start_box">
                 <property name="visible">True</property>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index e2c1b47c..1bad01c8 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -55,6 +55,7 @@ public class Sudoku : Gtk.Application
     private SudokuSaver saver;
 
     private AspectFrame previous_layout;
+    private Orientation main_squeezer_orientation;
 
     private SimpleAction undo_action;
     private SimpleAction redo_action;
@@ -254,9 +255,29 @@ public class Sudoku : Gtk.Application
 
     private void size_allocate_cb (Allocation allocation)
     {
+        int width, height;
+        window.get_size (out width, out height);
+        update_layout (width, height);
         if (window_is_maximized || window_is_fullscreen || window_is_tiled)
             return;
-        window.get_size (out window_width, out window_height);
+        window_width = width;
+        window_height = height;
+    }
+
+    private void update_layout (int width, int height)
+    {
+        main_squeezer_orientation = height > width ? Orientation.HORIZONTAL : Orientation.VERTICAL;
+        frame_h.ratio = height < 350 ? 1.9f : 1.4f;
+        apply_main_squeezer_orientation ();
+    }
+
+    private void apply_main_squeezer_orientation ()
+    {
+        var child = main_squeezer.visible_child;
+        if (child == start_box || child == start_box_s)
+            main_squeezer.orientation = main_squeezer_orientation;
+        else
+            main_squeezer.orientation = Orientation.HORIZONTAL;
     }
 
     private const Gdk.WindowState tiled_state = Gdk.WindowState.TILED
@@ -709,6 +730,7 @@ public class Sudoku : Gtk.Application
         start_box_s.visible = !value;
         frame_h.visible = value;
         frame_v.visible = value;
+        apply_main_squeezer_orientation ();
     }
 
     private bool is_board_visible ()


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