Skip to main content

ferroui_base/data/
indexer_binding.rs

1use crate::data::core::IndexerBindingExpression;
2use crate::data::{BindingBase, BindingExpressionBase, BindingMode};
3use crate::{FerroObject, FerroProperty, Ref};
4use std::rc::Rc;
5
6/// A binding to a registered property of another object: what the binding
7/// indexer of [`FerroObject`] ([`FerroObject::indexer`]) produces.
8#[derive(Clone)]
9pub struct IndexerBinding {
10    source: Ref<FerroObject>,
11    /// The property of the source being bound.
12    pub property: &'static FerroProperty,
13    mode: BindingMode,
14}
15
16impl IndexerBinding {
17    pub fn new(source: Ref<FerroObject>, property: &'static FerroProperty, mode: BindingMode) -> Self {
18        Self { source, property, mode }
19    }
20
21    pub fn source(&self) -> &Ref<FerroObject> {
22        &self.source
23    }
24
25    pub fn mode(&self) -> BindingMode {
26        self.mode
27    }
28}
29
30impl BindingBase for IndexerBinding {
31    fn as_any(&self) -> Option<&dyn std::any::Any> {
32        Some(self)
33    }
34
35    fn create_instance(
36        &self,
37        target: &FerroObject,
38        target_property: Option<&'static FerroProperty>,
39        _anchor: Option<&Ref<FerroObject>>,
40    ) -> Rc<dyn BindingExpressionBase> {
41        IndexerBindingExpression::new(&self.source, self.property, target, target_property, self.mode)
42    }
43}