[gnome-games/wip/exalm/unified-window: 42/60] application-window: Switch to HdyApplicationWindow



commit e8932dda40052709d5c9c772fb9f07efe5aec85f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Apr 10 02:50:03 2020 +0500

    application-window: Switch to HdyApplicationWindow
    
    Move headerbars inside the window for this.

 data/ui/application-window.ui     | 14 ++------------
 data/ui/collection-box.ui         |  7 +++++++
 data/ui/display-box.ui            |  8 +++++++-
 src/ui/application-window.vala    | 15 +++++----------
 src/ui/collection-box.vala        | 13 ++++++++++---
 src/ui/collection-header-bar.vala |  6 +-----
 src/ui/collection-view.vala       |  5 ++---
 src/ui/display-box.vala           | 10 +++++++++-
 src/ui/display-view.vala          |  2 +-
 9 files changed, 44 insertions(+), 36 deletions(-)
---
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index c5d87266..ad62942d 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="GamesApplicationWindow" parent="GtkApplicationWindow">
+  <template class="GamesApplicationWindow" parent="HdyApplicationWindow">
     <property name="default-width">768</property>
     <property name="default-height">600</property>
     <property name="show-menubar">False</property>
@@ -11,19 +11,9 @@
     <signal name="window-state-event" after="yes" handler="on_window_state_event"/>
     <signal name="notify::is-active" after="yes" handler="on_active_changed"/>
     <child>
-      <object class="GtkStack" id="content_box">
+      <object class="GtkStack" id="stack">
         <property name="visible">True</property>
       </object>
     </child>
-    <child type="titlebar">
-      <object class="HdyTitleBar">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkStack" id="header_bar">
-            <property name="visible">True</property>
-          </object>
-        </child>
-      </object>
-    </child>
   </template>
 </interface>
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index 1ca3f507..cf690892 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -10,6 +10,12 @@
     <signal name="notify::is-folded" handler="update_bottom_bar"/>
     <signal name="notify::is-showing-bottom-bar" handler="update_bottom_bar"/>
     <signal name="notify::is-subview-open" handler="update_bottom_bar"/>
+    <child>
+      <object class="GamesCollectionHeaderBar" id="header_bar">
+        <property name="visible">True</property>
+        <property name="swipe-group">swipe_group</property>
+      </object>
+    </child>
     <child>
       <object class="GamesSearchBar" id="search_bar">
         <property name="visible">True</property>
@@ -130,6 +136,7 @@
       </object>
     </child>
   </template>
+  <object class="HdySwipeGroup" id="swipe_group"/>
   <object class="GtkImage" id="close_icon">
     <property name="visible">True</property>
     <property name="icon-name">window-close-symbolic</property>
diff --git a/data/ui/display-box.ui b/data/ui/display-box.ui
index 84267862..f6f76a76 100644
--- a/data/ui/display-box.ui
+++ b/data/ui/display-box.ui
@@ -1,10 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="GamesDisplayBox" parent="GtkBin">
+  <template class="GamesDisplayBox" parent="GtkBox">
     <property name="visible">True</property>
+    <property name="orientation">vertical</property>
     <signal name="notify::is-showing-snapshots" handler="block_autohide_changed"/>
     <signal name="notify::is-menu-open" handler="block_autohide_changed"/>
+    <child>
+      <object class="GamesDisplayHeaderBar" id="header_bar">
+        <property name="visible">True</property>
+      </object>
+    </child>
     <child>
       <object class="GamesFullscreenBox" id="fullscreen_box">
         <property name="visible">True</property>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index a10aeed8..408b35b0 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/application-window.ui")]
-private class Games.ApplicationWindow : Gtk.ApplicationWindow {
+private class Games.ApplicationWindow : Hdy.ApplicationWindow {
        private const uint WINDOW_SIZE_UPDATE_DELAY_MILLISECONDS = 500;
 
        private UiView _current_view;
@@ -16,8 +16,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                        _current_view = value;
 
-                       content_box.visible_child = current_view.content_box;
-                       header_bar.visible_child = current_view.title_bar;
+                       stack.visible_child = current_view.content_box;
 
                        if (current_view != null)
                                current_view.is_view_active = true;
@@ -45,9 +44,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool loading_notification { get; set; }
 
        [GtkChild]
-       private Gtk.Stack content_box;
-       [GtkChild]
-       private Gtk.Stack header_bar;
+       private Gtk.Stack stack;
 
        private CollectionView collection_view;
        private DisplayView display_view;
@@ -85,10 +82,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                collection_view = new CollectionView (this, game_model);
                display_view = new DisplayView (this);
 
-               content_box.add (collection_view.content_box);
-               content_box.add (display_view.content_box);
-               header_bar.add (collection_view.title_bar);
-               header_bar.add (display_view.title_bar);
+               stack.add (collection_view.content_box);
+               stack.add (display_view.content_box);
 
                collection_view.game_activated.connect (on_game_activated);
                display_view.back.connect (on_display_back);
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 48e8f50f..a5aca7b8 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -5,7 +5,6 @@ private class Games.CollectionBox : Gtk.Box {
        public signal void game_activated (Game game);
 
        public GameModel game_model { get; construct; }
-       public Hdy.SwipeGroup swipe_group { get; construct; }
        public bool search_mode { get; set; }
        public bool loading_notification { get; set; }
 
@@ -27,6 +26,14 @@ private class Games.CollectionBox : Gtk.Box {
        private Gtk.Stack _viewstack;
        [GtkChild]
        private Hdy.ViewSwitcherBar view_switcher_bar;
+       [GtkChild (name="header_bar")]
+       private CollectionHeaderBar _header_bar;
+       [GtkChild]
+       private Hdy.SwipeGroup swipe_group;
+
+       public CollectionHeaderBar header_bar {
+               get { return _header_bar; }
+       }
 
        public Gtk.Stack viewstack {
                get { return _viewstack; }
@@ -72,8 +79,8 @@ private class Games.CollectionBox : Gtk.Box {
                swipe_group.add_swipeable (platform_view.get_leaflet ());
        }
 
-       public CollectionBox (GameModel game_model, Hdy.SwipeGroup swipe_group) {
-               Object (game_model: game_model, swipe_group: swipe_group);
+       public CollectionBox (GameModel game_model) {
+               Object (game_model: game_model);
        }
 
        public void show_error (string error_message) {
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 685239a4..49047476 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -23,7 +23,7 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
        public bool is_showing_bottom_bar { get; set; }
        public bool is_subview_open { get; set; }
        public string subview_title { get; set; }
-       public Hdy.SwipeGroup swipe_group { get; construct; }
+       public Hdy.SwipeGroup swipe_group { get; construct set; }
 
        [GtkChild]
        private Hdy.Deck deck;
@@ -36,10 +36,6 @@ private class Games.CollectionHeaderBar : Gtk.Bin {
 
        private ulong viewstack_child_changed_id;
 
-       public CollectionHeaderBar (Hdy.SwipeGroup swipe_group) {
-               Object (swipe_group: swipe_group);
-       }
-
        [GtkCallback]
        private void update_adaptive_state () {
                bool showing_title = view_switcher_title.title_visible;
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index ee872bec..a22f7836 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -47,10 +47,9 @@ private class Games.CollectionView : Object, UiView {
        private KonamiCode konami_code;
 
        construct {
-               var swipe_group = new Hdy.SwipeGroup ();
+               box = new CollectionBox (game_model);
+               header_bar = box.header_bar;
 
-               box = new CollectionBox (game_model, swipe_group);
-               header_bar = new CollectionHeaderBar (swipe_group);
                box.game_activated.connect (game => {
                        game_activated (game);
                });
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 45b46cc9..ac0983e3 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/display-box.ui")]
-private class Games.DisplayBox : Gtk.Bin {
+private class Games.DisplayBox : Gtk.Box {
        public signal void back ();
        public signal void snapshots_hidden ();
        public signal void restart ();
@@ -15,6 +15,8 @@ private class Games.DisplayBox : Gtk.Bin {
                        // A top margin is added to the snapshots list in fullscreen mode
                        // so that the fullscreen header bar doesn't cover it
                        snapshots_list.set_margin (value ? fullscreen_header_bar_height : 0);
+
+                       windowed_header_bar.visible = !value;
                }
        }
 
@@ -69,6 +71,12 @@ private class Games.DisplayBox : Gtk.Bin {
        private FlashBox flash_box;
        [GtkChild]
        private SnapshotsList snapshots_list;
+       [GtkChild (name="header_bar")]
+       private DisplayHeaderBar _header_bar;
+
+       public DisplayHeaderBar windowed_header_bar {
+               get { return _header_bar; }
+       }
 
        private int fullscreen_header_bar_height;
 
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 02cffb21..0fdaf734 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -73,7 +73,7 @@ private class Games.DisplayView : Object, UiView {
 
        construct {
                box = new DisplayBox ();
-               header_bar = new DisplayHeaderBar ();
+               header_bar = box.windowed_header_bar;
 
                box.back.connect (on_display_back);
                header_bar.back.connect (on_display_back);


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