Skip to main content

ferroui_xaml_interactions_custom/validation/
text_box_validation_behavior.rs

1//! Port of `Validation/TextBoxValidationBehavior.cs`.
2
3use super::property_validation_behavior::PropertyValidationBehavior;
4use ferroui_base::{
5    ferro_class, ferro_class_info, instantiate, FerroObjectImpl, FerroObjectImplExt, Ref, StaticType, StyledElementImpl,
6};
7use ferroui_controls::TextBox;
8use ferroui_xaml_interactivity::{DisposingBehaviorImpl, StyledElementBehaviorImpl};
9use std::any::TypeId;
10
11/// Validation behavior for [`TextBox`] text.
12#[repr(C)]
13pub struct TextBoxValidationBehavior {
14    base: PropertyValidationBehavior,
15}
16
17ferro_class!(TextBoxValidationBehavior: PropertyValidationBehavior);
18ferro_class_info!(TextBoxValidationBehavior { new: TextBoxValidationBehavior::new });
19ferroui_base::ferro_impl_classes!(TextBoxValidationBehavior: StyledElementImpl, StyledElementBehaviorImpl, DisposingBehaviorImpl);
20
21ferroui_base::ferro_overrides! {
22    impl FerroObjectImpl for TextBoxValidationBehavior {
23        /// The constructor body: the property the behavior validates.
24        fn constructed(this: &Self) {
25            Self::parent_constructed(this);
26
27            this.set_property(Some(TextBox::text_property().as_property()));
28        }
29    }
30}
31
32impl TextBoxValidationBehavior {
33    /// Creates the class data; see [`ferroui_base::FerroObject::construct`].
34    pub fn construct() -> Self {
35        Self { base: PropertyValidationBehavior::construct(<TextBox as StaticType>::TYPE, TypeId::of::<Option<String>>()) }
36    }
37
38    /// Initializes a new instance of the [`TextBoxValidationBehavior`] class.
39    pub fn new() -> Ref<Self> {
40        instantiate(Self::construct())
41    }
42}