use crate::winrt::{IInspectable, IActivationFactory, PropertyAccess};
use crate::error::Result;
use windows::core::IInspectable as CoreIInspectable;
#[derive(Clone)]
pub struct XamlTextBlock {
inspectable: IInspectable,
}
impl XamlTextBlock {
pub fn new() -> Result<Self> {
let factory = IActivationFactory::get("Windows.UI.Xaml.Controls.TextBlock")
.map_err(|e| crate::error::Error::control_creation(format!("Failed to get TextBlock factory: {}", e)))?;
let inspectable: CoreIInspectable = factory.activate_instance()
.map_err(|e| crate::error::Error::control_creation(format!("Failed to activate TextBlock: {}", e)))?;
Ok(XamlTextBlock {
inspectable: IInspectable::from(inspectable),
})
}
pub fn as_inspectable(&self) -> &IInspectable {
&self.inspectable
}
pub fn set_text(&self, text: &str) -> Result<()> {
self.set_string_property("Text", text)
}
pub fn get_text(&self) -> Result<String> {
self.get_string_property("Text")
}
pub fn set_font_size(&self, size: f64) -> Result<()> {
self.set_numeric_property("FontSize", size)
}
}
impl PropertyAccess for XamlTextBlock {
fn inspectable(&self) -> &IInspectable {
&self.inspectable
}
}
impl Default for XamlTextBlock {
fn default() -> Self {
Self::new().expect("Failed to create XAML TextBlock")
}
}
unsafe impl Send for XamlTextBlock {}
unsafe impl Sync for XamlTextBlock {}