mod binding;
mod computed;
mod list;
mod macros;
mod traits;
pub use binding::*;
pub use computed::*;
pub use list::*;
pub use traits::*;
pub trait PropertySink: Send {
fn set_property(
&mut self,
property: &str,
value: crate::widget::capability::CapabilityValue,
) -> Result<(), crate::widget::capability::CapabilityAccessError>;
fn get_property(
&self,
property: &str,
) -> Result<
crate::widget::capability::CapabilityValue,
crate::widget::capability::CapabilityAccessError,
>;
}
#[cfg(not(alloc_frugal))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WidgetPropertySink {
pub widget_id: crate::core::ObjectId,
}
#[cfg(not(alloc_frugal))]
impl WidgetPropertySink {
pub fn new(widget_id: crate::core::ObjectId) -> Self {
Self { widget_id }
}
}
#[cfg(not(alloc_frugal))]
impl PropertySink for WidgetPropertySink {
fn set_property(
&mut self,
property: &str,
value: crate::widget::capability::CapabilityValue,
) -> Result<(), crate::widget::capability::CapabilityAccessError> {
crate::widget::runtime::with_widget_mut(self.widget_id, |widget| {
crate::widget::widget_property_set(widget, property, value)
})
.unwrap_or(Err(crate::widget::capability::CapabilityAccessError::UnknownWidget))
}
fn get_property(
&self,
property: &str,
) -> Result<
crate::widget::capability::CapabilityValue,
crate::widget::capability::CapabilityAccessError,
> {
crate::widget::runtime::with_widget(self.widget_id, |widget| {
crate::widget::widget_property_get(widget, property)
})
.unwrap_or(Err(crate::widget::capability::CapabilityAccessError::UnknownWidget))
}
}
#[cfg(not(alloc_frugal))]
pub fn bind_widget_property(
binding: &Binding<crate::widget::capability::CapabilityValue>,
key: &str,
widget_id: crate::core::ObjectId,
property: &str,
) {
let property = crate::compat::String::from(property);
let observed_property = property.clone();
let synced = binding.clone();
binding.observe(key, move |value| {
let applied = crate::widget::runtime::with_widget_mut(widget_id, |widget| {
crate::widget::widget_property_set(widget, &observed_property, value.clone())
});
if matches!(applied, Some(Ok(()))) {
synced.announce_synced(&observed_property);
}
});
let initial = binding.get();
let _ = crate::widget::runtime::with_widget_mut(widget_id, |widget| {
crate::widget::widget_property_set(widget, &property, initial)
});
binding.announce_synced(&property);
}
#[cfg(not(alloc_frugal))]
pub fn pull_widget_property(
binding: &Binding<crate::widget::capability::CapabilityValue>,
widget_id: crate::core::ObjectId,
property: &str,
) -> bool {
let value = crate::widget::runtime::with_widget(widget_id, |widget| {
crate::widget::widget_property_get(widget, property)
});
match value {
Some(Ok(value)) => {
binding.set(value);
binding.announce_synced(property);
true
}
_ => false,
}
}