Skip to content

Commit

Permalink
Remove themer use from gradient example 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 12, 2024
1 parent b721fd9 commit 98621aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
20 changes: 10 additions & 10 deletions examples/gradient/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::application;
use iced::widget::{
checkbox, column, container, horizontal_space, row, slider, text, themer,
checkbox, column, container, horizontal_space, row, slider, text,
};
use iced::{gradient, window};
use iced::{
Expand Down Expand Up @@ -70,16 +70,16 @@ impl Sandbox for Gradient {
transparent,
} = *self;

let gradient = gradient::Linear::new(angle)
.add_stop(0.0, start)
.add_stop(1.0, end);
let gradient_box = container(horizontal_space())
.style(move |_theme, _status| {
let gradient = gradient::Linear::new(angle)
.add_stop(0.0, start)
.add_stop(1.0, end);

let gradient_box = themer(
gradient,
container(horizontal_space())
.width(Length::Fill)
.height(Length::Fill),
);
gradient.into()
})
.width(Length::Fill)
.height(Length::Fill);

let angle_picker = row![
text("Angle").width(64),
Expand Down
24 changes: 21 additions & 3 deletions widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,24 @@ impl Appearance {
}
}

impl From<Color> for Appearance {
fn from(color: Color) -> Self {
Self::default().with_background(color)
}
}

impl From<Gradient> for Appearance {
fn from(gradient: Gradient) -> Self {
Self::default().with_background(gradient)
}
}

impl From<gradient::Linear> for Appearance {
fn from(gradient: gradient::Linear) -> Self {
Self::default().with_background(gradient)
}
}

/// The possible status of a [`Container`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
Expand Down Expand Up @@ -571,19 +589,19 @@ impl DefaultStyle for Appearance {

impl DefaultStyle for Color {
fn default_style(&self, _status: Status) -> Appearance {
Appearance::default().with_background(*self)
Appearance::from(*self)
}
}

impl DefaultStyle for Gradient {
fn default_style(&self, _status: Status) -> Appearance {
Appearance::default().with_background(*self)
Appearance::from(*self)
}
}

impl DefaultStyle for gradient::Linear {
fn default_style(&self, _status: Status) -> Appearance {
Appearance::default().with_background(*self)
Appearance::from(*self)
}
}

Expand Down

0 comments on commit 98621aa

Please sign in to comment.