[gnome-games/wip/exalm/mobile: 5/8] ui: Use HdyViewSwitcherBar for narrow mode
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/mobile: 5/8] ui: Use HdyViewSwitcherBar for narrow mode
- Date: Tue, 28 May 2019 18:37:00 +0000 (UTC)
commit 0fb504dfaacf0f5432b3963d06e5cb026f93731a
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed May 22 18:47:36 2019 +0500
ui: Use HdyViewSwitcherBar for narrow mode
Create AdaptiveState in CollectionView, pass it to CollectionBox and
CollectionHeaderBar. Set its 'is-showing-bottom-bar' property to true when
HdySqueezer in the headerbar is showing title instead of view switcher.
Use it to show a HdyViewSwitcherBar in CollectionBox when it's true.
data/ui/collection-box.ui | 6 +++++
data/ui/collection-header-bar.ui | 6 ++---
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
src/ui/collection-box.vala | 20 ++++++++++++++--
src/ui/collection-header-bar.vala | 50 ++++++++++++++++++++++++++++++++++-----
src/ui/collection-view.vala | 7 ++++--
7 files changed, 78 insertions(+), 13 deletions(-)
---
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index 50fa825f..344451a5 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -102,6 +102,12 @@
</child>
</object>
</child>
+ <child>
+ <object class="HdyViewSwitcherBar" id="view_switcher_bar">
+ <property name="visible">True</property>
+ <property name="stack">viewstack</property>
+ </object>
+ </child>
</template>
<object class="GtkImage" id="close_icon">
<property name="visible">True</property>
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index aadd4db9..3402063a 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -54,9 +54,10 @@
</packing>
</child>
<child type="title">
- <object class="GtkStack" id="title_stack">
+ <object class="HdySqueezer" id="title_squeezer">
<property name="visible">True</property>
<property name="transition-type">crossfade</property>
+ <signal name="notify::visible-child" handler="on_squeezer_visible_child_changed"/>
<child>
<object class="HdyViewSwitcher" id="view_switcher">
<property name="visible">True</property>
@@ -64,9 +65,8 @@
</object>
</child>
<child>
- <object class="GtkLabel" id="empty_title">
+ <object class="GtkLabel" id="title_label">
<property name="visible">True</property>
- <property name="label" translatable="yes">Games</property>
<style>
<class name="title"/>
</style>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5221aa79..379b6b73 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -65,6 +65,7 @@ src/retro/retro-runner.vala
src/retro/retro-simple-type.vala
src/ui/application.vala
src/ui/application-window.vala
+src/ui/collection-header-bar.vala
src/ui/display-view.vala
src/ui/error-display.vala
src/ui/gamepad-mapper.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 83735b4f..566b73f4 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -40,6 +40,7 @@ src/retro/retro-runner.c
src/retro/retro-simple-type.c
src/ui/application.c
src/ui/application-window.c
+src/ui/collection-header-bar.c
src/ui/display-view.c
src/ui/error-display.c
src/ui/gamepad-mapper.c
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index e6d87b38..ae621b81 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -22,6 +22,9 @@ private class Games.CollectionBox : Gtk.Box {
private PlatformsView platform_view;
[GtkChild (name = "viewstack")]
private Gtk.Stack _viewstack;
+ [GtkChild]
+ private Hdy.ViewSwitcherBar view_switcher_bar;
+
public Gtk.Stack viewstack {
get { return _viewstack; }
}
@@ -38,13 +41,22 @@ private class Games.CollectionBox : Gtk.Box {
}
}
+ private AdaptiveState _adaptive_state;
+ public AdaptiveState adaptive_state {
+ get { return _adaptive_state; }
+ construct {
+ _adaptive_state = value;
+ adaptive_state.notify["is-showing-bottom-bar"].connect (update_bottom_bar);
+ }
+ }
+
private Binding collection_binding;
private Binding platform_collection_binding;
private Binding search_binding;
private Binding loading_notification_binding;
- public CollectionBox (ListModel collection) {
- Object (collection: collection);
+ public CollectionBox (ListModel collection, AdaptiveState adaptive_state) {
+ Object (collection: collection, adaptive_state: adaptive_state);
}
construct {
@@ -166,4 +178,8 @@ private class Games.CollectionBox : Gtk.Box {
public bool search_bar_handle_event (Gdk.Event event) {
return search_bar.handle_event (event);
}
+
+ private void update_bottom_bar () {
+ view_switcher_bar.reveal = adaptive_state.is_showing_bottom_bar;
+ }
}
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index 5f42ffcf..0cb9da68 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -7,8 +7,16 @@ private class Games.CollectionHeaderBar : Gtk.HeaderBar {
public Gtk.Stack viewstack {
get { return _viewstack; }
set {
+ if (viewstack_child_changed_id != 0) {
+ viewstack.disconnect (viewstack_child_changed_id);
+ viewstack_child_changed_id = 0;
+ }
+
_viewstack = value;
view_switcher.stack = _viewstack;
+
+ if (viewstack != null)
+ viewstack_child_changed_id = viewstack.notify["visible-child"].connect
(update_title);
}
}
@@ -17,26 +25,56 @@ private class Games.CollectionHeaderBar : Gtk.HeaderBar {
get { return _is_collection_empty; }
set {
_is_collection_empty = value;
- if (_is_collection_empty)
- title_stack.visible_child = empty_title;
- else
- title_stack.visible_child = view_switcher;
+ title_squeezer.set_child_enabled (view_switcher, !value);
search.sensitive = !_is_collection_empty;
+ update_adaptive_state ();
}
}
[GtkChild]
- private Gtk.Stack title_stack;
+ private Hdy.Squeezer title_squeezer;
[GtkChild]
- private Gtk.Label empty_title;
+ private Gtk.Label title_label;
[GtkChild]
private Hdy.ViewSwitcher view_switcher;
[GtkChild]
private Gtk.ToggleButton search;
private Binding search_binding;
+ public AdaptiveState adaptive_state { get; construct; }
+
+ private ulong viewstack_child_changed_id;
+
construct {
search_binding = bind_property ("search-mode", search, "active",
BindingFlags.BIDIRECTIONAL);
}
+
+ public CollectionHeaderBar (AdaptiveState adaptive_state) {
+ Object (adaptive_state: adaptive_state);
+ }
+
+ [GtkCallback]
+ private void on_squeezer_visible_child_changed () {
+ update_adaptive_state ();
+ }
+
+ private void update_adaptive_state () {
+ bool showing_title = title_squeezer.visible_child != view_switcher;
+ adaptive_state.is_showing_bottom_bar = showing_title && !is_collection_empty;
+
+ update_title ();
+ }
+
+ private void update_title () {
+ var title = _("Games");
+
+ if (!is_collection_empty) {
+ var child = viewstack.visible_child;
+
+ viewstack.child_get (child, "title", out title, null);
+ }
+
+ title_label.label = title;
+ }
}
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 95c8cb5a..8455e5b9 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -58,10 +58,13 @@ private class Games.CollectionView : Object, UiView {
private Binding header_bar_empty_collection_binding;
private KonamiCode konami_code;
+ private AdaptiveState adaptive_state;
construct {
- box = new CollectionBox (collection);
- header_bar = new CollectionHeaderBar ();
+ adaptive_state = new AdaptiveState ();
+
+ box = new CollectionBox (collection, adaptive_state);
+ header_bar = new CollectionHeaderBar (adaptive_state);
box.game_activated.connect (game => {
game_activated (game);
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]