[gnome-tour/bilelmoussaoui/fixes] make PaginatorWidget implement Buildable



commit 86aa9043011d9520bb33355d6cca797c309f9013
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Mon Jan 3 17:21:01 2022 +0100

    make PaginatorWidget implement Buildable
    
    This allow us to simplify the changes on the UI part

 data/resources/ui/window.ui | 51 ++++++++++++++++++++++++++++++++++++++++++++-
 src/widgets/pages/image.rs  | 14 ++++++-------
 src/widgets/paginator.rs    | 20 ++++++++++++++++--
 src/widgets/window.rs       | 45 +++------------------------------------
 4 files changed, 78 insertions(+), 52 deletions(-)
---
diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui
index 64f52de..3359a23 100644
--- a/data/resources/ui/window.ui
+++ b/data/resources/ui/window.ui
@@ -4,7 +4,56 @@
     <property name="default-width">960</property>
     <property name="default-height">720</property>
     <property name="content">
-      <object class="PaginatorWidget" id="paginator" />
+      <object class="PaginatorWidget" id="paginator">
+        <child>
+          <object class="WelcomePageWidget" />
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/overview.svg</property>
+            <property name="head" translatable="yes">Get an Overview</property>
+            <property name="body" translatable="yes">Press the Super key to see open windows and 
apps.</property>
+          </object>
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/search.svg</property>
+            <property name="head" translatable="yes">Just Type to Search</property>
+            <property name="body" translatable="yes">Type in the overview to search. Launch apps, find 
things.</property>
+          </object>
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/workspaces.svg</property>
+            <property name="head" translatable="yes">Keep on Top with Workspaces</property>
+            <property name="body" translatable="yes">Easily organize windows with the workspaces 
view.</property>
+          </object>
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/blank.svg</property>
+            <property name="head" translatable="yes">Up/Down for the Overview</property>
+            <property name="body" translatable="yes">On a touchpad, use three-finger vertical swipes. Try 
it!</property>
+          </object>
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/blank.svg</property>
+            <property name="head" translatable="yes">Left/Right for Workspaces</property>
+            <property name="body" translatable="yes">On a touchpad, use three-finger horizontal swipes. Try 
it!</property>
+          </object>
+        </child>
+        <child>
+          <object class="ImagePageWidget">
+            <property name="resource-uri">/org/gnome/Tour/ready-to-go.svg</property>
+            <property name="head" translatable="yes">That's it. Have a nice day!</property>
+            <property name="body" translatable="yes">To get more advice and tips, see the Help 
app.</property>
+            <style>
+              <class name="last-page" />
+            </style>
+          </object>
+        </child>
+      </object>
     </property>
   </template>
 </interface>
diff --git a/src/widgets/pages/image.rs b/src/widgets/pages/image.rs
index 1be7856..c4e26a1 100644
--- a/src/widgets/pages/image.rs
+++ b/src/widgets/pages/image.rs
@@ -32,6 +32,11 @@ mod imp {
             layout_manager.set_orientation(gtk::Orientation::Vertical);
             obj.add_css_class("page");
 
+            obj.set_hexpand(true);
+            obj.set_vexpand(true);
+            obj.set_halign(gtk::Align::Fill);
+            obj.set_valign(gtk::Align::Fill);
+
             let container = gtk::Box::builder()
                 .orientation(gtk::Orientation::Vertical)
                 .spacing(12)
@@ -146,16 +151,11 @@ glib::wrapper! {
 
 impl ImagePageWidget {
     pub fn new(resource_uri: &str, head: String, body: String) -> Self {
-        let image_page = glib::Object::new::<Self>(&[
-            ("hexpand", &true),
-            ("vexpand", &true),
-            ("halign", &gtk::Align::Fill),
-            ("valign", &gtk::Align::Fill),
+        glib::Object::new::<Self>(&[
             ("resource-uri", &resource_uri),
             ("head", &head),
             ("body", &body),
         ])
-        .unwrap();
-        image_page
+        .unwrap()
     }
 }
diff --git a/src/widgets/paginator.rs b/src/widgets/paginator.rs
index 861d22f..00290e9 100644
--- a/src/widgets/paginator.rs
+++ b/src/widgets/paginator.rs
@@ -45,6 +45,7 @@ mod imp {
         const NAME: &'static str = "PaginatorWidget";
         type ParentType = gtk::Box;
         type Type = super::PaginatorWidget;
+        type Interfaces = (gtk::Buildable,);
 
         fn class_init(klass: &mut Self::Class) {
             Self::bind_template(klass);
@@ -73,12 +74,27 @@ mod imp {
     }
     impl WidgetImpl for PaginatorWidget {}
     impl BoxImpl for PaginatorWidget {}
+    impl BuildableImpl for PaginatorWidget {
+        fn add_child(
+            &self,
+            buildable: &Self::Type,
+            builder: &gtk::Builder,
+            child: &glib::Object,
+            type_: Option<&str>,
+        ) {
+            if !self.carousel.is_bound() {
+                self.parent_add_child(buildable, builder, child, type_);
+            } else {
+                buildable.add_page(child.clone().downcast::<gtk::Widget>().unwrap());
+            }
+        }
+    }
 }
 
 glib::wrapper! {
     pub struct PaginatorWidget(ObjectSubclass<imp::PaginatorWidget>)
-        @extends gtk::Widget, gtk::Box;
-
+        @extends gtk::Widget, gtk::Box,
+        @implements gtk::Buildable;
 }
 
 impl PaginatorWidget {
diff --git a/src/widgets/window.rs b/src/widgets/window.rs
index 1766ec8..fec600c 100644
--- a/src/widgets/window.rs
+++ b/src/widgets/window.rs
@@ -1,15 +1,14 @@
 use adw::prelude::*;
-use gettextrs::gettext;
 use gtk::subclass::prelude::*;
 use gtk::{gio, glib};
 
-use super::pages::{ImagePageWidget, WelcomePageWidget};
 use super::paginator::PaginatorWidget;
 use crate::Application;
 
 mod imp {
     use super::*;
     use crate::config;
+    use crate::widgets::pages::{ImagePageWidget, WelcomePageWidget};
     use adw::subclass::prelude::*;
 
     #[derive(Debug, Default, gtk::CompositeTemplate)]
@@ -26,6 +25,8 @@ mod imp {
         type ParentType = adw::ApplicationWindow;
 
         fn class_init(klass: &mut Self::Class) {
+            WelcomePageWidget::static_type();
+            ImagePageWidget::static_type();
             Self::bind_template(klass);
         }
 
@@ -42,46 +43,6 @@ mod imp {
             if config::PROFILE == "Devel" {
                 widget.add_css_class("devel");
             }
-
-            self.paginator.add_page(WelcomePageWidget::new());
-            self.paginator.add_page(ImagePageWidget::new(
-                "/org/gnome/Tour/overview.svg",
-                gettext("Get an Overview"),
-                gettext("Press the Super key to see open windows and apps."),
-            ));
-
-            self.paginator.add_page(ImagePageWidget::new(
-                "/org/gnome/Tour/search.svg",
-                gettext("Just Type to Search"),
-                gettext("Type in the overview to search. Launch apps, find things."),
-            ));
-
-            self.paginator.add_page(ImagePageWidget::new(
-                "/org/gnome/Tour/workspaces.svg",
-                gettext("Keep on Top with Workspaces"),
-                gettext("Easily organize windows with the workspaces view."),
-            ));
-
-            self.paginator.add_page(ImagePageWidget::new(
-                "/org/gnome/Tour/blank.svg",
-                gettext("Up/Down for the Overview"),
-                gettext("On a touchpad, use three-finger vertical swipes. Try it!"),
-            ));
-
-            self.paginator.add_page(ImagePageWidget::new(
-                "/org/gnome/Tour/blank.svg",
-                gettext("Left/Right for Workspaces"),
-                gettext("On a touchpad, use three-finger horizontal swipes. Try it!"),
-            ));
-
-            let last_page = ImagePageWidget::new(
-                "/org/gnome/Tour/ready-to-go.svg",
-                gettext("That's it. Have a nice day!"),
-                gettext("To get more advice and tips, see the Help app."),
-            );
-            last_page.add_css_class("last-page");
-            self.paginator.add_page(last_page);
-
             self.parent_constructed(widget);
         }
     }


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