Wire up container styling to iced_native
This commit is contained in:
parent
edea093350
commit
d61cb58d92
17 changed files with 65 additions and 99 deletions
|
|
@ -150,7 +150,7 @@ impl Application for GameOfLife {
|
|||
Container::new(content)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.style(style::Container)
|
||||
.style(&style::Container)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,11 @@ impl Application for Example {
|
|||
let title_bar = pane_grid::TitleBar::new(title)
|
||||
.controls(pane.controls.view(id, total_panes, pane.is_pinned))
|
||||
.padding(10)
|
||||
.style(style::TitleBar { is_focused });
|
||||
.style(if is_focused {
|
||||
&style::TitleBar::Focused
|
||||
} else {
|
||||
&style::TitleBar::Active
|
||||
});
|
||||
|
||||
pane_grid::Content::new(pane.content.view(
|
||||
id,
|
||||
|
|
@ -185,7 +189,11 @@ impl Application for Example {
|
|||
pane.is_pinned,
|
||||
))
|
||||
.title_bar(title_bar)
|
||||
.style(style::Pane { is_focused })
|
||||
.style(if is_focused {
|
||||
&style::Pane::Focused
|
||||
} else {
|
||||
&style::Pane::Active
|
||||
})
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
@ -387,14 +395,16 @@ mod style {
|
|||
0xC4 as f32 / 255.0,
|
||||
);
|
||||
|
||||
pub struct TitleBar {
|
||||
pub is_focused: bool,
|
||||
pub enum TitleBar {
|
||||
Active,
|
||||
Focused,
|
||||
}
|
||||
|
||||
impl container::StyleSheet for TitleBar {
|
||||
fn style(&self) -> container::Style {
|
||||
let pane = Pane {
|
||||
is_focused: self.is_focused,
|
||||
let pane = match self {
|
||||
Self::Active => Pane::Active,
|
||||
Self::Focused => Pane::Focused,
|
||||
}
|
||||
.style();
|
||||
|
||||
|
|
@ -406,8 +416,9 @@ mod style {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Pane {
|
||||
pub is_focused: bool,
|
||||
pub enum Pane {
|
||||
Active,
|
||||
Focused,
|
||||
}
|
||||
|
||||
impl container::StyleSheet for Pane {
|
||||
|
|
@ -415,10 +426,9 @@ mod style {
|
|||
container::Style {
|
||||
background: Some(Background::Color(SURFACE)),
|
||||
border_width: 2.0,
|
||||
border_color: if self.is_focused {
|
||||
Color::BLACK
|
||||
} else {
|
||||
Color::from_rgb(0.7, 0.7, 0.7)
|
||||
border_color: match self {
|
||||
Self::Active => Color::from_rgb(0.7, 0.7, 0.7),
|
||||
Self::Focused => Color::BLACK,
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ impl Sandbox for ScrollableDemo {
|
|||
Container::new(scrollable)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.style(*theme),
|
||||
.style(theme.clone().into()),
|
||||
)
|
||||
.push(ProgressBar::new(
|
||||
0.0..=1.0,
|
||||
|
|
@ -190,7 +190,7 @@ impl Sandbox for ScrollableDemo {
|
|||
.height(Length::Fill)
|
||||
.center_x()
|
||||
.center_y()
|
||||
.style(self.theme)
|
||||
.style(self.theme.into())
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ impl Default for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Theme> for Box<dyn container::StyleSheet> {
|
||||
impl From<Theme> for &'static dyn container::StyleSheet {
|
||||
fn from(theme: Theme) -> Self {
|
||||
match theme {
|
||||
Theme::Light => Default::default(),
|
||||
Theme::Dark => dark::Container.into(),
|
||||
Theme::Dark => &dark::Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ impl Sandbox for Styling {
|
|||
.height(Length::Fill)
|
||||
.center_x()
|
||||
.center_y()
|
||||
.style(self.theme)
|
||||
.style(self.theme.into())
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
@ -176,11 +176,11 @@ mod style {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Theme> for Box<dyn container::StyleSheet> {
|
||||
impl From<Theme> for &'static dyn container::StyleSheet {
|
||||
fn from(theme: Theme) -> Self {
|
||||
match theme {
|
||||
Theme::Light => Default::default(),
|
||||
Theme::Dark => dark::Container.into(),
|
||||
Theme::Dark => &dark::Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ fn tooltip<'a>(
|
|||
)
|
||||
.gap(5)
|
||||
.padding(10)
|
||||
.style(style::Tooltip)
|
||||
.style(&style::Tooltip)
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue