StyledElement
struct · ferroui-base · v0.5.0
struct StyledElement
Extends an Animatable with the following features:
- An inherited
DataContext. - Implements the logical tree.
- A collection of class strings for custom styling.
- Implements styling: tracks the frames applied by styles and themes.
Members
get_logical_ancestorsget_self_and_logical_ancestorsfind_logical_ancestor_of_typeget_logical_childrenget_logical_descendantsget_self_and_logical_descendantsfind_logical_descendant_of_typeget_logical_parentget_logical_parent_of_typeget_logical_siblingsis_logical_ancestor_ofTYPEto_refbegin_inittry_end_initlogical_children_collection_changedon_attached_to_logical_treeon_detached_from_logical_treeon_data_context_changedon_data_context_begin_updateon_data_context_end_updateon_initializedstyle_key_overrideon_control_theme_changedon_templated_parent_control_theme_changedinvalidate_stylesis_logical_rootstyling_parentnotify_child_resources_changedchild_index_provideris_theme_variant_rootdata_context_propertyname_propertyparent_propertytemplated_parent_propertytheme_propertyconstructnewattached_to_logical_treedetached_from_logical_treedata_context_changedinitializedresources_changedactual_theme_variant_changednamehas_nameset_nameclassespseudo_classesset_pseudo_classdata_contextset_data_contextis_initializedstylesis_styles_initializedstyle_keyresourcesresources_if_createdset_resourcesthemeset_themeactual_theme_varianthas_resourcestry_get_resourcetry_find_resourcefind_resourcetemplated_parentset_templated_parentlogical_childrenis_attached_to_logical_treeparentapply_stylingtry_apply_stylingend_initinitialize_if_neededset_parentnotify_attached_to_logical_treenotify_detached_from_logical_treeget_effective_themestyles_addedstyles_removednotify_resources_changedset_data_context_with_prioritybind_classget_class_property
get_logical_ancestors
fn get_logical_ancestors(self: &Self) -> LogicalAncestors
Enumerates the ancestors of the element in the logical tree, from its parent to the root.
get_self_and_logical_ancestors
fn get_self_and_logical_ancestors(self: &Self) -> LogicalAncestors
Enumerates the element and its ancestors in the logical tree.
find_logical_ancestor_of_type
fn find_logical_ancestor_of_type<T: ObjectType>(self: &Self, include_self: bool) -> Option<Ref<T>>
Finds the first logical ancestor of class T, optionally starting
with the element itself.
get_logical_children
fn get_logical_children(self: &Self) -> Rc<Vec<Ref<StyledElement>>>
The logical children of the element.
get_logical_descendants
fn get_logical_descendants(self: &Self) -> LogicalDescendants
Enumerates the descendants of the element in the logical tree, in depth-first pre-order.
get_self_and_logical_descendants
fn get_self_and_logical_descendants(self: &Self) -> LogicalDescendants
Enumerates the element and its descendants in the logical tree, in depth-first pre-order.
find_logical_descendant_of_type
fn find_logical_descendant_of_type<T: ObjectType>(self: &Self, include_self: bool) -> Option<Ref<T>>
Finds the first logical descendant of class T (depth first),
optionally starting with the element itself.
get_logical_parent
fn get_logical_parent(self: &Self) -> Option<Ref<StyledElement>>
The logical parent of the element.
get_logical_parent_of_type
fn get_logical_parent_of_type<T: ObjectType>(self: &Self) -> Option<Ref<T>>
The logical parent of the element, if it is of class T.
get_logical_siblings
fn get_logical_siblings(self: &Self) -> Rc<Vec<Ref<StyledElement>>>
The children of the logical parent of the element, including the element itself; empty when the element has no logical parent.
is_logical_ancestor_of
fn is_logical_ancestor_of(self: &Self, target: Option<&StyledElement>) -> bool
Whether the element is a logical ancestor of target.
TYPE
const TYPE: &'static $crate::TypeInfo
The runtime type of this class.
to_ref
fn to_ref(self: &Self) -> $crate::Ref<StyledElement>
Returns a strong reference to this object.
begin_init
fn begin_init(self: &Self)
Signals the beginning of a batch of initialization: styling is
deferred until the matching end_init.
try_end_init
fn try_end_init(self: &Self) -> Result<(), InitializationError>
Signals the end of a batch of initialization: the element is
styled (if it is attached to a rooted logical tree) and
initialized. A style or control theme that cannot be applied (two
setters for the same property) is an error, the counterpart of
the invalid operation EndInit raises in the managed original;
what follows the failure is skipped. This is the overridable
member; end_init is the form that
panics on the error.
logical_children_collection_changed
fn logical_children_collection_changed(self: &Self, e: &NotifyCollectionChangedEventArgs<'_, Ref<StyledElement>>)
Called when the logical children collection changes.
on_attached_to_logical_tree
fn on_attached_to_logical_tree(self: &Self, e: &LogicalTreeAttachmentEventArgs)
Called when the styled element is added to a rooted logical tree.
on_detached_from_logical_tree
fn on_detached_from_logical_tree(self: &Self, e: &LogicalTreeAttachmentEventArgs)
Called when the styled element is removed from a rooted logical tree.
on_data_context_changed
fn on_data_context_changed(self: &Self)
Called when the data context changes.
on_data_context_begin_update
fn on_data_context_begin_update(self: &Self)
Called when the data context begins updating.
on_data_context_end_update
fn on_data_context_end_update(self: &Self)
Called when the data context finishes updating.
on_initialized
fn on_initialized(self: &Self)
Called when the control finishes initialization.
style_key_override
fn style_key_override(self: &Self) -> &'static TypeInfo
The type by which the element is styled. Defaults to the element's own type; override to be styled as a base class.
on_control_theme_changed
fn on_control_theme_changed(self: &Self)
Called when the control theme changes.
on_templated_parent_control_theme_changed
fn on_templated_parent_control_theme_changed(self: &Self)
Called when the templated parent's control theme changes.
invalidate_styles
fn invalidate_styles(self: &Self, recurse: bool)
Detaches all styles from the element (and optionally from its inheritance children) so that they are re-applied.
is_logical_root
fn is_logical_root(self: &Self) -> bool
Whether the element is the root of a logical tree.
styling_parent
fn styling_parent(self: &Self) -> Option<StyleHostRef>
The parent style host of the element: by default the inheritance parent, when it is a styled element. The root of a tree overrides this to return the host of the global styles.
notify_child_resources_changed
fn notify_child_resources_changed(self: &Self, e: ResourcesChangedEventArgs)
Notifies the children of the element that the resources visible to them have changed. The base method notifies the logical children.
child_index_provider
fn child_index_provider(self: &Self) -> Option<Rc<dyn IChildIndexProvider>>
The child index provider implemented by the element, if any. Used to match the children of the element by their position.
is_theme_variant_root
fn is_theme_variant_root(self: &Self) -> bool
Whether the element is a root of theme variant resolution: at a root the default theme variant resolves to the variant of the platform instead of being inherited.
data_context_property
fn data_context_property() -> &'static StyledProperty<Option<BoxedValue>>
Defines the DataContext property.
name_property
fn name_property() -> &'static DirectProperty<StyledElement, Option<String>>
Defines the Name property.
parent_property
fn parent_property() -> &'static DirectProperty<StyledElement, Option<Ref<StyledElement>>>
Defines the Parent property.
templated_parent_property
fn templated_parent_property() -> &'static DirectProperty<StyledElement, Option<Ref<FerroObject>>>
Defines the TemplatedParent property.
theme_property
fn theme_property() -> &'static StyledProperty<Option<Ref<ControlTheme>>>
Defines the Theme property.
construct
fn construct() -> Self
Creates the class data; see FerroObject::construct.
new
fn new() -> Ref<Self>
attached_to_logical_tree
fn attached_to_logical_tree(self: &Self, handler: impl Fn(&LogicalTreeAttachmentEventArgs) -> () + 'static) -> Subscription
Raised when the styled element is attached to a rooted logical tree.
detached_from_logical_tree
fn detached_from_logical_tree(self: &Self, handler: impl Fn(&LogicalTreeAttachmentEventArgs) -> () + 'static) -> Subscription
Raised when the styled element is detached from a rooted logical tree.
data_context_changed
fn data_context_changed(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
Occurs when the data context property changes.
initialized
fn initialized(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
Occurs when the styled element has finished initialization.
resources_changed
fn resources_changed(self: &Self, handler: impl Fn(&ResourcesChangedEventArgs) -> () + 'static) -> Subscription
Raised when the resources change on the element or an ancestor of the element.
actual_theme_variant_changed
fn actual_theme_variant_changed(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
Raised when the theme variant in effect for the element changes.
name
fn name(self: &Self) -> Option<String>
The name of the styled element.
An element's name is used to uniquely identify it within its name scope. Once the element has been styled its name may not be changed.
has_name
fn has_name(self: &Self, name: &str) -> bool
Whether the name of the styled element is name, without a copy of the name (the name
selectors of styles test it for every element they are evaluated on).
set_name
fn set_name(self: &Self, value: Option<String>)
classes
fn classes(self: &Self) -> Classes
The styled element's classes.
The collection is returned by handle: clones refer to the same collection.
pseudo_classes
fn pseudo_classes(self: &Self) -> &dyn IPseudoClasses
The pseudoclasses of the element, settable by the control itself.
set_pseudo_class
fn set_pseudo_class(self: &Self, name: &str, value: bool)
Adds or removes a pseudoclass. Removing one from an element whose classes were never made makes nothing: an element without classes holds none to remove. An addition (FerroUI deviation, desktop-performance.md section 9.21): every input element removed its focus, pointer-over and disabled pseudoclasses when constructed, which made its collection of classes (three allocations) whether it would ever have a class or not.
data_context
fn data_context(self: &Self) -> Option<BoxedValue>
The control's data context.
The data context is an inherited property that specifies the default object that will be used for data binding.
set_data_context
fn set_data_context(self: &Self, value: Option<BoxedValue>)
is_initialized
fn is_initialized(self: &Self) -> bool
Whether the element has finished initialization.
For more information about when this happens, see the initialized
event.
styles
fn styles(self: &Self) -> Ref<Styles>
The styles for the styled element.
Styles for the entire application are added to the application's styles collection.
is_styles_initialized
fn is_styles_initialized(self: &Self) -> bool
Whether the styles collection of the element has been created.
style_key
fn style_key(self: &Self) -> &'static TypeInfo
The type by which the element is styled.
resources
fn resources(self: &Self) -> Ref<ResourceDictionary>
The styled element's resource dictionary.
resources_if_created
fn resources_if_created(self: &Self) -> Option<Ref<ResourceDictionary>>
The resource dictionary of the element if it has been created; unlike resources, this
does not create one.
set_resources
fn set_resources(self: &Self, value: Ref<ResourceDictionary>)
theme
fn theme(self: &Self) -> Option<Ref<ControlTheme>>
The theme to be applied to the element.
By default the theme is looked up as a resource keyed by the element's style key; setting this property takes precedence over that lookup.
set_theme
fn set_theme(self: &Self, value: impl Into<Nullable<ControlTheme>>)
actual_theme_variant
fn actual_theme_variant(self: &Self) -> Option<ThemeVariant>
The UI theme variant that is currently used by the element, which
might be different than the requested theme variant. None until a
theme variant has been established for the element or an ancestor.
has_resources
fn has_resources(self: &Self) -> bool
Whether the element or its styles have resources.
try_get_resource
fn try_get_resource(self: &Self, key: &ResourceKey, theme: Option<&ThemeVariant>) -> Option<ResourceValue>
Tries to find a resource within the element: in its resource dictionary, then in its styles.
try_find_resource
fn try_find_resource(self: &Self, key: &ResourceKey, theme: Option<&ThemeVariant>) -> Option<ResourceValue>
Tries to find a resource by searching up the logical tree and then the global styles.
find_resource
fn find_resource(self: &Self, key: &ResourceKey) -> ResourceValue
Finds a resource by searching up the logical tree and then the global styles. Returns the unset value marker if it is not found.
templated_parent
fn templated_parent(self: &Self) -> Option<Ref<FerroObject>>
The styled element whose lookless template this element is part of.
set_templated_parent
fn set_templated_parent(self: &Self, value: impl Into<Nullable<FerroObject>>)
Sets the templated parent. Called by the template that creates the element.
logical_children
fn logical_children(self: &Self) -> &FerroList<Ref<StyledElement>>
The styled element's logical children.
is_attached_to_logical_tree
fn is_attached_to_logical_tree(self: &Self) -> bool
Whether the element is attached to a rooted logical tree.
parent
fn parent(self: &Self) -> Option<Ref<StyledElement>>
The styled element's logical parent.
apply_styling
fn apply_styling(self: &Self) -> bool
Applies styling to the control if the control is initialized and styling is not already applied.
The styling system will automatically apply styling when required, so this method need only be called by tests or in rare special cases.
Returns true if styling is applied to the control, false if the control is still initializing.
try_apply_styling
fn try_apply_styling(self: &Self) -> Result<bool, DuplicateSetterError>
As apply_styling, reporting a style or
control theme that cannot be applied (two setters for the same
property: the invalid operation of the managed original) instead of
panicking. After an error the styling pass is ended and the element
is not marked as styled, as when the managed original throws.
end_init
fn end_init(self: &Self)
Signals the end of a batch of initialization
(try_end_init). A style or control theme that
cannot be applied panics with the message of the error.
initialize_if_needed
fn initialize_if_needed(self: &Self)
Marks the element as initialized and raises the initialization notifications, if initialization is complete.
set_parent
fn set_parent(self: &Self, parent: impl Into<Nullable<StyledElement>>)
Sets the element's logical parent.
You should not usually need to call this method: it is called when an element is added to or removed from a logical children collection.
notify_attached_to_logical_tree
fn notify_attached_to_logical_tree(self: &Self, e: &LogicalTreeAttachmentEventArgs)
Notifies the element that it has been attached to a rooted logical tree. Called by a parent for children that are part of its logical tree without being in its logical children collection (the template child of a templated control).
notify_detached_from_logical_tree
fn notify_detached_from_logical_tree(self: &Self, e: &LogicalTreeAttachmentEventArgs)
Notifies the element that it has been detached from a rooted logical
tree. See notify_attached_to_logical_tree.
get_effective_theme
fn get_effective_theme(self: &Self) -> Option<Ref<ControlTheme>>
The theme in effect for the element: the Theme property if set,
otherwise the control theme resource keyed by the element's style key
that is visible to the element (a resource holding a
Ref<ControlTheme>).
styles_added
fn styles_added(self: &Self, styles: &[Rc<dyn IStyle>])
Called when styles are added to the styles collection of the element or a nested styles collection.
styles_removed
fn styles_removed(self: &Self, styles: &[Rc<dyn IStyle>])
Called when styles are removed from the styles collection of the element or a nested styles collection.
notify_resources_changed
fn notify_resources_changed(self: &Self, e: ResourcesChangedEventArgs, propagate: bool)
Notifies the element, and with propagate its children, that the
resources visible to it have changed.
set_data_context_with_priority
fn set_data_context_with_priority(self: &Self, value: Option<BoxedValue>, priority: BindingPriority) -> Option<Rc<dyn IDisposable>>
The priority-aware setter used by templates.
bind_class
fn bind_class(self: &Self, class_name: &str, source: &dyn BindingBase, anchor: Option<&Ref<FerroObject>>) -> Rc<dyn BindingExpressionBase>
Binds the presence of the class class_name on this element to
source. anchor provides the context the binding locates its source
with when the element cannot.
get_class_property
fn get_class_property(class_name: &str) -> &'static FerroProperty
The property a binding to the class class_name is set on.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeFerroObjectImplExtStyledElementImplExtClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>ReceiverAnyErasedDestructorIntoEitherIDataContextProviderDerefUpcast<T>Upcast<StyledElement>StaticTypeObjectTypeSubclassable<T>DefaultConstructibleFerroObjectImplStyledElementImplIResourceNodeIResourceHostIStyleHostIThemeVariantHost
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.