slt/widgets.rs
1//! Widget state types passed to [`Context`](crate::Context) widget methods.
2//!
3//! Each interactive widget (text input, list, tabs, table, etc.) has a
4//! corresponding state struct defined here. Create the state once, then pass
5//! a `&mut` reference each frame.
6
7use std::collections::HashSet;
8use std::fs;
9use std::path::PathBuf;
10use std::time::{SystemTime, UNIX_EPOCH};
11use unicode_width::UnicodeWidthStr;
12
13use crate::context::Response;
14use crate::Style;
15
16/// Bare function-pointer validator used by the deprecated positional
17/// [`FormState::validate`](crate::widgets::FormState::validate) API.
18///
19/// Retained for backward compatibility. New code should attach
20/// [`Validator`](crate::widgets::Validator) closures per field via
21/// [`FormField::validate`](crate::widgets::FormField::validate); see the
22/// [`validators`] module for built-ins.
23pub type FormValidator = fn(&str) -> Result<(), String>;
24type TextInputValidator = Box<dyn Fn(&str) -> Result<(), String>>;
25
26/// Built-in field validator constructors (required / length / email / range /
27/// regex / one-of).
28///
29/// Each function returns a closure suitable for
30/// [`FormField::validate`](crate::widgets::FormField::validate) or
31/// [`Validator::new`](crate::widgets::Validator::new). All matchers are
32/// handwritten — there is no `regex` or email-parsing dependency.
33pub mod validators {
34 include!("widgets/validators.rs");
35}
36
37include!("widgets/input.rs");
38include!("widgets/collections.rs");
39include!("widgets/feedback.rs");
40include!("widgets/selection.rs");
41include!("widgets/commanding.rs");
42include!("widgets/responses.rs");
43
44#[cfg(test)]
45mod tests;