Skip to main content

ferroui_controls/
user_control.rs

1use crate::primitives::TemplatedControlImpl;
2use crate::{ContentControl, ContentControlImpl, ControlImpl};
3use ferroui_base::input::InputElementImpl;
4use ferroui_base::interactivity::InteractiveImpl;
5use ferroui_base::layout::LayoutableImpl;
6use ferroui_base::{ferro_class, ferro_impl_classes, instantiate, FerroObjectImpl, Ref, StyledElementImpl, VisualImpl};
7
8/// Provides the base class for defining a new control that encapsulates
9/// related existing controls and provides its own logic.
10#[repr(C)]
11pub struct UserControl {
12    base: ContentControl,
13}
14
15ferro_class!(UserControl: ContentControl);
16ferroui_base::ferro_class_info!(UserControl { new: UserControl::new });
17ferro_impl_classes!(
18    UserControl: FerroObjectImpl,
19    StyledElementImpl,
20    VisualImpl,
21    LayoutableImpl,
22    InteractiveImpl,
23    InputElementImpl,
24    TemplatedControlImpl,
25    ContentControlImpl
26);
27
28impl ControlImpl for UserControl {
29    fn on_create_automation_peer(this: &Self) -> Ref<crate::automation::peers::AutomationPeer> {
30        crate::automation::peers::UserControlAutomationPeer::new(this).upcast()
31    }
32}
33
34impl UserControl {
35    /// Creates the class data; see [`ferroui_base::FerroObject::construct`].
36    pub fn construct() -> Self {
37        Self { base: ContentControl::construct() }
38    }
39
40    pub fn new() -> Ref<Self> {
41        instantiate(Self::construct())
42    }
43}