[gnome-sudoku] Rework main menu. Use ListBox



commit b4bfa3242e649a6b21e56163213df3b166d7a473
Author: Andrey Kutejko <andy128k gmail com>
Date:   Wed Aug 5 22:46:44 2020 +0200

    Rework main menu. Use ListBox

 data/gnome-sudoku.ui  | 102 ++++++++++++++++++++------------------------------
 src/gnome-sudoku.vala |   3 ++
 src/main-menu.vala    |  59 +++++++++++++++++++++++++++++
 src/meson.build       |   1 +
 4 files changed, 104 insertions(+), 61 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index edc787b..0fe02e9 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -180,12 +180,48 @@
                 <property name="width-request">350</property>
                 <property name="height-request">350</property>
                 <child>
-                  <object class="GtkButton">
+                  <object class="GtkFrame">
                     <property name="visible">True</property>
-                    <property name="use-underline">True</property>
-                    <property name="label" translatable="yes">_Easy</property>
-                    <property name="action-name">app.start-game</property>
-                    <property name="action-target">1</property>  <!-- 1 corresponds to enum 
DifficultyCategory.EASY -->
+                    <property name="shadow-type">GTK_SHADOW_IN</property>
+                    <child>
+                      <object class="SudokuMainMenu">
+                        <child>
+                          <object class="SudokuMainMenuItem">
+                            <property name="label" translatable="yes">_Easy</property>
+                            <property name="action-name">app.start-game</property>
+                            <property name="action-target">1</property>  <!-- 1 corresponds to enum 
DifficultyCategory.EASY -->
+                          </object>
+                        </child>
+                        <child>
+                          <object class="SudokuMainMenuItem">
+                            <property name="label" translatable="yes">_Medium</property>
+                            <property name="action-name">app.start-game</property>
+                            <property name="action-target">2</property>  <!-- 2 corresponds to enum 
DifficultyCategory.MEDIUM -->
+                          </object>
+                        </child>
+                        <child>
+                          <object class="SudokuMainMenuItem">
+                            <property name="label" translatable="yes">_Hard</property>
+                            <property name="action-name">app.start-game</property>
+                            <property name="action-target">3</property>  <!-- 3 corresponds to enum 
DifficultyCategory.HARD -->
+                          </object>
+                        </child>
+                        <child>
+                          <object class="SudokuMainMenuItem">
+                            <property name="label" translatable="yes">_Very Hard</property>
+                            <property name="action-name">app.start-game</property>
+                            <property name="action-target">4</property>  <!-- 4 corresponds to enum 
DifficultyCategory.VERY_HARD -->
+                          </object>
+                        </child>
+                        <child>
+                          <object class="SudokuMainMenuItem">
+                            <property name="label" translatable="yes">_Create your own puzzle</property>
+                            <property name="action-name">app.create-game</property>
+                            <property name="has-separator">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">True</property>
@@ -193,62 +229,6 @@
                     <property name="position">0</property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="use-underline">True</property>
-                    <property name="label" translatable="yes">_Medium</property>
-                    <property name="action-name">app.start-game</property>
-                    <property name="action-target">2</property>  <!-- 2 corresponds to enum 
DifficultyCategory.MEDIUM -->
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="use-underline">True</property>
-                    <property name="label" translatable="yes">_Hard</property>
-                    <property name="action-name">app.start-game</property>
-                    <property name="action-target">3</property>  <!-- 3 corresponds to enum 
DifficultyCategory.HARD -->
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">2</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="use-underline">True</property>
-                    <property name="label" translatable="yes">_Very Hard</property>
-                    <property name="action-name">app.start-game</property>
-                    <property name="action-target">4</property>  <!-- 4 corresponds to enum 
DifficultyCategory.VERY_HARD -->
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">3</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="use-underline">True</property>
-                    <property name="margin-top">30</property>
-                    <property name="label" translatable="yes">_Create your own puzzle</property>
-                    <property name="action-name">app.create-game</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">5</property>
-                  </packing>
-                </child>
               </object> <!-- End of start_box -->
               <packing>
                 <property name="name">start_box</property>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 0c13ecd..92ca706 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -101,6 +101,9 @@ public class Sudoku : Gtk.Application
 
         Object (application_id: "org.gnome.Sudoku", flags: ApplicationFlags.FLAGS_NONE);
         add_main_option_entries (option_entries);
+
+        typeof (SudokuMainMenu).ensure ();
+        typeof (SudokuMainMenuItem).ensure ();
     }
 
     protected override int handle_local_options (GLib.VariantDict options)
diff --git a/src/main-menu.vala b/src/main-menu.vala
new file mode 100644
index 0000000..a1aa7cc
--- /dev/null
+++ b/src/main-menu.vala
@@ -0,0 +1,59 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright © 2020 Andrii Kuteiko
+ *
+ * This file is part of GNOME Sudoku.
+ *
+ * GNOME Sudoku is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Sudoku is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Sudoku. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Gdk;
+
+private class SudokuMainMenu : ListBox
+{
+    construct
+    {
+        visible = true;
+        can_focus = false;
+        set_header_func ((row) => {
+            var mi = row as SudokuMainMenuItem;
+            if (mi != null && mi.has_separator)
+            {
+                var separator = new Separator (Orientation.HORIZONTAL);
+                mi.set_header (separator);
+            }
+        });
+    }
+}
+
+private class SudokuMainMenuItem : ListBoxRow
+{
+    public string label { get; set construct; }
+    public bool has_separator { get; set construct; }
+
+    construct
+    {
+        height_request = 80;
+        visible = true;
+        can_focus = true;
+
+        var label_widget = new Label (this.label);
+        label_widget.visible = true;
+        label_widget.can_focus = false;
+        label_widget.use_underline = true;
+
+        add (label_widget);
+    }
+}
diff --git a/src/meson.build b/src/meson.build
index 34e6568..4b17c75 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,6 +6,7 @@ gnome_sudoku_vala_args = [
 gnome_sudoku_sources = [
   'config.vapi',
   'gnome-sudoku.vala',
+  'main-menu.vala',
   'number-picker.vala',
   'print-dialog.vala',
   'sudoku-printer.vala',


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