Add navigation support for small screens

This commit is contained in:
Kévin Commaille 2021-05-07 08:51:09 +02:00
parent 8a3150f6fa
commit ce9bfd8922
No known key found for this signature in database
GPG key ID: 296D60AE1E61661C
5 changed files with 36 additions and 15 deletions

View file

@ -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>

View file

@ -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>

View file

@ -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();
});

View file

@ -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");

View file

@ -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);