summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 15:36:32 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 15:36:32 +0700
commitd61cb58d92b6fcd520f665deb093f3747ffd5e5c (patch)
treed65fbd23f2ccbb46b18d2e3bbf214d321f6e980c /examples
parentedea093350e1b576e2b7db50c525e7fa5c3bea9f (diff)
downloadiced-d61cb58d92b6fcd520f665deb093f3747ffd5e5c.tar.gz
iced-d61cb58d92b6fcd520f665deb093f3747ffd5e5c.tar.bz2
iced-d61cb58d92b6fcd520f665deb093f3747ffd5e5c.zip
Wire up `container` styling to `iced_native`
Diffstat (limited to 'examples')
-rw-r--r--examples/game_of_life/src/main.rs2
-rw-r--r--examples/pane_grid/src/main.rs34
-rw-r--r--examples/scrollable/src/main.rs4
-rw-r--r--examples/scrollable/src/style.rs4
-rw-r--r--examples/styling/src/main.rs6
-rw-r--r--examples/tooltip/src/main.rs2
6 files changed, 31 insertions, 21 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 50112618..ee425f44 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -150,7 +150,7 @@ impl Application for GameOfLife {
Container::new(content)
.width(Length::Fill)
.height(Length::Fill)
- .style(style::Container)
+ .style(&style::Container)
.into()
}
}
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs
index 69872bad..844b604d 100644
--- a/examples/pane_grid/src/main.rs
+++ b/examples/pane_grid/src/main.rs
@@ -177,7 +177,11 @@ impl Application for Example {
let title_bar = pane_grid::TitleBar::new(title)
.controls(pane.controls.view(id, total_panes, pane.is_pinned))
.padding(10)
- .style(style::TitleBar { is_focused });
+ .style(if is_focused {
+ &style::TitleBar::Focused
+ } else {
+ &style::TitleBar::Active
+ });
pane_grid::Content::new(pane.content.view(
id,
@@ -185,7 +189,11 @@ impl Application for Example {
pane.is_pinned,
))
.title_bar(title_bar)
- .style(style::Pane { is_focused })
+ .style(if is_focused {
+ &style::Pane::Focused
+ } else {
+ &style::Pane::Active
+ })
})
.width(Length::Fill)
.height(Length::Fill)
@@ -387,14 +395,16 @@ mod style {
0xC4 as f32 / 255.0,
);
- pub struct TitleBar {
- pub is_focused: bool,
+ pub enum TitleBar {
+ Active,
+ Focused,
}
impl container::StyleSheet for TitleBar {
fn style(&self) -> container::Style {
- let pane = Pane {
- is_focused: self.is_focused,
+ let pane = match self {
+ Self::Active => Pane::Active,
+ Self::Focused => Pane::Focused,
}
.style();
@@ -406,8 +416,9 @@ mod style {
}
}
- pub struct Pane {
- pub is_focused: bool,
+ pub enum Pane {
+ Active,
+ Focused,
}
impl container::StyleSheet for Pane {
@@ -415,10 +426,9 @@ mod style {
container::Style {
background: Some(Background::Color(SURFACE)),
border_width: 2.0,
- border_color: if self.is_focused {
- Color::BLACK
- } else {
- Color::from_rgb(0.7, 0.7, 0.7)
+ border_color: match self {
+ Self::Active => Color::from_rgb(0.7, 0.7, 0.7),
+ Self::Focused => Color::BLACK,
},
..Default::default()
}
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 272f0ce2..bc20d428 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -164,7 +164,7 @@ impl Sandbox for ScrollableDemo {
Container::new(scrollable)
.width(Length::Fill)
.height(Length::Fill)
- .style(*theme),
+ .style(theme.clone().into()),
)
.push(ProgressBar::new(
0.0..=1.0,
@@ -190,7 +190,7 @@ impl Sandbox for ScrollableDemo {
.height(Length::Fill)
.center_x()
.center_y()
- .style(self.theme)
+ .style(self.theme.into())
.into()
}
}
diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs
index d955f52d..66f3b9d3 100644
--- a/examples/scrollable/src/style.rs
+++ b/examples/scrollable/src/style.rs
@@ -16,11 +16,11 @@ impl Default for Theme {
}
}
-impl From<Theme> for Box<dyn container::StyleSheet> {
+impl From<Theme> for &'static dyn container::StyleSheet {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => dark::Container.into(),
+ Theme::Dark => &dark::Container,
}
}
}
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 1746d7b4..d8254dd9 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -149,7 +149,7 @@ impl Sandbox for Styling {
.height(Length::Fill)
.center_x()
.center_y()
- .style(self.theme)
+ .style(self.theme.into())
.into()
}
}
@@ -176,11 +176,11 @@ mod style {
}
}
- impl From<Theme> for Box<dyn container::StyleSheet> {
+ impl From<Theme> for &'static dyn container::StyleSheet {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => dark::Container.into(),
+ Theme::Dark => &dark::Container,
}
}
}
diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs
index cfeaf6a6..cb2f81df 100644
--- a/examples/tooltip/src/main.rs
+++ b/examples/tooltip/src/main.rs
@@ -115,7 +115,7 @@ fn tooltip<'a>(
)
.gap(5)
.padding(10)
- .style(style::Tooltip)
+ .style(&style::Tooltip)
.into()
}