[gnome-sudoku] Use GtkStack to switch between board and new game screen.



commit 334bd006ce9dc9a31253590e77aadb3032b78246
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Jul 20 17:18:56 2014 +0200

    Use GtkStack to switch between board and new game screen.
    
    Also, make sure the board expands to fill the window when the window is large.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733435

 data/gnome-sudoku.ui  |   16 ++++++++++++----
 src/gnome-sudoku.vala |   18 +++++++-----------
 2 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index fb37d81..7529554 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -84,17 +84,18 @@
             </object>
         </child>
         <child>
-            <object class="GtkBox" id="main_box">
+            <object class="GtkStack" id="main_stack">
                 <property name="visible">True</property>
-                <property name="halign">center</property>
                 <child>
                     <object class="GtkBox" id="start_box">
                         <property name="orientation">vertical</property>
-                        <property name="visible">False</property>
+                        <property name="visible">True</property>
                         <property name="halign">center</property>
+                        <property name="valign">center</property>
                         <property name="homogeneous">True</property>
                         <property name="margin">80</property>
                         <property name="width-request">350</property>
+                        <property name="height-request">350</property>
                         <child>
                             <object class="GtkButton" id="easy_button">
                                 <property name="visible">True</property>
@@ -151,11 +152,15 @@
                                 <property name="position">3</property>
                             </packing>
                         </child>
-                    </object> <!-- End of new_start_box -->
+                    </object> <!-- End of start_box -->
+                    <packing>
+                        <property name="name">start_box</property>
+                    </packing>
                 </child>
                 <child>
                     <object class="GtkBox" id="game_box">
                         <property name="visible">True</property>
+                        <property name="halign">fill</property>
                         <property name="spacing">20</property>
                         <property name="margin">20</property>
                         <child>
@@ -184,6 +189,9 @@
                             </packing>
                         </child>
                     </object> <!-- End of game_box -->
+                    <packing>
+                        <property name="name">game_box</property>
+                    </packing>
                 </child>
             </object>
         </child>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 8a69b41..e346b73 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -17,10 +17,9 @@ public class Sudoku : Gtk.Application
     private SudokuView view;
 
     private HeaderBar header_bar;
-    private Box game_box; // Holds the grid and controls boxes
+    private Stack main_stack;
     private Box grid_box; // Holds the view
     private Box controls_box; // Holds the controls
-    private Box start_box; // Holds the new game screen
 
     private Box undo_redo_box;
     private Button back_button;
@@ -131,10 +130,9 @@ public class Sudoku : Gtk.Application
         set_app_menu (builder.get_object ("sudoku-menu") as MenuModel);
 
         header_bar = (HeaderBar) builder.get_object ("headerbar");
-        game_box = (Box) builder.get_object ("game_box");
+        main_stack = (Stack) builder.get_object ("main_stack");
         grid_box = (Box) builder.get_object ("grid_box");
         controls_box = (Box) builder.get_object ("controls_box");
-        start_box = (Box) builder.get_object ("start_box");
         undo_redo_box = (Box) builder.get_object ("undo_redo_box");
 
         back_button = (Button) builder.get_object ("back_button");
@@ -270,9 +268,8 @@ public class Sudoku : Gtk.Application
 
     private void new_game_cb ()
     {
-        start_box.visible = true;
+        main_stack.set_visible_child_name ("start_box");
         back_button.visible = true;
-        game_box.visible = false;
         undo_redo_box.visible = false;
         header_bar_subtitle = header_bar.get_subtitle ();
         header_bar.set_subtitle (null);
@@ -308,9 +305,8 @@ public class Sudoku : Gtk.Application
 
     private void back_cb ()
     {
-        start_box.visible = false;
+        main_stack.set_visible_child_name ("game_box");
         back_button.visible = false;
-        game_box.visible = true;
         undo_redo_box.visible = true;
         header_bar.set_subtitle (header_bar_subtitle);
         print_action.set_enabled (true);
@@ -318,7 +314,7 @@ public class Sudoku : Gtk.Application
 
     private void undo_cb ()
     {
-        if (!game_box.visible)
+        if (main_stack.get_visible_child_name () != "game_box")
             return;
         game.undo ();
         undo_action.set_enabled (!game.is_undostack_null ());
@@ -327,7 +323,7 @@ public class Sudoku : Gtk.Application
 
     private void redo_cb ()
     {
-        if (!game_box.visible)
+        if (main_stack.get_visible_child_name () != "game_box")
             return;
         game.redo ();
         redo_action.set_enabled (!game.is_redostack_null ());
@@ -336,7 +332,7 @@ public class Sudoku : Gtk.Application
 
     private void print_cb ()
     {
-        if (!game_box.visible)
+        if (main_stack.get_visible_child_name () != "game_box")
             return;
         var printer = new SudokuPrinter ({game.board.clone ()}, ref window);
         printer.print_sudoku ();


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