ferroui_xaml_interactivity/templates/
notification_template.rs1use ferroui_base::styling::ITemplate;
4use ferroui_base::{ferro_markup_type, BoxedValue};
5use ferroui_controls::notifications::INotification;
6use ferroui_markup_xaml::templates::TemplateContent;
7use std::cell::RefCell;
8use std::rc::Rc;
9
10#[derive(Default)]
13pub struct NotificationTemplate {
14 content: RefCell<Option<BoxedValue>>,
15}
16
17impl NotificationTemplate {
18 pub fn new() -> Rc<Self> {
20 Rc::new(Self::default())
21 }
22
23 pub fn content(&self) -> Option<BoxedValue> {
26 self.content.borrow().clone()
27 }
28
29 pub fn set_content(&self, value: Option<BoxedValue>) {
30 *self.content.borrow_mut() = value;
31 }
32
33 pub fn build(&self) -> Option<Rc<dyn INotification>> {
39 TemplateContent::load_as::<Rc<dyn INotification>>(self.content().as_ref()).map(|result| result.result().clone())
40 }
41}
42
43impl ITemplate for NotificationTemplate {
44 fn build(&self) -> BoxedValue {
46 Rc::new(NotificationTemplate::build(self))
47 }
48}
49
50impl PartialEq for NotificationTemplate {
51 fn eq(&self, other: &Self) -> bool {
52 std::ptr::eq(self, other)
53 }
54}
55
56ferro_markup_type!(class NotificationTemplate {
57 this: Rc<NotificationTemplate>,
58 handles: [NotificationTemplate, Rc<NotificationTemplate>, Option<Rc<NotificationTemplate>>],
59 interfaces: [Rc<dyn ITemplate>],
60 constructors: [() => NotificationTemplate::new],
61 content: Content,
62 properties: [
63 Content: Option<BoxedValue> {
64 get: NotificationTemplate::content,
65 set: NotificationTemplate::set_content
66 } [TemplateContent(TemplateResultType = type(Rc<dyn INotification>))],
67 ],
68});