[lightsoff/arnaudb/rework-ui: 3/5] Create AspectFrame in UI file.




commit a0e70830a9f6de91550be641373ca7ef93f84e19
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Oct 29 16:07:39 2020 +0100

    Create AspectFrame in UI file.

 data/lightsoff.ui         | 11 +++++++++++
 src/lightsoff-window.vala | 16 ++++------------
 2 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/data/lightsoff.ui b/data/lightsoff.ui
index f9a555b..c62f928 100644
--- a/data/lightsoff.ui
+++ b/data/lightsoff.ui
@@ -27,6 +27,7 @@
   <requires lib="gtk+" version="3.12"/>
   <template class="LightsoffWindow" parent="ManagedWindow">
     <property name="can_focus">False</property>
+    <property name="resizable">True</property>
     <child type="titlebar">
       <object class="GtkHeaderBar" id="headerbar">
         <property name="visible">True</property>
@@ -75,5 +76,15 @@
         </child>
       </object>
     </child>
+    <child>
+      <object class="GtkAspectFrame" id="aspect_frame">
+        <property name="visible">True</property>
+        <property name="obey_child">False</property>
+        <property name="shadow_type">none</property>
+        <style>
+          <class name="aspect"/>
+        </style>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/lightsoff-window.vala b/src/lightsoff-window.vala
index 18d7d1c..67ba221 100644
--- a/src/lightsoff-window.vala
+++ b/src/lightsoff-window.vala
@@ -18,6 +18,7 @@ private class LightsoffWindow : ManagedWindow
     [GtkChild] private HeaderBar    headerbar;
     [GtkChild] private MenuButton   menu_button;
     [GtkChild] private Label        score_label;
+    [GtkChild] private AspectFrame  aspect_frame;
 
     private GLib.Settings settings;
     private GameView game_view;
@@ -37,26 +38,19 @@ private class LightsoffWindow : ManagedWindow
         key_controller.key_pressed.connect (on_key_pressed);
     }
 
-    private Gtk.Widget build_game_container (int level, out GameView out_game_view)
+    private inline void populate_game_container (int level)
     {
-        var aspect_frame = new Gtk.AspectFrame (null, 0.5f, 0.5f, 1.0f, false);
-        aspect_frame.set_shadow_type (ShadowType.NONE);
-        aspect_frame.get_style_context ().add_class ("aspect");
-        aspect_frame.show ();
-
         GtkGameView gtk_game_view = new GtkGameView (level);
         gtk_game_view.show ();
 
         aspect_frame.add (gtk_game_view);
-        out_game_view = gtk_game_view;
+        game_view = gtk_game_view;
 
         var provider = new Gtk.CssProvider ();
         provider.load_from_resource ("/org/gnome/LightsOff/ui/lightsoff.css");
         Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
         if (gdk_screen != null) // else..?
             StyleContext.add_provider_for_screen ((!) gdk_screen, provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
-
-        return aspect_frame;
     }
 
     internal LightsoffWindow ()
@@ -75,12 +69,10 @@ private class LightsoffWindow : ManagedWindow
         int level = settings.get_int ("level");
         level_changed_cb (level);
 
-        this.add (build_game_container (level, out game_view));
+        populate_game_container (level);
 
-        this.set_resizable (true);
         game_view.level_changed.connect (level_changed_cb);
         game_view.moves_changed.connect (update_subtitle);
-
     }
 
     private void update_subtitle (int moves)


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