[swell-foop/arnaudb/code-improvements: 3/9] Use GtkBuilder more.



commit 682a715a1cbe8da3b2a4543c66ae1a36280ebebd
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat May 2 00:28:46 2020 +0200

    Use GtkBuilder more.

 data/first-run-stack.ui               | 73 +++++++++++++++++++++++++++++++++++
 data/meson.build                      |  4 --
 src/org.gnome.SwellFoop.gresource.xml |  2 +
 src/window.vala                       | 55 +++++++-------------------
 4 files changed, 89 insertions(+), 45 deletions(-)
---
diff --git a/data/first-run-stack.ui b/data/first-run-stack.ui
new file mode 100644
index 0000000..ee9a91c
--- /dev/null
+++ b/data/first-run-stack.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   This file is part of Swell-Foop.
+
+   Copyright (C) 2020 Arnaud Bonatti <arnaud bonatti gmail com>
+
+   Swell-Foop 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 2 of the License, or
+   (at your option) any later version.
+
+   Swell-Foop 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 Swell-Foop.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkStack" id="first_run_stack">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <child>
+          <object class="GtkImage">
+            <property name="icon-name">org.gnome.SwellFoop</property>
+            <property name="visible">True</property>
+            <property name="icon-size">6</property>
+            <property name="pixel-size">96</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Welcome to Swell Foop</property>
+            <style>
+              <class name="welcome"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="tip_label">
+            <property name="visible">True</property>
+            <property name="justify">center</property>
+            <style>
+              <class name="tip"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="play_button">
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="label" translatable="yes">Let’s _Play</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <style>
+              <class name="play"/>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/data/meson.build b/data/meson.build
index 379c5a8..f08b126 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -14,10 +14,6 @@ install_data('preferences.ui',
   install_dir: pkgdatadir,
 )
 
-install_data('swell-foop.css',
-  install_dir: pkgdatadir,
-)
-
 desktop = 'org.gnome.SwellFoop.desktop'
 
 # Desktop file
diff --git a/src/org.gnome.SwellFoop.gresource.xml b/src/org.gnome.SwellFoop.gresource.xml
index b56feaa..a8e2438 100644
--- a/src/org.gnome.SwellFoop.gresource.xml
+++ b/src/org.gnome.SwellFoop.gresource.xml
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/SwellFoop/ui">
+    <file preprocess="xml-stripblanks" alias="first-run-stack.ui">../data/first-run-stack.ui</file>
+    <file alias="swell-foop.css">../data/swell-foop.css</file>
     <file preprocess="xml-stripblanks" alias="swell-foop.ui">../data/swell-foop.ui</file>
   </gresource>
 </gresources>
diff --git a/src/window.vala b/src/window.vala
index 9f3bd69..9a5946a 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -108,59 +108,32 @@ private class SwellFoopWindow : ApplicationWindow
 
     private Stack build_first_run_stack ()
     {
-        var stack = new Stack ();
-        var first_vbox = new Box (Orientation.VERTICAL, 12);
-        load_css ();
-        var logo = new Image.from_icon_name ("org.gnome.SwellFoop", IconSize.DIALOG);
-        logo.set_pixel_size (96);
-        first_vbox.pack_start (logo, false);
-        var label = new Label (_("Welcome to Swell Foop"));
-        label.get_style_context ().add_class ("welcome");
-        first_vbox.pack_start (label, false);
-        label = new Label (_("Clear as many blocks as you can.\nFewer clicks means more points."));
-        label.get_style_context ().add_class ("tip");
-        first_vbox.pack_start (label, false);
-        var play_button = new Button.with_mnemonic (_("Let’s _Play"));
-        play_button.get_style_context ().add_class ("play");
-        play_button.get_style_context ().add_class ("suggested-action");
-        play_button.valign = Align.CENTER;
-        play_button.halign = Align.CENTER;
+        CssProvider css_provider = new CssProvider ();
+        css_provider.load_from_resource ("/org/gnome/SwellFoop/ui/swell-foop.css");
+        Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+        if (gdk_screen != null) // else..?
+            StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+        Builder builder = new Builder.from_resource ("/org/gnome/SwellFoop/ui/first-run-stack.ui");
+        var stack = (Stack) builder.get_object ("first_run_stack");
+        var tip_label = (Label) builder.get_object ("tip_label");
+        tip_label.set_label (_("Clear as many blocks as you can.\nFewer clicks means more points."));
+        var play_button = (Button) builder.get_object ("play_button");
         play_button.clicked.connect (() => {
             /* FIXME: Currently, on Wayland, the game frame is displayed outside
              * the window if there's a transition set. Uncomment these 2 lines
              * when that's no longer a problem.
-             *
-             * stack.set_transition_type (StackTransitionType.SLIDE_UP);
-             * stack.set_transition_duration (500);
              */
+              stack.set_transition_type (StackTransitionType.SLIDE_UP);
+              stack.set_transition_duration (500);
+             /* */
             stack.set_visible_child_name ("game");
             key_press_event.connect (key_press_event_cb);
             settings.set_boolean ("first-run", false);
         });
-        first_vbox.pack_start (play_button, false);
-        first_vbox.halign = Align.CENTER;
-        first_vbox.valign = Align.CENTER;
-        stack.add_named (first_vbox, "first-run");
-        stack.set_visible_child_name ("first-run");
-        stack.show_all ();
         return stack;
     }
 
-    private void load_css ()
-    {
-        var css_provider = new CssProvider ();
-        var css_path = Path.build_filename (Config.DATADIR, "swell-foop.css");
-        try
-        {
-            css_provider.load_from_path (css_path);
-        }
-        catch (GLib.Error e)
-        {
-            warning ("Error loading css styles from %s: %s", css_path, e.message);
-        }
-        StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
-    }
-
     /*\
     * * various
     \*/


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