use std::ops::RangeInclusive;
use egui::Ui;
use crate::Icons;
use crate::components::IconComponent;
use crate::numeric_stepper;
pub struct Stepper<'a> {
value: &'a mut f32,
range: RangeInclusive<f32>,
step: f32,
width: f32,
decimals: usize,
suffix: &'a str,
enabled: bool,
}
impl<'a> Stepper<'a> {
pub fn new(value: &'a mut f32, range: RangeInclusive<f32>, step: f32) -> Self {
Self {
value,
range,
step,
width: 112.0,
decimals: 0,
suffix: "",
enabled: true,
}
}
pub fn width(mut self, width: f32) -> Self {
self.width = width;
self
}
pub fn decimals(mut self, decimals: usize) -> Self {
self.decimals = decimals;
self
}
pub fn suffix(mut self, suffix: &'a str) -> Self {
self.suffix = suffix;
self
}
pub fn enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
}
impl IconComponent for Stepper<'_> {
type Output = bool;
fn show(self, ui: &mut Ui, icons: &mut Icons) -> bool {
ui.add_enabled_ui(self.enabled, |ui| {
let decimals = self.decimals;
let suffix = self.suffix;
numeric_stepper(ui, icons, self.value, self.range, self.step, self.width, |value| {
format!("{value:.decimals$}{suffix}")
})
})
.inner
}
}