From 2ee04ebfc314449d45cb5314010f0f0dc0f20879 Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Fri, 7 Jun 2024 15:12:01 -0500 Subject: [PATCH] small rename --- src/controls/button.rs | 2 +- src/controls/checkbox.rs | 2 +- src/controls/group.rs | 4 ++-- src/controls/heading.rs | 2 +- src/controls/hidden.rs | 2 +- src/controls/mod.rs | 8 +++---- src/controls/output.rs | 2 +- src/controls/radio_buttons.rs | 2 +- src/controls/select.rs | 2 +- src/controls/slider.rs | 2 +- src/controls/stepper.rs | 2 +- src/controls/submit.rs | 2 +- src/controls/text_area.rs | 2 +- src/controls/text_input.rs | 2 +- src/form_builder.rs | 14 +++++------ src/styles/grid_form.rs | 44 +++++++++++++++++++++-------------- src/styles/mod.rs | 29 +++++++++++------------ 17 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/controls/button.rs b/src/controls/button.rs index 1b72b24..69f4562 100644 --- a/src/controls/button.rs +++ b/src/controls/button.rs @@ -15,7 +15,7 @@ pub struct ButtonData { impl VanityControlData for ButtonData { fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, _value_getter: Option>, ) -> View { diff --git a/src/controls/checkbox.rs b/src/controls/checkbox.rs index 67bd179..03f76f4 100644 --- a/src/controls/checkbox.rs +++ b/src/controls/checkbox.rs @@ -13,7 +13,7 @@ impl ControlData for CheckboxData { type ReturnType = bool; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/group.rs b/src/controls/group.rs index 1832f41..ccdcf7d 100644 --- a/src/controls/group.rs +++ b/src/controls/group.rs @@ -12,11 +12,11 @@ impl FormBuilder { self.validations.push(validation); } - let render_fn = move |fs: &FS, fd: RwSignal| { + let render_fn = move |fs: &mut FS, fd: RwSignal| { let (views, validation_cbs): (Vec<_>, Vec<_>) = group_builder .render_fns .into_iter() - .map(|r_fn| r_fn(&fs, fd)) + .map(|r_fn| r_fn(fs, fd)) .unzip(); let view = fs.group(views.collect_view(), group_builder.styles); diff --git a/src/controls/heading.rs b/src/controls/heading.rs index c9d05a9..72b040b 100644 --- a/src/controls/heading.rs +++ b/src/controls/heading.rs @@ -9,7 +9,7 @@ pub struct HeadingData { impl VanityControlData for HeadingData { fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, _value_getter: Option>, ) -> View { diff --git a/src/controls/hidden.rs b/src/controls/hidden.rs index 88bcafc..d5f7f77 100644 --- a/src/controls/hidden.rs +++ b/src/controls/hidden.rs @@ -10,7 +10,7 @@ impl ControlData for HiddenData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, _value_setter: Box, diff --git a/src/controls/mod.rs b/src/controls/mod.rs index cacf492..d331160 100644 --- a/src/controls/mod.rs +++ b/src/controls/mod.rs @@ -23,7 +23,7 @@ pub trait UnparseFn: Fn(FDT) -> CR + 'static {} pub trait FieldGetter: Fn(FD) -> FDT + 'static {} pub trait FieldSetter: Fn(&mut FD, FDT) + 'static {} pub trait RenderFn: - FnOnce(&FS, RwSignal) -> (View, Option>) + 'static + FnOnce(&mut FS, RwSignal) -> (View, Option>) + 'static { } @@ -35,7 +35,7 @@ impl UnparseFn for F where F: Fn(FDT) -> CR + 'static {} impl FieldGetter for F where F: Fn(FD) -> FDT + 'static {} impl FieldSetter for F where F: Fn(&mut FD, FDT) + 'static {} impl RenderFn for F where - F: FnOnce(&FS, RwSignal) -> (View, Option>) + 'static + F: FnOnce(&mut FS, RwSignal) -> (View, Option>) + 'static { } @@ -43,7 +43,7 @@ impl RenderFn for F where pub trait VanityControlData: 'static { /// Builds the control, returning the [`View`] that was built. fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Option>, ) -> View; @@ -56,7 +56,7 @@ pub trait ControlData: 'static { /// Builds the control, returning the [`View`] that was built. fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/output.rs b/src/controls/output.rs index d13500c..4a67410 100644 --- a/src/controls/output.rs +++ b/src/controls/output.rs @@ -8,7 +8,7 @@ pub struct OutputData; impl VanityControlData for OutputData { fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Option>, ) -> View { diff --git a/src/controls/radio_buttons.rs b/src/controls/radio_buttons.rs index 6fa8961..8f68fd5 100644 --- a/src/controls/radio_buttons.rs +++ b/src/controls/radio_buttons.rs @@ -14,7 +14,7 @@ impl ControlData for RadioButtonsData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/select.rs b/src/controls/select.rs index 8d06488..cd16628 100644 --- a/src/controls/select.rs +++ b/src/controls/select.rs @@ -16,7 +16,7 @@ impl ControlData for SelectData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/slider.rs b/src/controls/slider.rs index 3cd5b5b..d9991eb 100644 --- a/src/controls/slider.rs +++ b/src/controls/slider.rs @@ -28,7 +28,7 @@ impl ControlData for SliderData { type ReturnType = i32; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/stepper.rs b/src/controls/stepper.rs index f874d6f..4633f94 100644 --- a/src/controls/stepper.rs +++ b/src/controls/stepper.rs @@ -18,7 +18,7 @@ impl ControlData for StepperData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/submit.rs b/src/controls/submit.rs index 35ee7bc..244dfe5 100644 --- a/src/controls/submit.rs +++ b/src/controls/submit.rs @@ -10,7 +10,7 @@ pub struct SubmitData { impl VanityControlData for SubmitData { fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, _value_getter: Option>, ) -> View { diff --git a/src/controls/text_area.rs b/src/controls/text_area.rs index ea1214f..de08662 100644 --- a/src/controls/text_area.rs +++ b/src/controls/text_area.rs @@ -12,7 +12,7 @@ impl ControlData for TextAreaData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/controls/text_input.rs b/src/controls/text_input.rs index dd62869..8e1ff8b 100644 --- a/src/controls/text_input.rs +++ b/src/controls/text_input.rs @@ -28,7 +28,7 @@ impl ControlData for TextInputData { type ReturnType = String; fn build_control( - fs: &FS, + fs: &mut FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, diff --git a/src/form_builder.rs b/src/form_builder.rs index 10b952c..746aec1 100644 --- a/src/form_builder.rs +++ b/src/form_builder.rs @@ -90,7 +90,7 @@ impl FormBuilder { getter, } = vanity_control.build(); - let render_fn = move |fs: &FS, fd: RwSignal| { + let render_fn = move |fs: &mut FS, fd: RwSignal| { let value_getter = getter.map(|getter| (move || getter(fd.get())).into_signal()); let view = VanityControlData::build_control(fs, render_data, value_getter); (view, None) @@ -120,7 +120,7 @@ impl FormBuilder { self.validations.push(validation_fn.clone()); } - let render_fn = move |fs: &FS, fd: RwSignal| { + let render_fn = move |fs: &mut FS, fd: RwSignal| { let (view, cb) = Self::build_control_view( fd, fs, @@ -139,7 +139,7 @@ impl FormBuilder { fn build_control_view( fd: RwSignal, - fs: &FS, + fs: &mut FS, getter: Rc>, setter: Rc>, unparse_fn: Box::ReturnType, FDT>>, @@ -230,7 +230,7 @@ impl FormBuilder { } pub(crate) fn build_action_form( - self, + mut self, action: Action>>, ) -> Form where @@ -241,7 +241,7 @@ impl FormBuilder { let (views, validation_cbs): (Vec<_>, Vec<_>) = self .render_fns .into_iter() - .map(|r_fn| r_fn(&self.fs, self.fd)) + .map(|r_fn| r_fn(&mut self.fs, self.fd)) .unzip(); let elements = self.fs.form_frame(views.into_view(), self.styles); @@ -271,11 +271,11 @@ impl FormBuilder { } } - pub(crate) fn build_plain_form(self, url: String) -> Form { + pub(crate) fn build_plain_form(mut self, url: String) -> Form { let (views, validation_cbs): (Vec<_>, Vec<_>) = self .render_fns .into_iter() - .map(|r_fn| r_fn(&self.fs, self.fd)) + .map(|r_fn| r_fn(&mut self.fs, self.fd)) .unzip(); let elements = self.fs.form_frame(views.into_view(), self.styles); diff --git a/src/styles/grid_form.rs b/src/styles/grid_form.rs index 3cefd8c..a16f679 100644 --- a/src/styles/grid_form.rs +++ b/src/styles/grid_form.rs @@ -13,21 +13,23 @@ pub enum GridFormStylingAttributes { } #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct GridFormStyle; +pub struct GridFormStyle { + count: u32, +} impl FormStyle for GridFormStyle { type StylingAttributes = GridFormStylingAttributes; - fn form_frame(&self, children: View, _styles: Vec) -> View { + fn form_frame(&mut self, children: View, _styles: Vec) -> View { view! {
{children}
}.into_view() } - fn heading(&self, control: ControlRenderData) -> View { + fn heading(&mut self, control: ControlRenderData) -> View { view! {

{&control.data.title}

}.into_view() } fn text_input( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -40,12 +42,13 @@ impl FormStyle for GridFormStyle { GridFormStylingAttributes::Width(w) => width = w, } } + self.count += 1; - view! { + let inner = view! {
{move || validation_state.get().err()}
@@ -64,11 +67,18 @@ impl FormStyle for GridFormStyle { />
} + .into_view(); + + view! { + + {inner.clone()} + + } .into_view() } fn select( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -111,7 +121,7 @@ impl FormStyle for GridFormStyle { .into_view() } - fn submit(&self, control: ControlRenderData) -> View { + fn submit(&mut self, control: ControlRenderData) -> View { view! { } @@ -119,7 +129,7 @@ impl FormStyle for GridFormStyle { } fn text_area( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -144,12 +154,12 @@ impl FormStyle for GridFormStyle { .into_view() } - fn custom_component(&self, view: View) -> View { + fn custom_component(&mut self, view: View) -> View { view } fn hidden( - &self, + &mut self, _control: ControlRenderData, value_getter: Signal, ) -> View { @@ -157,7 +167,7 @@ impl FormStyle for GridFormStyle { } fn radio_buttons( - &self, + &mut self, control: ControlRenderData, value_getter: Signal< ::ReturnType, @@ -224,7 +234,7 @@ impl FormStyle for GridFormStyle { } fn checkbox( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -261,7 +271,7 @@ impl FormStyle for GridFormStyle { } fn stepper( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box< @@ -302,7 +312,7 @@ impl FormStyle for GridFormStyle { } fn output( - &self, + &mut self, _control: ControlRenderData, value_getter: Option>, ) -> View { @@ -310,7 +320,7 @@ impl FormStyle for GridFormStyle { } fn slider( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -380,7 +390,7 @@ impl FormStyle for GridFormStyle { } // TODO: change this and form frame to use ControlRenderData - fn group(&self, inner: View, styles: Vec) -> View { + fn group(&mut self, inner: View, styles: Vec) -> View { let mut width = 12; for style in styles { match style { diff --git a/src/styles/mod.rs b/src/styles/mod.rs index 0b0e574..fffe2e3 100644 --- a/src/styles/mod.rs +++ b/src/styles/mod.rs @@ -22,36 +22,36 @@ pub trait FormStyle: Default + 'static { /// /// Do NOT wrap it in an actual `form` element; any /// wrapping should be done with `div` or similar elements. - fn form_frame(&self, children: View, styles: Vec) -> View; - fn heading(&self, control: ControlRenderData) -> View; + fn form_frame(&mut self, children: View, style: Vec) -> View; + fn heading(&mut self, control: ControlRenderData) -> View; fn hidden( - &self, + &mut self, control: ControlRenderData, value_getter: Signal, ) -> View; fn text_input( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, validation_state: Signal>, ) -> View; fn text_area( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, validation_state: Signal>, ) -> View; fn radio_buttons( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, validation_state: Signal>, ) -> View; fn select( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, @@ -59,33 +59,32 @@ pub trait FormStyle: Default + 'static { ) -> View; fn button(&self, control: ControlRenderData>) -> View; fn checkbox( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, ) -> View; fn stepper( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, validation_state: Signal>, ) -> View; fn output( - &self, + &mut self, control: ControlRenderData, value_getter: Option>, ) -> View; fn slider( - &self, + &mut self, control: ControlRenderData, value_getter: Signal<::ReturnType>, value_setter: Box::ReturnType)>, validation_state: Signal>, ) -> View; - fn submit(&self, control: ControlRenderData) -> View; + fn submit(&mut self, control: ControlRenderData) -> View; // TODO: test custom component - fn custom_component(&self, view: View) -> View; - // TODO: test group - fn group(&self, inner: View, styles: Vec) -> View; + fn custom_component(&mut self, view: View) -> View; + fn group(&mut self, inner: View, style: Vec) -> View; }