Simplify style of `pane_grid` example

This commit is contained in:
Héctor Ramón Jiménez 2020-07-09 06:29:54 +02:00
parent 67f4c9aea3
commit 6820eea9ce
1 changed files with 6 additions and 7 deletions

View File

@ -97,16 +97,15 @@ impl Sandbox for Example {
let pane_grid = let pane_grid =
PaneGrid::new(&mut self.panes, |pane, content, focus| { PaneGrid::new(&mut self.panes, |pane, content, focus| {
let is_focused = focus.is_some();
let title_bar = let title_bar =
pane_grid::TitleBar::new(format!("Pane {}", content.id)) pane_grid::TitleBar::new(format!("Pane {}", content.id))
.padding(10) .padding(10)
.style(style::TitleBar { focus }); .style(style::TitleBar { is_focused });
pane_grid::Content::new(content.view(pane, total_panes)) pane_grid::Content::new(content.view(pane, total_panes))
.title_bar(title_bar) .title_bar(title_bar)
.style(style::Pane { .style(style::Pane { is_focused })
is_focused: focus.is_some(),
})
}) })
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
@ -229,7 +228,7 @@ impl Content {
} }
mod style { mod style {
use iced::{button, container, pane_grid, Background, Color, Vector}; use iced::{button, container, Background, Color, Vector};
const SURFACE: Color = Color::from_rgb( const SURFACE: Color = Color::from_rgb(
0xF2 as f32 / 255.0, 0xF2 as f32 / 255.0,
@ -250,13 +249,13 @@ mod style {
); );
pub struct TitleBar { pub struct TitleBar {
pub focus: Option<pane_grid::Focus>, pub is_focused: bool,
} }
impl container::StyleSheet for TitleBar { impl container::StyleSheet for TitleBar {
fn style(&self) -> container::Style { fn style(&self) -> container::Style {
let pane = Pane { let pane = Pane {
is_focused: self.focus.is_some(), is_focused: self.is_focused,
} }
.style(); .style();