Skip to content

Commit

Permalink
Update PaneGrid example with more complex TitleBar
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmoody committed Dec 10, 2020
1 parent f54590d commit fb478a4
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions examples/pane_grid/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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)

This comment has been minimized.

Copy link
@cfpgomes

cfpgomes Jan 18, 2021

@clarkmoody This is giving me the following error when compiling: the trait From<iced_native::Row<'_, _, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>>is not implemented forString``. Is this expected?

.padding(10)
.style(style::TitleBar { is_focused });

pane_grid::Content::new(content.view(pane, total_panes))
.title_bar(title_bar)
Expand All @@ -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};
Expand Down

0 comments on commit fb478a4

Please sign in to comment.