1mod app;
5mod buffer;
6pub use buffer::BufferStats;
7#[doc(hidden)]
8pub mod branch;
9mod builders;
10mod control;
11pub mod each;
12pub use each::{Each, EachBuilder, each};
13mod input;
14#[cfg(feature = "markdown")]
15pub mod markdown;
16mod plan;
17pub use plan::{Plan, PlanInstance, PlanPart, plan};
18pub mod list;
19pub use app::{App, Error, Mounted, Result, Scope, Settle, UiStats, WeakScope, Widget};
20pub use builders::*;
21pub use control::{When, when};
22pub use glory_render::{
23 Current, DismissReason, Event, EventKind, FieldPart, FocusMode, FormAction, FormControl,
24 GridCommand, InputAssist, InputAutofill, InputEdit, InputEditCapture, InputEditIntent,
25 InputEditRejection, InputMode, ItemPosition, Layer, LayerPlacement, LinkOpen, Navigation,
26 NavigationPanel, NavigationPanelCommand, Orientation, Purpose, RangeCommand, RangeValue, Role,
27 ScrollAxes, ScrollCommand, ScrollMetrics, ScrollMovement, SelectionDirection, SemanticId,
28 Semantics, SliderValue, SpinValue, TextKind, TextSelection,
29};
30pub use list::{List, list};
31
32#[doc(hidden)]
35pub trait WidgetHost<'scope>: Sized {
36 type Output;
37 fn mount<W: Widget>(self, widget: W) -> Self::Output;
38 fn compose<W: Widget>(
39 self,
40 factory: impl FnOnce(&'scope glory_core::Scope) -> Result<Option<W>>,
41 ) -> Self::Output;
42}
43
44impl<W: Widget> Widget for Option<W> {
45 fn mount_with_host<'scope, H: WidgetHost<'scope>>(self, host: H) -> H::Output {
46 host.compose(|_| Ok(self))
47 }
48 fn is_empty(&self) -> bool {
49 self.is_none()
50 }
51 fn compose(&mut self, _: &glory_core::Scope) -> Result<Option<Box<dyn Widget>>> {
52 Ok(self.take().map(|value| Box::new(value) as Box<dyn Widget>))
53 }
54}
55
56#[doc(hidden)]
58pub struct Missing;
59
60pub struct Deferred<F>(Option<F>);
62pub fn defer<F, W>(factory: F) -> Deferred<F>
63where
64 F: FnOnce() -> W + 'static,
65 W: Widget,
66{
67 Deferred(Some(factory))
68}
69impl<F, W> Widget for Deferred<F>
70where
71 F: FnOnce() -> W + 'static,
72 W: Widget,
73{
74 fn mount_with_host<'scope, H: WidgetHost<'scope>>(mut self, host: H) -> H::Output {
75 host.compose(|_| Ok(Some(self.0.take().ok_or(Error::Gone)?())))
76 }
77 fn compose(&mut self, _: &glory_core::Scope) -> Result<Option<Box<dyn Widget>>> {
78 let factory = self.0.take().ok_or(Error::Gone)?;
79 Ok(Some(Box::new(factory())))
80 }
81}
82
83impl<W: Widget + ?Sized> Widget for Box<W> {
84 fn is_empty(&self) -> bool {
85 (**self).is_empty()
86 }
87 fn compose(&mut self, scope: &glory_core::Scope) -> Result<Option<Box<dyn Widget>>> {
88 (**self).compose(scope)
89 }
90 fn native_host(&self) -> Option<std::any::TypeId> {
91 (**self).native_host()
92 }
93 fn mount_host(
94 &mut self,
95 scope: &glory_core::Scope,
96 host: &mut dyn std::any::Any,
97 ) -> Result<bool> {
98 (**self).mount_host(scope, host)
99 }
100 fn static_plan(&mut self) -> Result<Plan> {
101 (**self).static_plan()
102 }
103 fn build(&mut self, scope: &Scope) -> Result {
104 (**self).build(scope)
105 }
106}