You need to sign in or sign up before continuing.
Commit 86aa9043 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

make PaginatorWidget implement Buildable

This allow us to simplify the changes on the UI part
parent 609731d6
...@@ -4,7 +4,56 @@ ...@@ -4,7 +4,56 @@
<property name="default-width">960</property> <property name="default-width">960</property>
<property name="default-height">720</property> <property name="default-height">720</property>
<property name="content"> <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> </property>
</template> </template>
</interface> </interface>
...@@ -32,6 +32,11 @@ mod imp { ...@@ -32,6 +32,11 @@ mod imp {
layout_manager.set_orientation(gtk::Orientation::Vertical); layout_manager.set_orientation(gtk::Orientation::Vertical);
obj.add_css_class("page"); 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() let container = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.spacing(12) .spacing(12)
...@@ -146,16 +151,11 @@ glib::wrapper! { ...@@ -146,16 +151,11 @@ glib::wrapper! {
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 image_page = glib::Object::new::<Self>(&[ glib::Object::new::<Self>(&[
("hexpand", &true),
("vexpand", &true),
("halign", &gtk::Align::Fill),
("valign", &gtk::Align::Fill),
("resource-uri", &resource_uri), ("resource-uri", &resource_uri),
("head", &head), ("head", &head),
("body", &body), ("body", &body),
]) ])
.unwrap(); .unwrap()
image_page
} }
} }
...@@ -45,6 +45,7 @@ mod imp { ...@@ -45,6 +45,7 @@ mod imp {
const NAME: &'static str = "PaginatorWidget"; const NAME: &'static str = "PaginatorWidget";
type ParentType = gtk::Box; type ParentType = gtk::Box;
type Type = super::PaginatorWidget; type Type = super::PaginatorWidget;
type Interfaces = (gtk::Buildable,);
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass); Self::bind_template(klass);
...@@ -73,12 +74,27 @@ mod imp { ...@@ -73,12 +74,27 @@ mod imp {
} }
impl WidgetImpl for PaginatorWidget {} impl WidgetImpl for PaginatorWidget {}
impl BoxImpl 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! { glib::wrapper! {
pub struct PaginatorWidget(ObjectSubclass<imp::PaginatorWidget>) pub struct PaginatorWidget(ObjectSubclass<imp::PaginatorWidget>)
@extends gtk::Widget, gtk::Box; @extends gtk::Widget, gtk::Box,
@implements gtk::Buildable;
} }
impl PaginatorWidget { impl PaginatorWidget {
......
use adw::prelude::*; use adw::prelude::*;
use gettextrs::gettext;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{gio, glib}; use gtk::{gio, glib};
use super::pages::{ImagePageWidget, WelcomePageWidget};
use super::paginator::PaginatorWidget; use super::paginator::PaginatorWidget;
use crate::Application; use crate::Application;
mod imp { mod imp {
use super::*; use super::*;
use crate::config; use crate::config;
use crate::widgets::pages::{ImagePageWidget, WelcomePageWidget};
use adw::subclass::prelude::*; use adw::subclass::prelude::*;
#[derive(Debug, Default, gtk::CompositeTemplate)] #[derive(Debug, Default, gtk::CompositeTemplate)]
...@@ -26,6 +25,8 @@ mod imp { ...@@ -26,6 +25,8 @@ mod imp {
type ParentType = adw::ApplicationWindow; type ParentType = adw::ApplicationWindow;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
WelcomePageWidget::static_type();
ImagePageWidget::static_type();
Self::bind_template(klass); Self::bind_template(klass);
} }
...@@ -42,46 +43,6 @@ mod imp { ...@@ -42,46 +43,6 @@ mod imp {
if config::PROFILE == "Devel" { if config::PROFILE == "Devel" {
widget.add_css_class("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); self.parent_constructed(widget);
} }
} }
......
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