Add container draw/event

This commit is contained in:
ClementTsang 2021-12-24 17:14:05 -05:00
parent 6ad4cbf464
commit 37a04ea69d
2 changed files with 18 additions and 7 deletions

View File

@ -41,19 +41,29 @@ impl<'a, Message> Container<'a, Message> {
impl<'a, Message> TmpComponent<Message> for Container<'a, Message> { impl<'a, Message> TmpComponent<Message> for Container<'a, Message> {
fn draw<B>( fn draw<B>(
&mut self, _state_ctx: &mut StateContext<'_>, _draw_ctx: DrawContext<'_>, &mut self, state_ctx: &mut StateContext<'_>, draw_ctx: DrawContext<'_>,
_frame: &mut Frame<'_, B>, frame: &mut Frame<'_, B>,
) where ) where
B: Backend, B: Backend,
{ {
todo!() if let Some(child) = &mut self.child {
if let Some(child_draw_ctx) = draw_ctx.children().next() {
child.draw(state_ctx, child_draw_ctx, frame)
}
}
} }
fn on_event( fn on_event(
&mut self, _state_ctx: &mut StateContext<'_>, _draw_ctx: DrawContext<'_>, _event: Event, &mut self, state_ctx: &mut StateContext<'_>, draw_ctx: DrawContext<'_>, event: Event,
_messages: &mut Vec<Message>, messages: &mut Vec<Message>,
) -> Status { ) -> Status {
todo!() if let Some(child) = &mut self.child {
if let Some(child_draw_ctx) = draw_ctx.children().next() {
return child.on_event(state_ctx, child_draw_ctx, event, messages);
}
}
Status::Ignored
} }
fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size { fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
@ -84,6 +94,7 @@ impl<'a, Message> TmpComponent<Message> for Container<'a, Message> {
}; };
let child_size = child.layout(child_bounds, &mut child_node); let child_size = child.layout(child_bounds, &mut child_node);
node.children = vec![child_node];
// Note that this is implicitly bounded by our above calculations, // Note that this is implicitly bounded by our above calculations,
// no need to recheck if it's valid! // no need to recheck if it's valid!

View File

@ -28,7 +28,7 @@ where
A: Application + 'static, A: Application + 'static,
B: Backend, B: Backend,
{ {
let mut app_data = AppData::default(); let mut app_data = AppData::default(); // FIXME: This needs to be cleared periodically, DO!
let mut layout: LayoutNode = LayoutNode::default(); let mut layout: LayoutNode = LayoutNode::default();
let mut user_interface = { let mut user_interface = {