From a11bcf5af0be26671ba90097c64021014ab2092d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 4 Jun 2020 07:13:38 +0200 Subject: Draft first-class `TitleBar` in `pane_grid` --- examples/pane_grid/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index b4bbd68f..4f081b48 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -97,7 +97,7 @@ impl Sandbox for Example { let pane_grid = PaneGrid::new(&mut self.panes, |pane, content, focus| { - content.view(pane, focus, total_panes) + pane_grid::Content::new(content.view(pane, focus, total_panes)) }) .width(Length::Fill) .height(Length::Fill) -- cgit From 67f4c9aea3a04aca765943f3314fd191f6d9c81f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jul 2020 06:27:38 +0200 Subject: Add a `TitleBar` to `pane_grid` example --- examples/pane_grid/src/main.rs | 46 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'examples') 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, total_panes: usize, ) -> Element { 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, + } + + 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() } -- cgit From 6820eea9cee75922f33ce7050e0e868f0749c83e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jul 2020 06:29:54 +0200 Subject: Simplify style of `pane_grid` example --- examples/pane_grid/src/main.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index cc4a45af..09c33613 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -97,16 +97,15 @@ impl Sandbox for Example { let pane_grid = PaneGrid::new(&mut self.panes, |pane, content, focus| { + let is_focused = focus.is_some(); let title_bar = pane_grid::TitleBar::new(format!("Pane {}", content.id)) .padding(10) - .style(style::TitleBar { focus }); + .style(style::TitleBar { is_focused }); pane_grid::Content::new(content.view(pane, total_panes)) .title_bar(title_bar) - .style(style::Pane { - is_focused: focus.is_some(), - }) + .style(style::Pane { is_focused }) }) .width(Length::Fill) .height(Length::Fill) @@ -229,7 +228,7 @@ impl Content { } mod style { - use iced::{button, container, pane_grid, Background, Color, Vector}; + use iced::{button, container, Background, Color, Vector}; const SURFACE: Color = Color::from_rgb( 0xF2 as f32 / 255.0, @@ -250,13 +249,13 @@ mod style { ); pub struct TitleBar { - pub focus: Option, + pub is_focused: bool, } impl container::StyleSheet for TitleBar { fn style(&self) -> container::Style { let pane = Pane { - is_focused: self.focus.is_some(), + is_focused: self.is_focused, } .style(); -- cgit From 3c5921f30c17bcbe0af74a30b6a256a3fa03515c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jul 2020 07:05:57 +0200 Subject: Update `pane_grid` GIFs --- examples/pane_grid/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/pane_grid/README.md b/examples/pane_grid/README.md index 3653fc5b..a4cfcb7d 100644 --- a/examples/pane_grid/README.md +++ b/examples/pane_grid/README.md @@ -15,8 +15,8 @@ This example showcases the `PaneGrid` widget, which features: The __[`main`]__ file contains all the code of the example. -- cgit