ferroui_base/styled_element_extensions.rs
1//! Port of `StyledElementExtensions.cs`: the extension methods are members
2//! of [`StyledElement`], the type they extend.
3//!
4//! The internal `IsClassesBindingProperty` is not repeated here: the one
5//! caller in the framework (the setter) asks
6//! [`ClassBindingManager::is_classes_binding_property`] directly.
7
8use crate::data::{BindingBase, BindingExpressionBase};
9use crate::{ClassBindingManager, FerroObject, FerroProperty, Ref, StyledElement};
10use std::rc::Rc;
11
12impl StyledElement {
13 /// Binds the presence of the class `class_name` on this element to
14 /// `source`. `anchor` provides the context the binding locates its source
15 /// with when the element cannot.
16 pub fn bind_class(
17 &self,
18 class_name: &str,
19 source: &dyn BindingBase,
20 anchor: Option<&Ref<FerroObject>>,
21 ) -> Rc<dyn BindingExpressionBase> {
22 ClassBindingManager::bind(self, class_name, source, anchor)
23 }
24
25 /// The property a binding to the class `class_name` is set on.
26 pub fn get_class_property(class_name: &str) -> &'static FerroProperty {
27 ClassBindingManager::get_class_property(class_name)
28 }
29}