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

Correctly switch between pages

parent 5863db56
...@@ -65,7 +65,6 @@ impl Application { ...@@ -65,7 +65,6 @@ impl Application {
window.previous_page(); window.previous_page();
}), }),
); );
self.app.set_accels_for_action("app.quit", &["<primary>q"]); self.app.set_accels_for_action("app.quit", &["<primary>q"]);
} }
......
...@@ -3,16 +3,18 @@ use gtk::prelude::*; ...@@ -3,16 +3,18 @@ use gtk::prelude::*;
pub struct HeaderBar { pub struct HeaderBar {
pub widget: gtk::HeaderBar, pub widget: gtk::HeaderBar,
container: gtk::Stack, container: gtk::Stack,
next_btn: gtk::Button,
} }
impl HeaderBar { impl HeaderBar {
pub fn new() -> Self { pub fn new() -> Self {
let widget = gtk::HeaderBar::new(); let widget = gtk::HeaderBar::new();
let container = gtk::Stack::new(); let container = gtk::Stack::new();
let next_btn = gtk::Button::new();
widget.set_show_title_buttons(true); widget.set_show_title_buttons(true);
let headerbar = Self { widget, container }; let headerbar = Self { widget, container, next_btn };
headerbar.init(); headerbar.init();
headerbar headerbar
} }
...@@ -22,6 +24,19 @@ impl HeaderBar { ...@@ -22,6 +24,19 @@ impl HeaderBar {
self.widget.set_show_title_buttons(false); 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) { fn init(&self) {
self.container.set_hexpand(true); self.container.set_hexpand(true);
self.container.set_transition_type(gtk::StackTransitionType::SlideLeftRight); self.container.set_transition_type(gtk::StackTransitionType::SlideLeftRight);
...@@ -37,16 +52,15 @@ impl HeaderBar { ...@@ -37,16 +52,15 @@ impl HeaderBar {
previous_btn.set_hexpand(true); previous_btn.set_hexpand(true);
previous_btn.set_property_width_request(60); previous_btn.set_property_width_request(60);
let next_btn = gtk::Button::new(); self.next_btn.add(&gtk::Label::new(Some("Next")));
next_btn.add(&gtk::Label::new(Some("Next"))); self.next_btn.get_style_context().add_class("suggested-action");
next_btn.get_style_context().add_class("suggested-action"); self.next_btn.set_action_name(Some("app.next-page"));
next_btn.set_action_name(Some("app.next-page")); self.next_btn.set_halign(gtk::Align::End);
next_btn.set_halign(gtk::Align::End); self.next_btn.set_hexpand(true);
next_btn.set_hexpand(true); self.next_btn.set_property_width_request(60);
next_btn.set_property_width_request(60);
pages_container.add(&previous_btn); pages_container.add(&previous_btn);
pages_container.add(&next_btn); pages_container.add(&self.next_btn);
self.container.add_named(&pages_container, "pages"); self.container.add_named(&pages_container, "pages");
self.widget.set_custom_title(Some(&self.container)); self.widget.set_custom_title(Some(&self.container));
......
...@@ -53,6 +53,7 @@ impl WelcomePageWidget { ...@@ -53,6 +53,7 @@ impl WelcomePageWidget {
actions_container.add(&skip_tour_btn); actions_container.add(&skip_tour_btn);
actions_container.add(&start_tour_btn); actions_container.add(&start_tour_btn);
actions_container.set_focus_child(Some(&start_tour_btn));
self.widget.add(&actions_container); self.widget.add(&actions_container);
} }
......
...@@ -23,6 +23,14 @@ impl PaginatorWidget { ...@@ -23,6 +23,14 @@ impl PaginatorWidget {
paginator 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) { pub fn next(&self) {
let next_page = self.current_page.borrow().clone() + 1; let next_page = self.current_page.borrow().clone() + 1;
self.go_to(next_page); self.go_to(next_page);
......
...@@ -35,12 +35,32 @@ impl Window { ...@@ -35,12 +35,32 @@ impl Window {
self.headerbar.start_tour(); self.headerbar.start_tour();
} }
fn end_tour(&self) {
self.container.set_visible_child_name("welcome");
self.headerbar.end_tour();
}
pub fn next_page(&self) { pub fn next_page(&self) {
self.paginator.next(); 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) { 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) { 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