[gnome-sudoku] Use an AspectFrame to ensure all looks good



commit 72266fedb5e06a381597cb06d087ec12565d8b00
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Aug 12 00:17:07 2014 +0200

    Use an AspectFrame to ensure all looks good
    
    size request increased from 350 to 480 by Parin
    https://bugzilla.gnome.org/show_bug.cgi?id=733520

 data/gnome-sudoku.ui  |  121 +++++++++++++++++++++++++------------------------
 src/gnome-sudoku.vala |   32 ++++++++++---
 2 files changed, 85 insertions(+), 68 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 9db7468..d85f406 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -3,6 +3,7 @@
     <!-- interface-requires gtk+ 3.10 -->
     <object class="GtkApplicationWindow" id="sudoku_app">
         <property name="title" translatable="yes">Sudoku</property>
+        <property name="border-width">25</property>
         <child type="titlebar">
             <object class="GtkHeaderBar" id="headerbar">
                 <property name="visible">True</property>
@@ -86,6 +87,7 @@
         <child>
             <object class="GtkStack" id="main_stack">
                 <property name="visible">True</property>
+                <property name="homogeneous">True</property>
                 <child>
                     <object class="GtkBox" id="start_box">
                         <property name="orientation">vertical</property>
@@ -93,7 +95,7 @@
                         <property name="halign">center</property>
                         <property name="valign">center</property>
                         <property name="homogeneous">True</property>
-                        <property name="margin">80</property>
+                        <property name="margin">0</property>
                         <property name="width-request">350</property>
                         <property name="height-request">350</property>
                         <child>
@@ -158,78 +160,77 @@
                     </packing>
                 </child>
                 <child>
-                    <object class="GtkBox" id="game_box">
+                    <object class="GtkAspectFrame" id="frame">
                         <property name="visible">True</property>
-                        <property name="halign">fill</property>
-                        <property name="spacing">20</property>
-                        <property name="margin">20</property>
+                        <property name="shadow-type">GTK_SHADOW_NONE</property>
+                        <property name="obey-child">false</property>
+                        <property name="ratio">1.4</property>
+                        <property name="xalign">0.5</property>
+                        <property name="yalign">0.5</property>
                         <child>
-                            <object class="GtkButtonBox" id="controls_box">
+                            <object class="GtkBox" id="game_box">
                                 <property name="visible">True</property>
-                                <property name="valign">end</property>
-                                <property name="can_focus">False</property>
-                                <property name="orientation">vertical</property>
-                                <property name="spacing">10</property>
+                                <property name="spacing">25</property>
                                 <child>
-                                    <object class="GtkButton" id="clear_button">
-                                        <property name="visible">True</property>
-                                        <property name="use_underline">True</property>
-                                        <property name="label" translatable="yes">_Clear Board</property>
-                                        <property name="halign">center</property>
-                                        <property name="valign">center</property>
-                                        <property name="action-name">app.reset</property>
-                                        <property name="tooltip-text" translatable="yes">Reset the board to 
its original state</property>
-                                        <property name="width-request">120</property>
-                                        <property name="height-request">60</property>
-                                    </object>
-                                    <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">0</property>
-                                    </packing>
+                                    <placeholder/>
                                 </child>
                                 <child>
-                                    <object class="GtkButton" id="new_button">
+                                    <object class="GtkButtonBox" id="controls_box">
                                         <property name="visible">True</property>
-                                        <property name="use_underline">True</property>
-                                        <property name="label" translatable="yes">_New Puzzle</property>
-                                        <property name="halign">center</property>
-                                        <property name="valign">center</property>
-                                        <property name="action-name">app.new-game</property>
-                                        <property name="tooltip-text" translatable="yes">Start a new 
puzzle</property>
-                                        <property name="width-request">120</property>
-                                        <property name="height-request">60</property>
-                                    </object>
+                                        <property name="halign">end</property>
+                                        <property name="valign">end</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                            <object class="GtkButton" id="clear_button">
+                                                <property name="visible">True</property>
+                                                <property name="use_underline">True</property>
+                                                <property name="label" translatable="yes">_Clear 
Board</property>
+                                                <property name="halign">center</property>
+                                                <property name="valign">center</property>
+                                                <property name="action-name">app.reset</property>
+                                                <property name="tooltip-text" translatable="yes">Reset the 
board to its original state</property>
+                                                <property name="width-request">120</property>
+                                                <property name="height-request">60</property>
+                                            </object>
+                                            <packing>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">0</property>
+                                            </packing>
+                                        </child>
+                                        <child>
+                                            <object class="GtkButton" id="new_button">
+                                                <property name="visible">True</property>
+                                                <property name="use_underline">True</property>
+                                                <property name="label" translatable="yes">_New 
Puzzle</property>
+                                                <property name="halign">center</property>
+                                                <property name="valign">center</property>
+                                                <property name="action-name">app.new-game</property>
+                                                <property name="tooltip-text" translatable="yes">Start a new 
puzzle</property>
+                                                <property name="width-request">120</property>
+                                                <property name="height-request">60</property>
+                                            </object>
+                                            <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">1</property>
+                                            </packing>
+                                        </child>
+                                    </object>  <!-- End of controls_box -->
                                     <packing>
                                         <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">1</property>
+                                        <property name="fill">True</property>
+                                        <property name="pack-type">end</property>
+                                        <property name="padding">0</property>
                                     </packing>
                                 </child>
-                            </object>  <!-- End of controls_box -->
-                            <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                            </packing>
-                        </child>
-                        <child>
-                            <object class="GtkBox" id="grid_box">
-                                <property name="width-request">475</property>
-                                <property name="height-request">475</property>
-                                <property name="visible">True</property>
-                                <child>
-                                    <placeholder/>
-                                </child>
-                            </object>
-                            <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
-                            </packing>
+                            </object> <!-- End of game_box -->
                         </child>
-                    </object> <!-- End of game_box -->
+                    </object>
                     <packing>
-                        <property name="name">game_box</property>
+                        <property name="name">frame</property>
                     </packing>
                 </child>
             </object>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 70ecb66..fdfbbc6 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -18,7 +18,7 @@ public class Sudoku : Gtk.Application
 
     private HeaderBar header_bar;
     private Stack main_stack;
-    private Box grid_box; // Holds the view
+    private Box game_box; // Holds the view
 
     private Box undo_redo_box;
     private Button back_button;
@@ -113,6 +113,21 @@ public class Sudoku : Gtk.Application
 
     protected override void activate () {
         builder = new Builder ();
+
+        var css_provider = new Gtk.CssProvider ();
+        try
+        {
+            /* Pixel-perfect compatibility with games that have a Button without ButtonBox. */
+            var data = """GtkButtonBox { -GtkButtonBox-child-internal-pad-x:0; }
+                          GtkBox#start_box { margin:0 80px 0 80px; }""";
+            css_provider.load_from_data (data, data.length);
+        }
+        catch (GLib.Error e)
+        {
+            warning ("Error loading css styles: %s", e.message);
+        }
+        Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+
         try
         {
             builder.add_from_resource ("/org/gnome/gnome-sudoku/ui/gnome-sudoku.ui");
@@ -130,7 +145,7 @@ public class Sudoku : Gtk.Application
 
         header_bar = (HeaderBar) builder.get_object ("headerbar");
         main_stack = (Stack) builder.get_object ("main_stack");
-        grid_box = (Box) builder.get_object ("grid_box");
+        game_box = (Box) builder.get_object ("game_box");
         undo_redo_box = (Box) builder.get_object ("undo_redo_box");
         back_button = (Button) builder.get_object ("back_button");
 
@@ -166,7 +181,7 @@ public class Sudoku : Gtk.Application
         clear_action.set_enabled (!board.is_empty ());
 
         if (view != null) {
-            grid_box.remove (view);
+            game_box.remove (view);
         }
 
         header_bar_subtitle = board.difficulty_category.to_string ();
@@ -177,12 +192,13 @@ public class Sudoku : Gtk.Application
         game.timer.start ();
 
         view = new SudokuView (game);
+        view.set_size_request (480, 480);
 
         view.show_possibilities = show_possibilities;
         view.show_warnings = settings.get_boolean ("show-warnings");
 
         view.show ();
-        grid_box.pack_start (view);
+        game_box.pack_start (view);
 
         game.cell_changed.connect (() => {
             undo_action.set_enabled (!game.is_undostack_null ());
@@ -271,7 +287,7 @@ public class Sudoku : Gtk.Application
 
     private void back_cb ()
     {
-        main_stack.set_visible_child_name ("game_box");
+        main_stack.set_visible_child_name ("frame");
         back_button.visible = false;
         undo_redo_box.visible = true;
         header_bar.set_subtitle (header_bar_subtitle);
@@ -280,7 +296,7 @@ public class Sudoku : Gtk.Application
 
     private void undo_cb ()
     {
-        if (main_stack.get_visible_child_name () != "game_box")
+        if (main_stack.get_visible_child_name () != "frame")
             return;
         game.undo ();
         undo_action.set_enabled (!game.is_undostack_null ());
@@ -289,7 +305,7 @@ public class Sudoku : Gtk.Application
 
     private void redo_cb ()
     {
-        if (main_stack.get_visible_child_name () != "game_box")
+        if (main_stack.get_visible_child_name () != "frame")
             return;
         game.redo ();
         redo_action.set_enabled (!game.is_redostack_null ());
@@ -298,7 +314,7 @@ public class Sudoku : Gtk.Application
 
     private void print_cb ()
     {
-        if (main_stack.get_visible_child_name () != "game_box")
+        if (main_stack.get_visible_child_name () != "frame")
             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]