Files
kira-installer/src/kira_color_bar.rs
T

37 lines
1.2 KiB
Rust

use iced::widget::{self, Row, container, text};
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> {
if let Some(items) = maybe_items {
let mut c_b = Row::new().height(Length::Fill);
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)
.align_y(Alignment::Center)
.padding(2),
);
}
container(c_b.spacing(2))
.style(container::rounded_box)
.padding(3)
.height(bar_height)
.into()
}
else {
widget::container(widget::space())
.height(bar_height)
.width(Length::Fill)
.into()
}
}