Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: Ported NavigationView to rust #558

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Library/demos/Navigation View/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::workbench;
use adw::prelude::*;

use crate::glib::clone;
use gtk::glib;

pub fn main() {
let nav_view: adw::NavigationView = workbench::builder().object("nav_view").unwrap();
let nav_pageone: adw::NavigationPage = workbench::builder().object("nav_pageone").unwrap();
let next_button: gtk::Button = workbench::builder().object("next_button").unwrap();
let previous_button: gtk::Button = workbench::builder().object("previous_button").unwrap();
let nav_pagetwo: adw::NavigationPage = workbench::builder().object("nav_pagetwo").unwrap();
let nav_pagethree: adw::NavigationPage = workbench::builder().object("nav_pagethree").unwrap();
let nav_pagefour: adw::NavigationPage = workbench::builder().object("nav_pagefour").unwrap();
let title: gtk::Label = workbench::builder().object("title").unwrap();

next_button.connect_clicked(
clone!(@weak nav_view, @weak nav_pageone, @weak nav_pagefour => move |_| {
let current_page = nav_view.visible_page().unwrap();
if current_page == nav_pageone {
nav_view.push(&nav_pagetwo);
} else if current_page == nav_pagetwo {
nav_view.push(&nav_pagethree);
} else if current_page == nav_pagethree {
nav_view.push(&nav_pagefour);
}
saadulkh marked this conversation as resolved.
Show resolved Hide resolved
}),
);

previous_button.connect_clicked(clone!(@weak nav_view => move |_| nav_view.pop();));

nav_view.connect_visible_page_notify(move |nav_view| {
let current_page = nav_view.visible_page().unwrap();
previous_button.set_sensitive(current_page != nav_pageone);
next_button.set_sensitive(current_page != nav_pagefour);
title.set_label(&current_page.title());
});
}