summaryrefslogtreecommitdiffstats
path: root/examples/tour.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tour.rs')
-rw-r--r--examples/tour.rs67
1 files changed, 45 insertions, 22 deletions
diff --git a/examples/tour.rs b/examples/tour.rs
index 91b75296..b0ee4d96 100644
--- a/examples/tour.rs
+++ b/examples/tour.rs
@@ -62,8 +62,9 @@ impl Sandbox for Tour {
if steps.has_previous() {
controls = controls.push(
- secondary_button(back_button, "Back")
- .on_press(Message::BackPressed),
+ button(back_button, "Back")
+ .on_press(Message::BackPressed)
+ .style(style::Button::Secondary),
);
}
@@ -71,8 +72,9 @@ impl Sandbox for Tour {
if steps.can_continue() {
controls = controls.push(
- primary_button(next_button, "Next")
- .on_press(Message::NextPressed),
+ button(next_button, "Next")
+ .on_press(Message::NextPressed)
+ .style(style::Button::Primary),
);
}
@@ -401,6 +403,7 @@ impl<'a> Step {
))
.push(
Text::new(&value.to_string())
+ .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center),
)
}
@@ -447,6 +450,7 @@ impl<'a> Step {
))
.push(
Text::new(&format!("{} px", spacing))
+ .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center),
);
@@ -561,6 +565,7 @@ impl<'a> Step {
))
.push(
Text::new(&format!("Width: {} px", width.to_string()))
+ .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center),
)
}
@@ -580,6 +585,7 @@ impl<'a> Step {
.push(Column::new().height(Length::Units(4096)))
.push(
Text::new("You are halfway there!")
+ .width(Length::Fill)
.size(30)
.horizontal_alignment(HorizontalAlignment::Center),
)
@@ -587,6 +593,7 @@ impl<'a> Step {
.push(ferris(300))
.push(
Text::new("You made it!")
+ .width(Length::Fill)
.size(50)
.horizontal_alignment(HorizontalAlignment::Center),
)
@@ -629,6 +636,7 @@ impl<'a> Step {
} else {
value
})
+ .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center),
)
}
@@ -692,29 +700,12 @@ fn button<'a, Message>(
) -> Button<'a, Message> {
Button::new(
state,
- Text::new(label)
- .color(Color::WHITE)
- .horizontal_alignment(HorizontalAlignment::Center),
+ Text::new(label).horizontal_alignment(HorizontalAlignment::Center),
)
.padding(12)
- .border_radius(12)
.min_width(100)
}
-fn primary_button<'a, Message>(
- state: &'a mut button::State,
- label: &str,
-) -> Button<'a, Message> {
- button(state, label).background(Color::from_rgb(0.11, 0.42, 0.87))
-}
-
-fn secondary_button<'a, Message>(
- state: &'a mut button::State,
- label: &str,
-) -> Button<'a, Message> {
- button(state, label).background(Color::from_rgb(0.4, 0.4, 0.4))
-}
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Language {
Rust,
@@ -757,6 +748,38 @@ pub enum Layout {
Column,
}
+mod style {
+ use iced::{button, Background, Color, Vector};
+
+ pub enum Button {
+ Primary,
+ Secondary,
+ }
+
+ impl button::StyleSheet for Button {
+ fn active(&self) -> button::Style {
+ button::Style {
+ background: Some(Background::Color(match self {
+ Button::Primary => Color::from_rgb(0.11, 0.42, 0.87),
+ Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5),
+ })),
+ border_radius: 12,
+ shadow_offset: Vector::new(1.0, 1.0),
+ text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE),
+ ..button::Style::default()
+ }
+ }
+
+ fn hovered(&self) -> button::Style {
+ button::Style {
+ text_color: Color::WHITE,
+ shadow_offset: Vector::new(1.0, 2.0),
+ ..self.active()
+ }
+ }
+ }
+}
+
// This should be gracefully handled by Iced in the future. Probably using our
// own proc macro, or maybe the whole process is streamlined by `wasm-pack` at
// some point.