pub struct Child<T>where
T: Component,{ /* private fields */ }Available on crate feature
winio only.Expand description
Helper to embed one component into another. It handles different types of messages and events.
Implementations§
Source§impl<T> Child<T>where
T: Component,
impl<T> Child<T>where
T: Component,
Sourcepub async fn init<'a>(
init: impl Into<<T as Component>::Init<'a>>,
) -> Result<Child<T>, <T as Component>::Error>
pub async fn init<'a>( init: impl Into<<T as Component>::Init<'a>>, ) -> Result<Child<T>, <T as Component>::Error>
Create and initialize the child component.
Sourcepub async fn start<C>(
&mut self,
sender: &ComponentSender<C>,
f: impl FnMut(<T as Component>::Event) -> Option<<C as Component>::Message>,
propagate: impl FnMut() -> <C as Component>::Message,
) -> !where
C: Component,
pub async fn start<C>(
&mut self,
sender: &ComponentSender<C>,
f: impl FnMut(<T as Component>::Event) -> Option<<C as Component>::Message>,
propagate: impl FnMut() -> <C as Component>::Message,
) -> !where
C: Component,
Start to receive and interp the events of the child component.
Define a root component MainModel, and it contains a
window: Child<Window>. The message of MainModel is defined as
ⓘ
enum MainMessage {
Noop,
Close,
}In the MainModel::start, you should write
ⓘ
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
WindowEvent::Close => MainMessage::Close,
},
// ...other children
}
}It is equivalent to
ⓘ
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
let fut_window = self.window.start(
sender,
|e| match e {
WindowEvent::Close => Some(MainMessage::Close),
// ignore other events
_ => None,
},
// you should always propagate internal messages
|| MainMessage::Noop,
);
// ...other children
futures_util::join!(fut_window, /* ... */);
}Sourcepub fn post(&mut self, message: <T as Component>::Message)
pub fn post(&mut self, message: <T as Component>::Message)
Post message to the child component.
Sourcepub async fn emit(
&mut self,
message: <T as Component>::Message,
) -> Result<bool, <T as Component>::Error>
pub async fn emit( &mut self, message: <T as Component>::Message, ) -> Result<bool, <T as Component>::Error>
Emit message to the child component.
Sourcepub async fn update(&mut self) -> Result<bool, <T as Component>::Error>
pub async fn update(&mut self) -> Result<bool, <T as Component>::Error>
Respond to the child message.
Sourcepub fn sender(&self) -> &ComponentSender<T>
pub fn sender(&self) -> &ComponentSender<T>
Get the sender of the child component.
Trait Implementations§
Source§impl<T> AsContainer for Child<T>where
T: AsContainer + Component,
Available on crate feature handle only.
impl<T> AsContainer for Child<T>where
T: AsContainer + Component,
Available on crate feature
handle only.Source§fn as_container(&self) -> BorrowedContainer<'_>
fn as_container(&self) -> BorrowedContainer<'_>
Get the container handle.
Source§impl<T> AsWidget for Child<T>
Available on crate feature handle only.
impl<T> AsWidget for Child<T>
Available on crate feature
handle only.Source§fn as_widget(&self) -> BorrowedWidget<'_>
fn as_widget(&self) -> BorrowedWidget<'_>
Get the widget handle.
Source§impl<T> AsWindow for Child<T>
Available on crate feature handle only.
impl<T> AsWindow for Child<T>
Available on crate feature
handle only.Source§fn as_window(&self) -> BorrowedWindow<'_>
fn as_window(&self) -> BorrowedWindow<'_>
Get the window handle.
Source§impl<T> Layoutable for Child<T>where
T: Component + Layoutable,
impl<T> Layoutable for Child<T>where
T: Component + Layoutable,
Source§fn loc(
&self,
) -> Result<Point2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
fn loc( &self, ) -> Result<Point2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
The left top location.
Source§fn set_loc(
&mut self,
p: Point2D<f64, LogicalSpace>,
) -> Result<(), <Child<T> as Failable>::Error>
fn set_loc( &mut self, p: Point2D<f64, LogicalSpace>, ) -> Result<(), <Child<T> as Failable>::Error>
Move the location.
Source§fn size(
&self,
) -> Result<Size2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
fn size( &self, ) -> Result<Size2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
The size.
Source§fn set_size(
&mut self,
s: Size2D<f64, LogicalSpace>,
) -> Result<(), <Child<T> as Failable>::Error>
fn set_size( &mut self, s: Size2D<f64, LogicalSpace>, ) -> Result<(), <Child<T> as Failable>::Error>
Resize.
Source§fn rect(&self) -> Result<Rect<f64, LogicalSpace>, <Child<T> as Failable>::Error>
fn rect(&self) -> Result<Rect<f64, LogicalSpace>, <Child<T> as Failable>::Error>
The bounding rectangle.
Source§fn set_rect(
&mut self,
r: Rect<f64, LogicalSpace>,
) -> Result<(), <Child<T> as Failable>::Error>
fn set_rect( &mut self, r: Rect<f64, LogicalSpace>, ) -> Result<(), <Child<T> as Failable>::Error>
Set the location and size.
Source§fn preferred_size(
&self,
) -> Result<Size2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
fn preferred_size( &self, ) -> Result<Size2D<f64, LogicalSpace>, <Child<T> as Failable>::Error>
The preferred size.
Auto Trait Implementations§
impl<T> Freeze for Child<T>
impl<T> RefUnwindSafe for Child<T>
impl<T> Send for Child<T>
impl<T> Sync for Child<T>
impl<T> Unpin for Child<T>
impl<T> UnsafeUnpin for Child<T>
impl<T> UnwindSafe for Child<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more