From 4e1e0e0890b83fb1c4c4406791e3aa63bba58a93 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Jun 2020 06:52:07 +0200 Subject: Draft drawing logic for `Content` and `TitleBar` --- graphics/src/widget/pane_grid.rs | 60 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/pane_grid.rs b/graphics/src/widget/pane_grid.rs index 7a840689..71b1658a 100644 --- a/graphics/src/widget/pane_grid.rs +++ b/graphics/src/widget/pane_grid.rs @@ -119,11 +119,63 @@ where fn draw_pane( &mut self, defaults: &Self::Defaults, - _title_bar: Option<&TitleBar<'_, Message, Self>>, - body: &Element<'_, Message, Self>, - layout: Layout<'_>, + title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>, + body: (&Element<'_, Message, Self>, Layout<'_>), + cursor_position: Point, + ) -> Self::Output { + let (body, body_layout) = body; + + let (body_primitive, body_interaction) = + body.draw(self, defaults, body_layout, cursor_position); + + if let Some((title_bar, title_bar_layout)) = title_bar { + let (title_bar_primitive, title_bar_interaction) = title_bar.draw( + self, + defaults, + title_bar_layout, + cursor_position, + ); + + ( + Primitive::Group { + primitives: vec![title_bar_primitive, body_primitive], + }, + if title_bar_interaction > body_interaction { + title_bar_interaction + } else { + body_interaction + }, + ) + } else { + (body_primitive, body_interaction) + } + } + + fn draw_title_bar( + &mut self, + defaults: &Self::Defaults, + style: &::Style, + title: (&Element<'_, Message, Self>, Layout<'_>), + controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>, cursor_position: Point, ) -> Self::Output { - body.draw(self, defaults, layout, cursor_position) + let (title, title_layout) = title; + + let (title_primitive, _) = + title.draw(self, defaults, title_layout, cursor_position); + + if let Some((controls, controls_layout)) = controls { + let (controls_primitive, controls_interaction) = + controls.draw(self, defaults, controls_layout, cursor_position); + + ( + Primitive::Group { + primitives: vec![title_primitive, controls_primitive], + }, + controls_interaction, + ) + } else { + (title_primitive, mouse::Interaction::default()) + } } } -- cgit