use crate::density;
use crate::theme::{self, surface, FontScale};
use iced::widget::{container, progress_bar, Container};
use iced::{Background, Border, Element, Length};
const PROGRESS_GIRTH_BASE: f32 = 4.0;
pub fn progress_line<'a, Message: 'a>(fraction: f32, scale: FontScale) -> Element<'a, Message> {
progress_bar(0.0..=1.0, fraction.clamp(0.0, 1.0))
.girth(scale.apply(PROGRESS_GIRTH_BASE))
.length(Length::Fill)
.style(|_t: &iced::Theme| progress_line_style())
.into()
}
pub fn progress_line_style() -> progress_bar::Style {
progress_bar::Style {
background: Background::Color(surface::row()),
bar: Background::Color(theme::text()),
border: Border { radius: (PROGRESS_GIRTH_BASE / 2.0).into(), ..Border::default() },
}
}
pub fn popover_card<'a, Message: 'a>(content: impl Into<Element<'a, Message>>) -> Container<'a, Message> {
container(content).style(|_t: &iced::Theme| container::Style {
background: Some(Background::Color(surface::sidebar())),
border: Border {
radius: density::card_radius().into(),
width: 1.0,
color: surface::card_border(),
},
..container::Style::default()
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_progress_line_never_fills_with_the_accent() {
let style = progress_line_style();
let accent = crate::color::to_iced(theme::active().accent);
assert_ne!(style.bar, Background::Color(accent));
assert_eq!(style.bar, Background::Color(theme::text()));
assert_ne!(style.bar, style.background, "a full bar has to look full");
}
}