[gnome-clocks/wip/exalm/hdy] headerbar: Fix view switcher
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/exalm/hdy] headerbar: Fix view switcher
- Date: Tue, 25 Feb 2020 18:52:36 +0000 (UTC)
commit 52b82633251b478c66f550c5fe21557bf779569f
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Feb 25 23:50:48 2020 +0500
headerbar: Fix view switcher
Don't manually switch the visible switcher and only use one switcher.
data/ui/headerbar.ui | 13 ++-----------
src/headerbar.vala | 25 +++++++------------------
2 files changed, 9 insertions(+), 29 deletions(-)
---
diff --git a/data/ui/headerbar.ui b/data/ui/headerbar.ui
index 9302e62..e28208f 100644
--- a/data/ui/headerbar.ui
+++ b/data/ui/headerbar.ui
@@ -36,21 +36,12 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
+ <signal name="notify::visible-child" handler="visible_child_changed"/>
<child>
- <object class="HdyViewSwitcher" id="title_wide_switcher">
+ <object class="HdyViewSwitcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
- <property name="policy">wide</property>
- <property name="stack" bind-source="ClocksHeaderBar" bind-property="stack"
bind-flags="sync-create">ignore-me</property>
- </object>
- </child>
- <child>
- <object class="HdyViewSwitcher" id="title_narrow_switcher">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="policy">narrow</property>
<property name="stack" bind-source="ClocksHeaderBar" bind-property="stack"
bind-flags="sync-create">ignore-me</property>
</object>
</child>
diff --git a/src/headerbar.vala b/src/headerbar.vala
index 90d3eaf..f623ed4 100644
--- a/src/headerbar.vala
+++ b/src/headerbar.vala
@@ -42,25 +42,21 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
set {
_mode = value;
- var width = get_allocated_width ();
-
switch (_mode) {
case NORMAL:
title_stack.visible_child_name = "switcher";
start_button_stack.show ();
end_button_stack.show ();
end_button_stack.visible_child_name = "menu";
- centering_policy = STRICT;
- switcher_bar.reveal = width <= 500;
break;
case STANDALONE:
title_stack.visible_child_name = "title";
start_button_stack.show ();
end_button_stack.hide ();
- centering_policy = STRICT;
- switcher_bar.reveal = false;
break;
}
+
+ visible_child_changed ();
}
}
@@ -99,26 +95,19 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
[GtkChild]
private Hdy.Squeezer squeezer;
[GtkChild]
- private Hdy.ViewSwitcher title_wide_switcher;
- [GtkChild]
- private Hdy.ViewSwitcher title_narrow_switcher;
- [GtkChild]
private Gtk.Box title_text;
[GtkChild]
private Gtk.Stack title_stack;
[GtkChild]
private Gtk.Revealer reveal_subtitle;
- public override void size_allocate (Gtk.Allocation allocation) {
- base.size_allocate (allocation);
- squeezer.set_child_enabled (title_wide_switcher, allocation.width > 800);
- squeezer.set_child_enabled (title_narrow_switcher, allocation.width > 500);
- squeezer.set_child_enabled (title_text, allocation.width <= 500);
- switcher_bar.reveal = allocation.width <= 500 && view_mode != STANDALONE;
- }
-
[GtkCallback]
private void subtitle_changed () {
reveal_subtitle.reveal_child = subtitle != null && subtitle.length > 0;
}
+
+ [GtkCallback]
+ private void visible_child_changed () {
+ switcher_bar.reveal = squeezer.visible_child == title_text && view_mode == NORMAL;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]