pelican_ui 2.0.6

Standard UI tools and components built off Pelican UI of the RAMP stack.
Documentation
use roost_ui::events::OnEvent;
use roost_ui::drawable::Align;
use roost_ui::{Context, Component};
use roost_ui::layouts::Column;

use crate::interactions;
use crate::components::{Text, TextSize, ExpandableText, TextStyle, Circle, Rectangle};
use crate::plugin::PelicanUI;

/// ## Slider
///
/// A UI component that allows users to select a value along a continuous range. 
///
/// <img src="https://raw.githubusercontent.com/ramp-stack/pelican_ui_std/main/src/examples/slider.png"
///      alt="Secondary Icons Example"
///      width="350">
///
/// ### Example
/// ```rust
/// let slider = Slider::new(
///     ctx,
///     50.0,
///     Some("Volume"),
///     None,
///     |ctx: &mut Context, percentage: f32| {
///         println!("Slider released at %{percentage}");
///     }
/// );
/// ```
#[derive(Debug, Component)]
pub struct Slider(Column, Option<Text>, Option<ExpandableText>, interactions::Slider); // last f32 = value 0.0..1.0
impl OnEvent for Slider {}
impl Slider {
    pub fn new(
        ctx: &mut Context,
        start: f32,
        label: Option<&str>,
        description: Option<&str>,
        on_change: impl FnMut(&mut Context, f32) + 'static,
    ) -> Self {
        let colors = ctx.get::<PelicanUI>().get().0.theme().colors;
        let background = Rectangle::new(colors.outline.primary, 3.0, None);
        let foreground = Rectangle::new(colors.brand, 3.0, None);
        let handle = Circle::new(18.0, colors.brand, false);
        Slider(Column::start(8.0),
            label.map(|l| Text::new(ctx, l, TextSize::H5, TextStyle::Heading, Align::Left, None)),
            description.map(|t| ExpandableText::new(ctx, t, TextSize::Md, TextStyle::Primary, Align::Left, None)),
            interactions::Slider::new(ctx, start, background, foreground, handle, on_change),
        )
    }
}