diff options
author | 2020-12-08 18:47:47 -0600 | |
---|---|---|
committer | 2020-12-10 12:18:28 -0600 | |
commit | fb478a4014021d200a76c93d7f93f57371a843d8 (patch) | |
tree | 6922481bfb5fc9d08ece74a15566216e2998cecc /examples/pane_grid | |
parent | f54590d7adac611db84b88cbcbf4f56c7542039c (diff) | |
download | iced-fb478a4014021d200a76c93d7f93f57371a843d8.tar.gz iced-fb478a4014021d200a76c93d7f93f57371a843d8.tar.bz2 iced-fb478a4014021d200a76c93d7f93f57371a843d8.zip |
Update PaneGrid example with more complex TitleBar
Diffstat (limited to 'examples/pane_grid')
-rw-r--r-- | examples/pane_grid/src/main.rs | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 3c3256cf..c44d24fd 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -1,7 +1,7 @@ use iced::{ button, executor, keyboard, pane_grid, scrollable, Align, Application, - Button, Column, Command, Container, Element, HorizontalAlignment, Length, - PaneGrid, Scrollable, Settings, Subscription, Text, + Button, Color, Column, Command, Container, Element, HorizontalAlignment, + Length, PaneGrid, Row, Scrollable, Settings, Subscription, Text, }; use iced_native::{event, subscription, Event}; @@ -141,10 +141,21 @@ impl Application for Example { let pane_grid = PaneGrid::new(&mut self.panes, |pane, content| { let is_focused = focus == Some(pane); - let title_bar = - pane_grid::TitleBar::new(format!("Pane {}", content.id)) - .padding(10) - .style(style::TitleBar { is_focused }); + let title = Row::with_children(vec![ + Text::new("Pane").into(), + Text::new(content.id.to_string()) + .color(if is_focused { + PANE_ID_COLOR_FOCUSED + } else { + PANE_ID_COLOR_UNFOCUSED + }) + .into(), + ]) + .spacing(5); + + let title_bar = pane_grid::TitleBar::new(title) + .padding(10) + .style(style::TitleBar { is_focused }); pane_grid::Content::new(content.view(pane, total_panes)) .title_bar(title_bar) @@ -165,6 +176,17 @@ impl Application for Example { } } +const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb( + 0xFF as f32 / 255.0, + 0xC7 as f32 / 255.0, + 0xC7 as f32 / 255.0, +); +const PANE_ID_COLOR_FOCUSED: Color = Color::from_rgb( + 0xFF as f32 / 255.0, + 0x47 as f32 / 255.0, + 0x47 as f32 / 255.0, +); + fn handle_hotkey(key_code: keyboard::KeyCode) -> Option<Message> { use keyboard::KeyCode; use pane_grid::{Axis, Direction}; |