[gnome-chess/bridadan/gnome-chess-adaptive_width: 4/7] Switch between narrow and normal views.



commit 1323674a9bf9cef9d87218a3b12ff998dc1d26e2
Author: Brian Daniels <brianddaniels gmail com>
Date:   Sun Sep 8 12:27:59 2019 -0500

    Switch between narrow and normal views.
    
    At 700px window width, the bottom controlls will split into two rows.

 src/gnome-chess.vala | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 9d4095c..8429cf8 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -13,6 +13,12 @@
 
 public class ChessApplication : Gtk.Application
 {
+    private enum LayoutMode {
+        NORMAL,
+        NARROW
+    }
+    private LayoutMode layout_mode;
+
     private bool is_tiled;
     private bool is_maximized;
     private int window_width;
@@ -25,6 +31,7 @@ public class ChessApplication : Gtk.Application
     private ChessScene scene;
     private ChessView view;
     private Gtk.Button pause_resume_button;
+    private Gtk.Box navigation_box;
     private Gtk.Widget first_move_button;
     private Gtk.Widget prev_move_button;
     private Gtk.Widget next_move_button;
@@ -150,9 +157,11 @@ Copyright © 2015–2016 Sahil Sareen""";
             window.maximize ();
         window.size_allocate.connect (size_allocate_cb);
         window.window_state_event.connect (window_state_event_cb);
+        window.configure_event.connect (configure_event_cb);
 
         info_bar = (Gtk.InfoBar) builder.get_object ("info_bar");
         pause_resume_button = (Gtk.Button) builder.get_object ("pause_button");
+        navigation_box = (Gtk.Box) builder.get_object ("navigation_box");
         first_move_button = (Gtk.Widget) builder.get_object ("first_move_button");
         prev_move_button = (Gtk.Widget) builder.get_object ("prev_move_button");
         next_move_button = (Gtk.Widget) builder.get_object ("next_move_button");
@@ -256,6 +265,22 @@ Copyright © 2015–2016 Sahil Sareen""";
         settings.set_boolean ("maximized", is_maximized);
     }
 
+    private void set_layout_mode(LayoutMode new_layout_mode)
+    {
+        if (layout_mode == new_layout_mode)
+            return;
+        layout_mode = new_layout_mode;
+
+        Gtk.Orientation orientation;
+
+        if (layout_mode == LayoutMode.NORMAL)
+            orientation = Gtk.Orientation.HORIZONTAL;
+        else
+            orientation = Gtk.Orientation.VERTICAL;
+
+        navigation_box.set_orientation(orientation);
+    }
+
     private void size_allocate_cb (Gtk.Allocation allocation)
     {
         if (is_maximized || is_tiled)
@@ -273,6 +298,15 @@ Copyright © 2015–2016 Sahil Sareen""";
         return false;
     }
 
+    private bool configure_event_cb (Gdk.EventConfigure event)
+    {
+        if (event.width <= 700 && layout_mode == LayoutMode.NORMAL)
+            set_layout_mode(LayoutMode.NARROW);
+        else if (event.width > 700 && layout_mode == LayoutMode.NARROW)
+            set_layout_mode(LayoutMode.NORMAL);
+        return Gdk.EVENT_PROPAGATE;
+    }
+
     public PieceType? show_promotion_type_selector ()
     {
         Gtk.Builder promotion_type_selector_builder = new Gtk.Builder.from_resource 
("/org/gnome/Chess/ui/promotion-type-selector.ui");


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