[gnome-tour: 1/2] Use the builder-pattern for various widgets
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tour: 1/2] Use the builder-pattern for various widgets
- Date: Thu, 1 Oct 2020 18:05:34 +0000 (UTC)
commit dbb6cbe032eaf1c36d671051d182388fa7ba391a
Author: Julian Hofer <julianhofer gnome org>
Date: Wed Sep 30 19:30:27 2020 +0200
Use the builder-pattern for various widgets
src/widgets/pages/image.rs | 43 +++++++++++++++++++++----------------
src/widgets/pages/welcome.rs | 51 ++++++++++++++++++++++++++------------------
2 files changed, 55 insertions(+), 39 deletions(-)
---
diff --git a/src/widgets/pages/image.rs b/src/widgets/pages/image.rs
index d0dd24a..85c6511 100644
--- a/src/widgets/pages/image.rs
+++ b/src/widgets/pages/image.rs
@@ -19,34 +19,41 @@ impl ImagePageWidget {
self.widget.set_halign(gtk::Align::Fill);
self.widget.set_valign(gtk::Align::Fill);
- let container = gtk::Box::new(gtk::Orientation::Vertical, 12);
- container.set_halign(gtk::Align::Center);
- container.set_valign(gtk::Align::Center);
- container.set_vexpand(true);
- container.set_margin_bottom(48);
- container.set_margin_top(12);
- container.set_margin_start(12);
- container.set_margin_end(12);
+ let container = gtk::BoxBuilder::new()
+ .orientation(gtk::Orientation::Vertical)
+ .spacing(12)
+ .halign(gtk::Align::Center)
+ .valign(gtk::Align::Center)
+ .vexpand(true)
+ .margin_bottom(48)
+ .margin_top(12)
+ .margin_start(12)
+ .margin_end(12)
+ .build();
let image = gtk::Image::from_resource(&resource_uri);
image.set_valign(gtk::Align::Start);
image.show();
container.add(&image);
- let head_label = gtk::Label::new(Some(&head));
- head_label.set_justify(gtk::Justification::Center);
- head_label.set_valign(gtk::Align::Center);
- head_label.set_margin_top(36);
+ let head_label = gtk::LabelBuilder::new()
+ .label(&head)
+ .justify(gtk::Justification::Center)
+ .valign(gtk::Align::Center)
+ .margin_top(36)
+ .build();
head_label.get_style_context().add_class("page-title");
head_label.show();
container.add(&head_label);
- let body_label = gtk::Label::new(Some(&body));
- body_label.set_lines(2);
- body_label.set_property_wrap(true);
- body_label.set_justify(gtk::Justification::Center);
- body_label.set_valign(gtk::Align::Center);
- body_label.set_margin_top(12);
+ let body_label = gtk::LabelBuilder::new()
+ .label(&body)
+ .lines(2)
+ .wrap(true)
+ .justify(gtk::Justification::Center)
+ .valign(gtk::Align::Center)
+ .margin_top(12)
+ .build();
body_label.get_style_context().add_class("page-body");
body_label.show();
container.add(&body_label);
diff --git a/src/widgets/pages/welcome.rs b/src/widgets/pages/welcome.rs
index add7d8e..c2fc45f 100644
--- a/src/widgets/pages/welcome.rs
+++ b/src/widgets/pages/welcome.rs
@@ -60,13 +60,15 @@ impl WelcomePageWidget {
}
fn init(&self) {
- let container = gtk::Box::new(gtk::Orientation::Vertical, 0);
-
- container.set_property_expand(true);
- container.set_valign(gtk::Align::Center);
- container.set_halign(gtk::Align::Center);
- container.set_margin_top(24);
- container.set_margin_bottom(24);
+ let container = gtk::BoxBuilder::new()
+ .orientation(gtk::Orientation::Vertical)
+ .spacing(0)
+ .expand(true)
+ .valign(gtk::Align::Center)
+ .halign(gtk::Align::Center)
+ .margin_top(24)
+ .margin_bottom(24)
+ .build();
#[cfg(not(feature = "video"))]
let header = {
@@ -154,23 +156,30 @@ impl WelcomePageWidget {
text.show();
container.add(&text);
- let actions_container = gtk::Box::new(gtk::Orientation::Horizontal, 12);
- actions_container.set_halign(gtk::Align::Center);
- actions_container.set_margin_top(36);
-
- let skip_tour_btn = gtk::Button::with_label(&gettext("_No Thanks"));
- skip_tour_btn.set_property_height_request(40);
- skip_tour_btn.set_property_width_request(180);
- skip_tour_btn.set_use_underline(true);
- skip_tour_btn.set_action_name(Some("app.skip-tour"));
+ let actions_container = gtk::BoxBuilder::new()
+ .orientation(gtk::Orientation::Horizontal)
+ .spacing(12)
+ .halign(gtk::Align::Center)
+ .margin_top(36)
+ .build();
+
+ let skip_tour_btn = gtk::ButtonBuilder::new()
+ .label(&gettext("_No Thanks"))
+ .height_request(40)
+ .width_request(180)
+ .use_underline(true)
+ .action_name("app.skip-tour")
+ .build();
skip_tour_btn.show();
actions_container.add(&skip_tour_btn);
- let start_tour_btn = gtk::Button::with_label(&gettext("_Start Tour"));
- start_tour_btn.set_property_height_request(40);
- start_tour_btn.set_property_width_request(180);
- start_tour_btn.set_use_underline(true);
- start_tour_btn.set_action_name(Some("app.start-tour"));
+ let start_tour_btn = gtk::ButtonBuilder::new()
+ .label(&gettext("_Start Tour"))
+ .height_request(40)
+ .width_request(180)
+ .use_underline(true)
+ .action_name("app.start-tour")
+ .build();
start_tour_btn.get_style_context().add_class("suggested-action");
start_tour_btn.show();
actions_container.add(&start_tour_btn);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]