use crate::prelude::*;
pub struct ProgressBar;
impl View for ProgressBar {
fn element(&self) -> Option<&'static str> {
Some("progressbar")
}
fn accessibility(&self, _cx: &mut AccessContext, node: &mut AccessNode) {
node.set_min_numeric_value(0.0);
node.set_max_numeric_value(1.0);
}
}
impl ProgressBar {
pub fn new<L>(cx: &mut Context, signal: L) -> Handle<Self>
where
L: SignalGet<f32> + SignalMap<f32>,
{
Self::horizontal(cx, signal)
}
pub fn horizontal<L>(cx: &mut Context, signal: L) -> Handle<Self>
where
L: SignalGet<f32> + SignalMap<f32>,
{
Self.build(cx, |cx| {
let progress = signal.map(|v| Units::Percentage(v * 100.0));
Element::new(cx).width(progress).class("progressbar-bar");
})
.role(Role::ProgressIndicator)
.numeric_value(signal.map(|val| *val as f64))
.orientation(Orientation::Horizontal)
}
pub fn vertical<L>(cx: &mut Context, signal: L) -> Handle<Self>
where
L: SignalGet<f32> + SignalMap<f32>,
{
Self.build(cx, |cx| {
let progress = signal.map(|v| Units::Percentage(v * 100.0));
Element::new(cx).top(Stretch(1.0)).height(progress).class("progressbar-bar");
})
.role(Role::ProgressIndicator)
.numeric_value(signal.map(|val| *val as f64))
.orientation(Orientation::Vertical)
}
}