2026-05-26 22:54:19 +02:00
|
|
|
use iced::widget::{self, Row, container, text};
|
2026-05-13 00:24:05 +02:00
|
|
|
use iced::{Alignment, Color, Element, Length};
|
|
|
|
|
|
|
|
|
|
// Assuming your Item struct or type implements Display or has a text representation
|
|
|
|
|
pub fn color_bar<Message: 'static>(
|
|
|
|
|
maybe_items: Option<Vec<(String, u16, Color)>>,
|
|
|
|
|
bar_height: u32,
|
|
|
|
|
) -> Element<'static, Message> {
|
2026-05-26 22:54:19 +02:00
|
|
|
|
2026-05-13 00:24:05 +02:00
|
|
|
if let Some(items) = maybe_items {
|
2026-05-26 22:54:19 +02:00
|
|
|
let mut c_b = Row::new().height(Length::Fill);
|
2026-05-13 00:24:05 +02:00
|
|
|
for (bar_text, bar_fill, bar_color) in items {
|
|
|
|
|
c_b = c_b.push(
|
|
|
|
|
container(text(bar_text).color(Color::BLACK).size(iced::Pixels(14.0)))
|
|
|
|
|
.height(Length::Fill)
|
|
|
|
|
.width(Length::FillPortion(bar_fill))
|
|
|
|
|
.style(move |_| container::background(bar_color))
|
|
|
|
|
.align_x(Alignment::Center)
|
2026-05-23 14:56:21 +02:00
|
|
|
.align_y(Alignment::Center)
|
|
|
|
|
.padding(2),
|
2026-05-13 00:24:05 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-05-26 22:54:19 +02:00
|
|
|
container(c_b.spacing(2))
|
2026-05-23 14:56:21 +02:00
|
|
|
.style(container::rounded_box)
|
|
|
|
|
.padding(3)
|
2026-05-26 22:54:19 +02:00
|
|
|
.height(bar_height)
|
2026-05-23 14:56:21 +02:00
|
|
|
.into()
|
2026-05-26 22:54:19 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
widget::container(widget::space())
|
|
|
|
|
.height(bar_height)
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 00:24:05 +02:00
|
|
|
}
|