ferroui_controls/metadata/template_part_attribute.rs
1use ferroui_base::TypeInfo;
2
3/// Declares that a templated control expects a named part of a given type
4/// in its control template.
5///
6/// Classes expose their parts through a `template_parts()` function.
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct TemplatePartAttribute {
9 /// The pre-defined name of the part.
10 pub name: &'static str,
11 /// The type of the named part: the part is of this class or a class
12 /// derived from it.
13 pub type_: &'static TypeInfo,
14 /// Whether the part is required to be present in the template. A
15 /// required part not found in the template is an error.
16 pub is_required: bool,
17}
18
19impl TemplatePartAttribute {
20 /// Declares an optional part.
21 pub const fn new(name: &'static str, type_: &'static TypeInfo) -> Self {
22 Self { name, type_, is_required: false }
23 }
24
25 /// Declares a required part.
26 pub const fn required(name: &'static str, type_: &'static TypeInfo) -> Self {
27 Self { name, type_, is_required: true }
28 }
29}