[gnome-tour/bilelmoussaoui/fixes: 8/11] subclass ImagePageWidget
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tour/bilelmoussaoui/fixes: 8/11] subclass ImagePageWidget
- Date: Fri, 31 Dec 2021 19:02:15 +0000 (UTC)
commit 11723557f78bb54eda0bca46906bee6c622a96ad
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Fri Dec 31 19:07:41 2021 +0100
subclass ImagePageWidget
src/widgets/pages/image.rs | 54 ++++++++++++++++++++++-------
src/widgets/paginator.rs | 4 +--
src/widgets/window.rs | 86 +++++++++++++++++-----------------------------
3 files changed, 75 insertions(+), 69 deletions(-)
---
diff --git a/src/widgets/pages/image.rs b/src/widgets/pages/image.rs
index 57ac0df..5d70c9f 100644
--- a/src/widgets/pages/image.rs
+++ b/src/widgets/pages/image.rs
@@ -1,26 +1,54 @@
+use gtk::glib;
use gtk::prelude::*;
+use gtk::subclass::prelude::*;
-pub struct ImagePageWidget {
- pub widget: gtk::Box,
+mod imp {
+ use super::*;
+
+ #[derive(Debug, Default)]
+ pub struct ImagePageWidget;
+
+ #[glib::object_subclass]
+ impl ObjectSubclass for ImagePageWidget {
+ const NAME: &'static str = "ImagePageWidget";
+ type ParentType = gtk::Box;
+ type Type = super::ImagePageWidget;
+ }
+
+ impl ObjectImpl for ImagePageWidget {
+ fn constructed(&self, obj: &Self::Type) {
+ let layout_manager = obj
+ .layout_manager()
+ .map(|l| l.downcast::<gtk::BoxLayout>().unwrap())
+ .unwrap();
+ layout_manager.set_orientation(gtk::Orientation::Vertical);
+ obj.add_css_class("page");
+ self.parent_constructed(obj);
+ }
+ }
+ impl WidgetImpl for ImagePageWidget {}
+ impl BoxImpl for ImagePageWidget {}
+}
+
+glib::wrapper! {
+ pub struct ImagePageWidget(ObjectSubclass<imp::ImagePageWidget>)
+ @extends gtk::Widget, gtk::Box;
}
impl ImagePageWidget {
pub fn new(resource_uri: &str, head: String, body: String) -> Self {
- let widget = gtk::Box::new(gtk::Orientation::Vertical, 0);
-
- let image_page = Self { widget };
-
+ let image_page = glib::Object::new::<Self>(&[
+ ("hexpand", &true),
+ ("vexpand", &true),
+ ("halign", >k::Align::Fill),
+ ("valign", >k::Align::Fill),
+ ])
+ .unwrap();
image_page.init(resource_uri, head, body);
image_page
}
fn init(&self, resource_uri: &str, head: String, body: String) {
- self.widget.set_hexpand(true);
- self.widget.set_vexpand(true);
- self.widget.add_css_class("page");
- self.widget.set_halign(gtk::Align::Fill);
- self.widget.set_valign(gtk::Align::Fill);
-
let container = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.spacing(12)
@@ -61,6 +89,6 @@ impl ImagePageWidget {
.build();
container.append(&body_label);
- self.widget.append(&clamp);
+ self.append(&clamp);
}
}
diff --git a/src/widgets/paginator.rs b/src/widgets/paginator.rs
index 57ba15d..0e0865e 100644
--- a/src/widgets/paginator.rs
+++ b/src/widgets/paginator.rs
@@ -150,11 +150,11 @@ impl PaginatorWidget {
Some(())
}
- pub fn add_page(&self, page: gtk::Widget) {
+ pub fn add_page(&self, page: impl IsA<gtk::Widget>) {
let imp = self.imp();
let page_nr = imp.pages.borrow().len();
imp.carousel.insert(&page, page_nr as i32);
- imp.pages.borrow_mut().push(page);
+ imp.pages.borrow_mut().push(page.upcast());
self.update_position();
}
diff --git a/src/widgets/window.rs b/src/widgets/window.rs
index 71eb1c4..b6c2540 100644
--- a/src/widgets/window.rs
+++ b/src/widgets/window.rs
@@ -40,66 +40,44 @@ impl Window {
if PROFILE == "Devel" {
self.widget.add_css_class("devel");
}
- self.paginator
- .add_page(WelcomePageWidget::new().widget.upcast::<gtk::Widget>());
- 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."),
- )
- .widget
- .upcast::<gtk::Widget>(),
- );
-
- 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."),
- )
- .widget
- .upcast::<gtk::Widget>(),
- );
-
- 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."),
- )
- .widget
- .upcast::<gtk::Widget>(),
- );
-
- 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!"),
- )
- .widget
- .upcast::<gtk::Widget>(),
- );
-
- 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!"),
- )
- .widget
- .upcast::<gtk::Widget>(),
- );
+ self.paginator.add_page(WelcomePageWidget::new().widget);
+ 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.widget.add_css_class("last-page");
- self.paginator
- .add_page(last_page.widget.upcast::<gtk::Widget>());
+ last_page.add_css_class("last-page");
+ self.paginator.add_page(last_page);
self.widget.set_content(Some(&self.paginator));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]