Commit 11723557 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

subclass ImagePageWidget

parent aa06f0f6
use gtk::glib;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::prelude::*;
pub struct ImagePageWidget { mod imp {
pub widget: gtk::Box, 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 { impl ImagePageWidget {
pub fn new(resource_uri: &str, head: String, body: String) -> Self { pub fn new(resource_uri: &str, head: String, body: String) -> Self {
let widget = gtk::Box::new(gtk::Orientation::Vertical, 0); let image_page = glib::Object::new::<Self>(&[
("hexpand", &true),
let image_page = Self { widget }; ("vexpand", &true),
("halign", &gtk::Align::Fill),
("valign", &gtk::Align::Fill),
])
.unwrap();
image_page.init(resource_uri, head, body); image_page.init(resource_uri, head, body);
image_page image_page
} }
fn init(&self, resource_uri: &str, head: String, body: String) { 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() let container = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.spacing(12) .spacing(12)
...@@ -61,6 +89,6 @@ impl ImagePageWidget { ...@@ -61,6 +89,6 @@ impl ImagePageWidget {
.build(); .build();
container.append(&body_label); container.append(&body_label);
self.widget.append(&clamp); self.append(&clamp);
} }
} }
...@@ -150,11 +150,11 @@ impl PaginatorWidget { ...@@ -150,11 +150,11 @@ impl PaginatorWidget {
Some(()) Some(())
} }
pub fn add_page(&self, page: gtk::Widget) { pub fn add_page(&self, page: impl IsA<gtk::Widget>) {
let imp = self.imp(); let imp = self.imp();
let page_nr = imp.pages.borrow().len(); let page_nr = imp.pages.borrow().len();
imp.carousel.insert(&page, page_nr as i32); imp.carousel.insert(&page, page_nr as i32);
imp.pages.borrow_mut().push(page); imp.pages.borrow_mut().push(page.upcast());
self.update_position(); self.update_position();
} }
......
...@@ -40,66 +40,44 @@ impl Window { ...@@ -40,66 +40,44 @@ impl Window {
if PROFILE == "Devel" { if PROFILE == "Devel" {
self.widget.add_css_class("devel"); self.widget.add_css_class("devel");
} }
self.paginator self.paginator.add_page(WelcomePageWidget::new().widget);
.add_page(WelcomePageWidget::new().widget.upcast::<gtk::Widget>()); self.paginator.add_page(ImagePageWidget::new(
self.paginator.add_page(
ImagePageWidget::new(
"/org/gnome/Tour/overview.svg", "/org/gnome/Tour/overview.svg",
gettext("Get an Overview"), gettext("Get an Overview"),
gettext("Press the Super key to see open windows and apps."), gettext("Press the Super key to see open windows and apps."),
) ));
.widget
.upcast::<gtk::Widget>(),
);
self.paginator.add_page( self.paginator.add_page(ImagePageWidget::new(
ImagePageWidget::new(
"/org/gnome/Tour/search.svg", "/org/gnome/Tour/search.svg",
gettext("Just Type to Search"), gettext("Just Type to Search"),
gettext("Type in the overview to search. Launch apps, find things."), gettext("Type in the overview to search. Launch apps, find things."),
) ));
.widget
.upcast::<gtk::Widget>(),
);
self.paginator.add_page( self.paginator.add_page(ImagePageWidget::new(
ImagePageWidget::new(
"/org/gnome/Tour/workspaces.svg", "/org/gnome/Tour/workspaces.svg",
gettext("Keep on Top with Workspaces"), gettext("Keep on Top with Workspaces"),
gettext("Easily organize windows with the workspaces view."), gettext("Easily organize windows with the workspaces view."),
) ));
.widget
.upcast::<gtk::Widget>(),
);
self.paginator.add_page( self.paginator.add_page(ImagePageWidget::new(
ImagePageWidget::new(
"/org/gnome/Tour/blank.svg", "/org/gnome/Tour/blank.svg",
gettext("Up/Down for the Overview"), gettext("Up/Down for the Overview"),
gettext("On a touchpad, use three-finger vertical swipes. Try it!"), gettext("On a touchpad, use three-finger vertical swipes. Try it!"),
) ));
.widget
.upcast::<gtk::Widget>(),
);
self.paginator.add_page( self.paginator.add_page(ImagePageWidget::new(
ImagePageWidget::new(
"/org/gnome/Tour/blank.svg", "/org/gnome/Tour/blank.svg",
gettext("Left/Right for Workspaces"), gettext("Left/Right for Workspaces"),
gettext("On a touchpad, use three-finger horizontal swipes. Try it!"), gettext("On a touchpad, use three-finger horizontal swipes. Try it!"),
) ));
.widget
.upcast::<gtk::Widget>(),
);
let last_page = ImagePageWidget::new( let last_page = ImagePageWidget::new(
"/org/gnome/Tour/ready-to-go.svg", "/org/gnome/Tour/ready-to-go.svg",
gettext("That's it. Have a nice day!"), gettext("That's it. Have a nice day!"),
gettext("To get more advice and tips, see the Help app."), gettext("To get more advice and tips, see the Help app."),
); );
last_page.widget.add_css_class("last-page"); last_page.add_css_class("last-page");
self.paginator self.paginator.add_page(last_page);
.add_page(last_page.widget.upcast::<gtk::Widget>());
self.widget.set_content(Some(&self.paginator)); self.widget.set_content(Some(&self.paginator));
} }
......
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