forked from glen/dyna3
Move set point spec validation into Regulator
This commit is contained in:
parent
302d93638d
commit
bbd0835a8f
2 changed files with 16 additions and 11 deletions
|
@ -120,6 +120,19 @@ pub struct Regulator {
|
|||
pub set_point_spec: Signal<String>
|
||||
}
|
||||
|
||||
impl Regulator {
|
||||
pub fn try_specify_set_point(&self, spec: String) -> bool {
|
||||
match spec.parse::<f64>() {
|
||||
Err(_) if !spec.is_empty() => false,
|
||||
set_pt => {
|
||||
self.set_point.set(set_pt.ok());
|
||||
self.set_point_spec.set(spec);
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the velocity is expressed in uniform coordinates
|
||||
pub struct ElementMotion<'a> {
|
||||
pub key: ElementKey,
|
||||
|
|
|
@ -50,17 +50,9 @@ fn RegulatorInput(regulator: Regulator) -> View {
|
|||
},
|
||||
placeholder=regulator.measurement.with(|result| result.to_string()),
|
||||
bind:value=value,
|
||||
on:change=move |_| {
|
||||
let value_val = value.get_clone_untracked();
|
||||
match value_val.parse::<f64>() {
|
||||
Err(_) if !value_val.is_empty() => valid.set(false),
|
||||
set_pt => batch(|| {
|
||||
regulator.set_point.set(set_pt.ok());
|
||||
regulator.set_point_spec.set(value_val);
|
||||
valid.set(true);
|
||||
})
|
||||
};
|
||||
},
|
||||
on:change=move |_| valid.set(
|
||||
regulator.try_specify_set_point(value.get_clone_untracked())
|
||||
),
|
||||
on:keydown={
|
||||
move |event: KeyboardEvent| {
|
||||
match event.key().as_str() {
|
||||
|
|
Loading…
Add table
Reference in a new issue