[gnome-tour/bilelmoussaoui/headerbar] replace next with start on the first page



commit 80e64abe9f9d1a1548fc8fafa25592b83e3f60c8
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Thu Feb 11 13:17:37 2021 +0100

    replace next with start on the first page

 src/widgets/paginator.rs | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/src/widgets/paginator.rs b/src/widgets/paginator.rs
index 12226a5..1f2611d 100644
--- a/src/widgets/paginator.rs
+++ b/src/widgets/paginator.rs
@@ -14,6 +14,7 @@ pub struct PaginatorWidget {
     pages: RefCell<Vec<gtk::Widget>>,
     current_page: RefCell<u32>,
     next_btn: gtk::Button,
+    start_btn: gtk::Button,
     finish_btn: gtk::Button,
     close_btn: gtk::Button,
     previous_btn: gtk::Button,
@@ -28,6 +29,7 @@ impl PaginatorWidget {
             carousel: libhandy::Carousel::new(),
             carousel_dots: libhandy::CarouselIndicatorDots::new(),
             headerbar: libhandy::HeaderBar::new(),
+            start_btn: gtk::Button::with_label(&gettext("_Start")),
             next_btn: gtk::Button::with_label(&gettext("_Next")),
             finish_btn: gtk::Button::with_label(&gettext("_Close")),
             close_btn: gtk::Button::with_label(&gettext("_Close")),
@@ -73,15 +75,22 @@ impl PaginatorWidget {
         let forelast_page = n_pages - 2.0;
         let last_page = n_pages - 1.0;
 
-        let (opacity_finish, opacity_previous) = if (0.0 <= position) && (position < 1.0) {
-            (0.0, position)
-        } else if (0.0 <= position) && (position <= forelast_page) {
-            (0.0, 1.0)
-        } else if (forelast_page < position) && (position <= last_page) {
-            (position - forelast_page, 1.0)
-        } else {
-            panic!("Position of the carousel is outside the allowed range");
-        };
+        let (opacity_finish, opacity_previous, opacity_start, opacity_next) =
+            if (0.0 <= position) && (position < 1.0) {
+                (0.0, position, 1.0, position)
+            } else if (0.0 <= position) && (position <= forelast_page) {
+                (0.0, 1.0, 1f64 - position, 1.0)
+            } else if (forelast_page < position) && (position <= last_page) {
+                (position - forelast_page, 1.0, 0.0, 1.0)
+            } else {
+                panic!("Position of the carousel is outside the allowed range");
+            };
+
+        self.start_btn.set_opacity(opacity_start);
+        self.start_btn.set_visible(opacity_start > 0_f64);
+
+        self.next_btn.set_opacity(opacity_next);
+        self.next_btn.set_visible(opacity_next > 0_f64);
 
         self.finish_btn.set_opacity(opacity_finish);
         self.finish_btn.set_visible(opacity_finish > 0_f64);
@@ -103,13 +112,18 @@ impl PaginatorWidget {
             .connect_property_position_notify(clone!(@weak p => move |_| {
                 p.update_position();
             }));
+        self.start_btn
+            .get_style_context()
+            .add_class("suggested-action");
+        self.start_btn.set_use_underline(true);
+        self.start_btn.set_action_name(Some("app.start-tour"));
+        self.start_btn.show();
 
         self.next_btn
             .get_style_context()
             .add_class("suggested-action");
         self.next_btn.set_use_underline(true);
         self.next_btn.set_action_name(Some("app.next-page"));
-        self.next_btn.show();
 
         self.close_btn.set_use_underline(true);
         self.close_btn.set_action_name(Some("app.quit"));
@@ -134,15 +148,21 @@ impl PaginatorWidget {
         next_overlay.add_overlay(&self.finish_btn);
         next_overlay.show();
 
+        let start_overlay = gtk::Overlay::new();
+        start_overlay.add(&self.start_btn);
+        start_overlay.add_overlay(&next_overlay);
+        start_overlay.show();
+
         let btn_size_group = gtk::SizeGroup::new(gtk::SizeGroupMode::Horizontal);
         btn_size_group.add_widget(&self.previous_btn);
         btn_size_group.add_widget(&self.close_btn);
-        btn_size_group.add_widget(&self.next_btn);
+        btn_size_group.add_widget(&next_overlay);
+        btn_size_group.add_widget(&start_overlay);
         btn_size_group.add_widget(&self.finish_btn);
 
         self.headerbar.set_custom_title(Some(&self.carousel_dots));
         self.headerbar.pack_start(&previous_overlay);
-        self.headerbar.pack_end(&next_overlay);
+        self.headerbar.pack_end(&start_overlay);
         self.headerbar.set_show_close_button(false);
         self.headerbar.show();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]