implemented some other controls

This commit is contained in:
2024-06-05 16:15:07 -05:00
parent 63153d76a0
commit ead75f050a
15 changed files with 679 additions and 38 deletions
+78
View File
@@ -0,0 +1,78 @@
use std::ops::RangeInclusive;
use leptos::{Signal, View};
use super::{ControlBuilder, ControlData, ControlRenderData};
use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SliderData {
pub(crate) name: String,
pub(crate) label: Option<String>,
pub(crate) min: i32,
pub(crate) max: i32,
}
impl Default for SliderData {
fn default() -> Self {
SliderData {
name: String::new(),
label: None,
min: 0,
max: 1,
}
}
}
impl ControlData for SliderData {
type ReturnType = i32;
fn build_control<FS: FormStyle>(
fs: &FS,
control: ControlRenderData<FS, Self>,
value_getter: Signal<Self::ReturnType>,
value_setter: Box<dyn Fn(Self::ReturnType)>,
validation_state: Signal<Result<(), String>>,
) -> View {
fs.slider(control, value_getter, value_setter, validation_state)
}
}
impl<FD: FormToolData, FS: FormStyle> FormBuilder<FD, FS> {
pub fn slider<FDT: Clone + PartialEq + 'static>(
self,
builder: impl Fn(
ControlBuilder<FD, FS, SliderData, FDT>,
) -> ControlBuilder<FD, FS, SliderData, FDT>,
) -> Self {
self.new_control(builder)
}
}
impl<FD: FormToolData, FS: FormStyle, FDT> ControlBuilder<FD, FS, SliderData, FDT> {
pub fn named(mut self, control_name: impl ToString) -> Self {
self.data.name = control_name.to_string();
self
}
pub fn labeled(mut self, label: impl ToString) -> Self {
self.data.label = Some(label.to_string());
self
}
pub fn min(mut self, min: i32) -> Self {
self.data.min = min;
self
}
pub fn max(mut self, max: i32) -> Self {
self.data.max = max;
self
}
pub fn range(mut self, range: RangeInclusive<i32>) -> Self {
self.data.min = *range.start();
self.data.max = *range.end();
self
}
}