Commit 11723557 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

subclass ImagePageWidget

parent aa06f0f6
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", &gtk::Align::Fill),
("valign", &gtk::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);
}
}
......@@ -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();
}
......
......@@ -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));
}
......
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