Update PaneGrid example with more complex TitleBar

This commit is contained in:
Clark Moody 2020-12-08 18:47:47 -06:00
parent f54590d7ad
commit fb478a4014

View File

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, executor, keyboard, pane_grid, scrollable, Align, Application, button, executor, keyboard, pane_grid, scrollable, Align, Application,
Button, Column, Command, Container, Element, HorizontalAlignment, Length, Button, Color, Column, Command, Container, Element, HorizontalAlignment,
PaneGrid, Scrollable, Settings, Subscription, Text, Length, PaneGrid, Row, Scrollable, Settings, Subscription, Text,
}; };
use iced_native::{event, subscription, Event}; use iced_native::{event, subscription, Event};
@ -141,8 +141,19 @@ impl Application for Example {
let pane_grid = PaneGrid::new(&mut self.panes, |pane, content| { let pane_grid = PaneGrid::new(&mut self.panes, |pane, content| {
let is_focused = focus == Some(pane); let is_focused = focus == Some(pane);
let title_bar = let title = Row::with_children(vec![
pane_grid::TitleBar::new(format!("Pane {}", content.id)) 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) .padding(10)
.style(style::TitleBar { is_focused }); .style(style::TitleBar { is_focused });
@ -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> { fn handle_hotkey(key_code: keyboard::KeyCode) -> Option<Message> {
use keyboard::KeyCode; use keyboard::KeyCode;
use pane_grid::{Axis, Direction}; use pane_grid::{Axis, Direction};