Commit 101fd925 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Correctly switch between pages

parent 5863db56
......@@ -65,7 +65,6 @@ impl Application {
window.previous_page();
}),
);
self.app.set_accels_for_action("app.quit", &["<primary>q"]);
}
......
......@@ -3,16 +3,18 @@ use gtk::prelude::*;
pub struct HeaderBar {
pub widget: gtk::HeaderBar,
container: gtk::Stack,
next_btn: gtk::Button,
}
impl HeaderBar {
pub fn new() -> Self {
let widget = gtk::HeaderBar::new();
let container = gtk::Stack::new();
let next_btn = gtk::Button::new();
widget.set_show_title_buttons(true);
let headerbar = Self { widget, container };
let headerbar = Self { widget, container, next_btn };
headerbar.init();
headerbar
}
......@@ -22,6 +24,19 @@ impl HeaderBar {
self.widget.set_show_title_buttons(false);
}
pub fn set_page_nr(&self, page_nr: i32, total_pages: i32) {
if page_nr == total_pages {
self.next_btn.set_label("Done");
} else {
self.next_btn.set_label("Next");
}
}
pub fn end_tour(&self) {
self.container.set_visible_child_name("welcome");
self.widget.set_show_title_buttons(true);
}
fn init(&self) {
self.container.set_hexpand(true);
self.container.set_transition_type(gtk::StackTransitionType::SlideLeftRight);
......@@ -37,16 +52,15 @@ impl HeaderBar {
previous_btn.set_hexpand(true);
previous_btn.set_property_width_request(60);
let next_btn = gtk::Button::new();
next_btn.add(&gtk::Label::new(Some("Next")));
next_btn.get_style_context().add_class("suggested-action");
next_btn.set_action_name(Some("app.next-page"));
next_btn.set_halign(gtk::Align::End);
next_btn.set_hexpand(true);
next_btn.set_property_width_request(60);
self.next_btn.add(&gtk::Label::new(Some("Next")));
self.next_btn.get_style_context().add_class("suggested-action");
self.next_btn.set_action_name(Some("app.next-page"));
self.next_btn.set_halign(gtk::Align::End);
self.next_btn.set_hexpand(true);
self.next_btn.set_property_width_request(60);
pages_container.add(&previous_btn);
pages_container.add(&next_btn);
pages_container.add(&self.next_btn);
self.container.add_named(&pages_container, "pages");
self.widget.set_custom_title(Some(&self.container));
......
......@@ -53,6 +53,7 @@ impl WelcomePageWidget {
actions_container.add(&skip_tour_btn);
actions_container.add(&start_tour_btn);
actions_container.set_focus_child(Some(&start_tour_btn));
self.widget.add(&actions_container);
}
......
......@@ -23,6 +23,14 @@ impl PaginatorWidget {
paginator
}
pub fn get_total_pages(&self) -> i32 {
self.pages.len().try_into().unwrap_or(1)
}
pub fn get_current_page(&self) -> i32 {
self.current_page.borrow().clone()
}
pub fn next(&self) {
let next_page = self.current_page.borrow().clone() + 1;
self.go_to(next_page);
......
......@@ -35,12 +35,32 @@ impl Window {
self.headerbar.start_tour();
}
fn end_tour(&self) {
self.container.set_visible_child_name("welcome");
self.headerbar.end_tour();
}
pub fn next_page(&self) {
let total_pages = self.paginator.get_total_pages();
let current_page = self.paginator.get_current_page();
self.headerbar.set_page_nr(current_page + 1, total_pages);
if current_page == total_pages {
self.widget.destroy();
} else {
self.paginator.next();
}
}
pub fn previous_page(&self) {
self.paginator.previous();
let total_pages = self.paginator.get_total_pages();
let current_page = self.paginator.get_current_page();
self.headerbar.set_page_nr(current_page - 1, total_pages);
match current_page {
1 => self.end_tour(),
_ => self.paginator.previous(),
}
}
fn init(&mut self) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment