diff options
author | 2020-07-09 06:27:38 +0200 | |
---|---|---|
committer | 2020-07-09 06:27:38 +0200 | |
commit | 67f4c9aea3a04aca765943f3314fd191f6d9c81f (patch) | |
tree | e3d497a559556061eeecba9d71947dee86587e86 /examples/pane_grid | |
parent | 1319c25f20a274d163d8009805b6fd3bb55ac88a (diff) | |
download | iced-67f4c9aea3a04aca765943f3314fd191f6d9c81f.tar.gz iced-67f4c9aea3a04aca765943f3314fd191f6d9c81f.tar.bz2 iced-67f4c9aea3a04aca765943f3314fd191f6d9c81f.zip |
Add a `TitleBar` to `pane_grid` example
Diffstat (limited to 'examples/pane_grid')
-rw-r--r-- | examples/pane_grid/src/main.rs | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 069e2f59..cc4a45af 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -97,7 +97,16 @@ impl Sandbox for Example { let pane_grid = PaneGrid::new(&mut self.panes, |pane, content, focus| { - pane_grid::Content::new(content.view(pane, focus, total_panes)) + let title_bar = + pane_grid::TitleBar::new(format!("Pane {}", content.id)) + .padding(10) + .style(style::TitleBar { focus }); + + pane_grid::Content::new(content.view(pane, total_panes)) + .title_bar(title_bar) + .style(style::Pane { + is_focused: focus.is_some(), + }) }) .width(Length::Fill) .height(Length::Fill) @@ -155,15 +164,14 @@ impl Content { fn view( &mut self, pane: pane_grid::Pane, - focus: Option<pane_grid::Focus>, total_panes: usize, ) -> Element<Message> { let Content { - id, scroll, split_horizontally, split_vertically, close, + .. } = self; let button = |state, label, message, style| { @@ -209,7 +217,6 @@ impl Content { .width(Length::Fill) .spacing(10) .align_items(Align::Center) - .push(Text::new(format!("Pane {}", id)).size(30)) .push(controls); Container::new(content) @@ -217,15 +224,12 @@ impl Content { .height(Length::Fill) .padding(5) .center_y() - .style(style::Pane { - is_focused: focus.is_some(), - }) .into() } } mod style { - use iced::{button, container, Background, Color, Vector}; + use iced::{button, container, pane_grid, Background, Color, Vector}; const SURFACE: Color = Color::from_rgb( 0xF2 as f32 / 255.0, @@ -245,6 +249,25 @@ mod style { 0xC4 as f32 / 255.0, ); + pub struct TitleBar { + pub focus: Option<pane_grid::Focus>, + } + + impl container::StyleSheet for TitleBar { + fn style(&self) -> container::Style { + let pane = Pane { + is_focused: self.focus.is_some(), + } + .style(); + + container::Style { + text_color: Some(Color::WHITE), + background: Some(pane.border_color.into()), + ..Default::default() + } + } + } + pub struct Pane { pub is_focused: bool, } @@ -254,9 +277,10 @@ mod style { container::Style { background: Some(Background::Color(SURFACE)), border_width: 2, - border_color: Color { - a: if self.is_focused { 1.0 } else { 0.3 }, - ..Color::BLACK + border_color: if self.is_focused { + Color::BLACK + } else { + Color::from_rgb(0.7, 0.7, 0.7) }, ..Default::default() } |