[gnome-tour/wip/exalm/ui-cleanups: 2/4] paginator: Clean up headerbar buttons
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tour/wip/exalm/ui-cleanups: 2/4] paginator: Clean up headerbar buttons
- Date: Mon, 13 Jul 2020 21:24:18 +0000 (UTC)
commit 5ee706c7e7a13f68126df4fa30e7e268c5a3318a
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Jul 14 01:53:16 2020 +0500
paginator: Clean up headerbar buttons
Remove redundant properties, stop setting width request. Add a size group
and put both buttons into it so that they always have the same width.
Separate next and close buttons, do a stick-to-finger crossfade on last
page.
src/widgets/paginator.rs | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/src/widgets/paginator.rs b/src/widgets/paginator.rs
index 49fd724..dbdaff5 100644
--- a/src/widgets/paginator.rs
+++ b/src/widgets/paginator.rs
@@ -13,7 +13,10 @@ pub struct PaginatorWidget {
headerbar: libhandy::HeaderBar,
pages: RefCell<Vec<Box<dyn Pageable>>>,
current_page: RefCell<u32>,
+ btn_size_group: gtk::SizeGroup,
next_btn: gtk::Button,
+ close_btn: gtk::Button,
+ next_overlay: gtk::Overlay,
}
impl PaginatorWidget {
@@ -24,7 +27,10 @@ impl PaginatorWidget {
widget,
carousel: libhandy::Carousel::new(),
headerbar: libhandy::HeaderBar::new(),
+ btn_size_group: gtk::SizeGroup::new(gtk::SizeGroupMode::Horizontal),
next_btn: gtk::Button::new(),
+ close_btn: gtk::Button::new(),
+ next_overlay: gtk::Overlay::new(),
pages: RefCell::new(Vec::new()),
current_page: RefCell::new(0),
});
@@ -60,35 +66,44 @@ impl PaginatorWidget {
self.carousel.set_property_expand(true);
self.carousel.set_animation_duration(300);
- self.carousel.connect_page_changed(clone!(@weak p => move |carousel, page_nr| {
+ self.carousel.connect_property_position_notify(clone!(@weak p => move |carousel| {
+ let n_pages = carousel.get_n_pages() as f64;
+ let position = carousel.get_position();
+ let opacity = (position - n_pages + 2_f64).max(0_f64);
+
+ p.close_btn.set_opacity(opacity);
+ p.close_btn.set_visible(opacity > 0_f64);
+ }));
+
+ self.carousel.connect_page_changed(clone!(@weak p => move |_carousel, page_nr| {
let pages = &p.pages.borrow();
let page = pages.get(page_nr as usize).unwrap();
p.headerbar.set_title(Some(&page.get_title()));
- if page_nr == carousel.get_n_pages() - 1 {
- p.next_btn.set_label(&gettext("Close"));
- } else {
- p.next_btn.set_label(&gettext("Next"));
- }
p.current_page.replace(page_nr);
}));
let previous_btn = gtk::Button::new();
previous_btn.add(>k::Label::new(Some("Previous")));
- previous_btn.set_halign(gtk::Align::Start);
previous_btn.set_action_name(Some("app.previous-page"));
- previous_btn.set_hexpand(true);
- previous_btn.set_property_width_request(60);
+
+ self.btn_size_group.add_widget(&previous_btn);
+ self.btn_size_group.add_widget(&self.next_btn);
+ self.btn_size_group.add_widget(&self.close_btn);
self.next_btn.add(>k::Label::new(Some(&gettext("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);
+
+ self.close_btn.add(>k::Label::new(Some(&gettext("Close"))));
+ self.close_btn.get_style_context().add_class("suggested-action");
+ self.close_btn.set_action_name(Some("app.next-page"));
+
+ self.next_overlay.add(&self.next_btn);
+ self.next_overlay.add_overlay(&self.close_btn);
self.headerbar.pack_start(&previous_btn);
- self.headerbar.pack_end(&self.next_btn);
+ self.headerbar.pack_end(&self.next_overlay);
self.headerbar.set_show_close_button(false);
self.widget.add(&self.headerbar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]