[fractal/fractal-next] Add navigation support for small screens
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] Add navigation support for small screens
- Date: Sat, 8 May 2021 20:47:44 +0000 (UTC)
commit ce9bfd8922da6b96b1f2f3587cafe7cc7278b414
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Fri May 7 08:51:09 2021 +0200
Add navigation support for small screens
data/resources/ui/content.ui | 7 +++++++
data/resources/ui/session.ui | 8 ++++----
src/session/content/content.rs | 3 +++
src/session/mod.rs | 9 +++++++++
src/session/sidebar/selection.rs | 24 +++++++++++++-----------
5 files changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/data/resources/ui/content.ui b/data/resources/ui/content.ui
index f7eda40f..612ccb46 100644
--- a/data/resources/ui/content.ui
+++ b/data/resources/ui/content.ui
@@ -9,6 +9,13 @@
<child>
<object class="AdwHeaderBar" id="headerbar">
<property name="show-start-title-buttons" bind-source="Content" bind-property="compact"
bind-flags="sync-create"/>
+ <child type="start">
+ <object class="GtkButton" id="back">
+ <property name="visible" bind-source="Content" bind-property="compact"
bind-flags="sync-create"/>
+ <property name="icon-name">go-previous-symbolic</property>
+ <property name="action-name">content.go-back</property>
+ </object>
+ </child>
<child type="end">
<object class="GtkMenuButton" id="room_menu">
<property name="icon-name">view-more-symbolic</property>
diff --git a/data/resources/ui/session.ui b/data/resources/ui/session.ui
index a7784cd6..91826c35 100644
--- a/data/resources/ui/session.ui
+++ b/data/resources/ui/session.ui
@@ -2,18 +2,18 @@
<interface>
<template class="Session" parent="AdwBin">
<child>
- <object class="AdwLeaflet" id="session">
+ <object class="AdwLeaflet" id="leaflet">
<child>
<object class="Sidebar" id="sidebar">
- <property name="compact" bind-source="session" bind-property="folded" bind-flags="sync-create" />
+ <property name="compact" bind-source="leaflet" bind-property="folded" bind-flags="sync-create" />
<property name="categories" bind-source="Session" bind-property="categories"
bind-flags="sync-create" />
<property name="selected-room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create | bidirectional" />
</object>
</child>
<child>
<object class="Content" id="content">
- <property name="compact" bind-source="session" bind-property="folded" bind-flags="sync-create" />
- <property name="room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create" />
+ <property name="compact" bind-source="leaflet" bind-property="folded" bind-flags="sync-create" />
+ <property name="room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create | bidirectional" />
</object>
</child>
</object>
diff --git a/src/session/content/content.rs b/src/session/content/content.rs
index 20b527cd..91d73eac 100644
--- a/src/session/content/content.rs
+++ b/src/session/content/content.rs
@@ -38,6 +38,9 @@ mod imp {
Self::bind_template(klass);
klass.set_accessible_role(gtk::AccessibleRole::Group);
+ klass.install_action("content.go-back", None, move |widget, _, _| {
+ widget.set_room(None);
+ });
klass.install_action("content.send-text-message", None, move |widget, _, _| {
widget.send_text_message();
});
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 9a1795c1..ab8b303e 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -44,6 +44,8 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/FractalNext/session.ui")]
pub struct Session {
+ #[template_child]
+ pub leaflet: TemplateChild<adw::Leaflet>,
#[template_child]
pub sidebar: TemplateChild<Sidebar>,
#[template_child]
@@ -170,6 +172,13 @@ impl Session {
return;
}
+ let leaflet = priv_.leaflet.get();
+ if selected_room.is_some() {
+ leaflet.navigate(adw::NavigationDirection::Forward);
+ } else {
+ leaflet.navigate(adw::NavigationDirection::Back);
+ }
+
priv_.selected_room.replace(selected_room);
self.notify("selected-room");
diff --git a/src/session/sidebar/selection.rs b/src/session/sidebar/selection.rs
index 4af219d0..6eeabf76 100644
--- a/src/session/sidebar/selection.rs
+++ b/src/session/sidebar/selection.rs
@@ -267,21 +267,23 @@ impl Selection {
let mut selected = GTK_INVALID_LIST_POSITION;
- if let Some(model) = self.model() {
- for i in 0..=model.n_items() {
- let room = model
- .item(i)
- .and_then(|o| o.downcast::<gtk::TreeListRow>().ok())
- .and_then(|r| r.item())
- .and_then(|o| o.downcast::<Room>().ok());
- if room == selected_room {
- selected = i;
- break;
+ if room.is_some() {
+ if let Some(model) = self.model() {
+ for i in 0..model.n_items() {
+ let r = model
+ .item(i)
+ .and_then(|o| o.downcast::<gtk::TreeListRow>().ok())
+ .and_then(|r| r.item())
+ .and_then(|o| o.downcast::<Room>().ok());
+ if r == room {
+ selected = i;
+ break;
+ }
}
}
}
- priv_.selected_room.replace(selected_room);
+ priv_.selected_room.replace(room);
if old_selected != selected {
priv_.selected.replace(selected);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]