[gnome-2048/arnaudb/wip/gtk4: 51/57] Use an UI file for Game.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048/arnaudb/wip/gtk4: 51/57] Use an UI file for Game.
- Date: Mon, 28 Sep 2020 14:35:55 +0000 (UTC)
commit 476d4a2b8c5a3e51a9942a3c9970b76dc2130fea
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jul 16 19:23:38 2020 +0200
Use an UI file for Game.
data/game.ui | 60 ++++++++++++++++++++++++++++
src/game.vala | 43 ++------------------
src/org.gnome.TwentyFortyEight.gresource.xml | 7 ++--
3 files changed, 68 insertions(+), 42 deletions(-)
---
diff --git a/data/game.ui b/data/game.ui
new file mode 100644
index 0000000..c49de6d
--- /dev/null
+++ b/data/game.ui
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ This file is part of GNOME 2048
+
+ GNOME 2048 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 2048 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 2048. If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+ <requires lib="gtk+" version="3.99"/>
+ <template class="Game" parent="GtkWidget">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="focusable">True</property>
+ <child>
+ <object class="GtkOverlay">
+ <child>
+ <object class="GtkGrid" id="_background_grid">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="column-homogeneous">True</property>
+ <property name="row-homogeneous">True</property>
+ <property name="column-spacing">8</property>
+ <property name="row-spacing">8</property>
+ <property name="margin-start">8</property>
+ <property name="margin-end">8</property>
+ <property name="margin-top">8</property>
+ <property name="margin-bottom">8</property>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkGrid" id="_foreground_grid">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="column-homogeneous">True</property>
+ <property name="row-homogeneous">True</property>
+ <property name="column-spacing">8</property>
+ <property name="row-spacing">8</property>
+ <property name="margin-start">8</property>
+ <property name="margin-end">8</property>
+ <property name="margin-top">8</property>
+ <property name="margin-bottom">8</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="background-grid"/>
+ </style>
+ </template>
+</interface>
diff --git a/src/game.vala b/src/game.vala
index 66a74c3..d85ece2 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -18,8 +18,12 @@
along with GNOME 2048. If not, see <https://www.gnu.org/licenses/>.
*/
+[GtkTemplate (ui = "/org/gnome/TwentyFortyEight/ui/game.ui")]
private class Game : Gtk.Widget
{
+ [GtkChild] private Gtk.Grid _background_grid;
+ [GtkChild] private Gtk.Grid _foreground_grid;
+
internal int width { internal get; private set; }
internal int height { internal get; private set; }
@@ -69,51 +73,12 @@ private class Game : Gtk.Widget
private uint _resize_view_id;
- private Gtk.Grid _background_grid;
- private Gtk.Grid _foreground_grid;
-
construct
{
Gtk.BinLayout layout = new Gtk.BinLayout ();
set_layout_manager (layout);
- focusable = true;
-
// map.connect (_init_state_watcher);
-
- add_css_class ("background-grid");
-
- _background_grid = new Gtk.Grid ();
- _background_grid.hexpand = true;
- _background_grid.vexpand = true;
- _background_grid.column_homogeneous = true;
- _background_grid.row_homogeneous = true;
- _background_grid.column_spacing = 8;
- _background_grid.row_spacing = 8;
- _background_grid.margin_start = 8;
- _background_grid.margin_end = 8;
- _background_grid.margin_top = 8;
- _background_grid.margin_bottom = 8;
-
- _foreground_grid = new Gtk.Grid ();
- _foreground_grid.hexpand = true;
- _foreground_grid.vexpand = true;
- _foreground_grid.column_homogeneous = true;
- _foreground_grid.row_homogeneous = true;
- _foreground_grid.column_spacing = 8;
- _foreground_grid.row_spacing = 8;
- _foreground_grid.margin_start = 8;
- _foreground_grid.margin_end = 8;
- _foreground_grid.margin_top = 8;
- _foreground_grid.margin_bottom = 8;
-
- Gtk.Overlay overlay = new Gtk.Overlay ();
- overlay.set_child (_background_grid);
- overlay.add_overlay (_foreground_grid);
- overlay.insert_after (this, /* insert first */ null);
-
- hexpand = true;
- vexpand = true;
}
internal Game (ref GLib.Settings settings)
diff --git a/src/org.gnome.TwentyFortyEight.gresource.xml b/src/org.gnome.TwentyFortyEight.gresource.xml
index 8e6c2d0..081a53d 100644
--- a/src/org.gnome.TwentyFortyEight.gresource.xml
+++ b/src/org.gnome.TwentyFortyEight.gresource.xml
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/TwentyFortyEight/ui">
- <file preprocess="xml-stripblanks" alias="congrats.ui">../data/congrats.ui</file>
+ <file preprocess="xml-stripblanks" alias="congrats.ui" >../data/congrats.ui</file>
+ <file preprocess="xml-stripblanks" alias="game.ui" >../data/game.ui</file>
<file preprocess="xml-stripblanks" alias="game-headerbar.ui">../data/game-headerbar.ui</file>
- <file preprocess="xml-stripblanks" alias="game-window.ui">../data/mainwindow.ui</file>
+ <file preprocess="xml-stripblanks" alias="game-window.ui" >../data/mainwindow.ui</file>
<file alias="gnome-2048.css">../data/gnome-2048.css</file>
</gresource>
<gresource prefix="/org/gnome/TwentyFortyEight/gtk">
- <file preprocess="xml-stripblanks" alias="help-overlay.ui">../data/help-overlay.ui</file>
+ <file preprocess="xml-stripblanks" alias="help-overlay.ui" >../data/help-overlay.ui</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]