pub struct Form;Expand description
A dynamic form component with multiple field types.
Form composes text inputs, checkboxes, and select fields into a
single navigable component. It manages internal focus between fields
and collects values on submission.
§Navigation
Tab— Focus next fieldBackTab(Shift+Tab) — Focus previous fieldCtrl+Enter— Submit the form
§Field-specific keys
- Text fields: Normal typing, Backspace, Delete, Home/End, Left/Right
- Checkbox: Space or Enter to toggle
- Select: Enter to open, Up/Down to navigate, Enter to confirm
§Example
use envision::component::{
Component, Focusable, Form, FormState, FormMessage,
FormOutput, FormField, FormValue,
};
let mut state = FormState::new(vec![
FormField::text("username", "Username"),
FormField::checkbox("remember", "Remember me"),
FormField::select("role", "Role", vec!["User", "Admin"]),
]);
Form::set_focused(&mut state, true);
// Type username
Form::update(&mut state, FormMessage::Input('A'));
assert_eq!(state.value("username"), Some(FormValue::Text("A".into())));
// Submit the form
let output = Form::update(&mut state, FormMessage::Submit);
assert!(matches!(output, Some(FormOutput::Submitted(_))));Trait Implementations§
Source§impl Component for Form
impl Component for Form
Source§type Message = FormMessage
type Message = FormMessage
Messages this component can receive. Read more
Source§type Output = FormOutput
type Output = FormOutput
Messages this component can emit to its parent. Read more
Source§fn handle_event(state: &Self::State, event: &Event) -> Option<Self::Message>
fn handle_event(state: &Self::State, event: &Event) -> Option<Self::Message>
Maps an input event to a component message. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
Update component state based on a message. Read more
Source§fn view(state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme)
fn view(state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme)
Render the component to the given area. Read more
Auto Trait Implementations§
impl Freeze for Form
impl RefUnwindSafe for Form
impl Send for Form
impl Sync for Form
impl Unpin for Form
impl UnsafeUnpin for Form
impl UnwindSafe for Form
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more