-
In previous versions of iced, setting the color of a progress bar was easily done, by calling |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think this is a known behaviour: https://github.com/iced-rs/rfcs/blob/master/text/0006-theming.md
|
Beta Was this translation helpful? Give feedback.
-
Ok so as of the recent changes, which are in 0.5, because a https://docs.rs/iced_style/latest/iced_style/theme/enum.ProgressBar.html#variant.Custom Something like this is possible (adapted from the 0.4 and lesser mod based styles, and not guaranteed to compile as is, just an example): mod style {
use super::*;
use iced::progress_bar::StyleSheet;
use iced_style::progress_bar;
pub struct ProgressBar(pub(super) [f32; 3]);
impl StyleSheet for ProgressBar {
type Style = iced_style::Theme;
fn appearance(&self, _style: &Self::Style) -> progress_bar::Appearance {
progress_bar::Appearance {
background: Background::Color(Color::from_rgb(0.6, 0.6, 0.6)),
bar: Background::Color(Color::from(self.0)),
border_radius: 10.0,
}
}
}
impl From<ProgressBar> for iced_style::theme::ProgressBar {
fn from(bar: ProgressBar) -> Self {
iced::theme::ProgressBar::Custom(Box::new(bar))
}
}
} So I think i can mark this as answered |
Beta Was this translation helpful? Give feedback.
Ok so as of the recent changes, which are in 0.5, because a
Box<dyn
is now there, instead of a function pointer, we can change colors like this without using a wholesale theme, which is great!https://docs.rs/iced_style/latest/iced_style/theme/enum.ProgressBar.html#variant.Custom
Something like this is possible (adapted from the 0.4 and lesser mod based styles, and not guaranteed to compile as is, just an example):