Browse Source

Add navigation support for small screens

merge-requests/1327/merge
Kévin Commaille 5 years ago
parent
commit
ce9bfd8922
No known key found for this signature in database
GPG Key ID: 296D60AE1E61661C
  1. 7
      data/resources/ui/content.ui
  2. 8
      data/resources/ui/session.ui
  3. 3
      src/session/content/content.rs
  4. 9
      src/session/mod.rs
  5. 24
      src/session/sidebar/selection.rs

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

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

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

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

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

Loading…
Cancel
Save