Implement theme styling for Rule
This commit is contained in:
parent
6f69df3d41
commit
c275fde67a
8 changed files with 86 additions and 123 deletions
|
|
@ -179,7 +179,7 @@ impl Sandbox for ScrollableDemo {
|
|||
.spacing(20)
|
||||
.padding(20)
|
||||
.push(choose_theme)
|
||||
.push(Rule::horizontal(20).style(self.theme))
|
||||
.push(Rule::horizontal(20))
|
||||
.push(scrollable_row);
|
||||
|
||||
Container::new(content)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use iced::{container, rule, scrollable};
|
||||
use iced::{container, scrollable};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Theme {
|
||||
|
|
@ -34,17 +34,8 @@ impl<'a> From<Theme> for Box<dyn scrollable::StyleSheet + 'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Theme> for Box<dyn rule::StyleSheet> {
|
||||
fn from(theme: Theme) -> Self {
|
||||
match theme {
|
||||
Theme::Light => Default::default(),
|
||||
Theme::Dark => dark::Rule.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod dark {
|
||||
use iced::{container, rule, scrollable, Color};
|
||||
use iced::{container, scrollable, Color};
|
||||
|
||||
const BACKGROUND: Color = Color::from_rgb(
|
||||
0x36 as f32 / 255.0,
|
||||
|
|
@ -139,17 +130,4 @@ mod dark {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rule;
|
||||
|
||||
impl rule::StyleSheet for Rule {
|
||||
fn style(&self) -> rule::Style {
|
||||
rule::Style {
|
||||
color: SURFACE,
|
||||
width: 2,
|
||||
radius: 1.0,
|
||||
fill_mode: rule::FillMode::Percent(30.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ impl Sandbox for Styling {
|
|||
.padding(20)
|
||||
.max_width(600)
|
||||
.push(choose_theme)
|
||||
.push(Rule::horizontal(38).style(self.theme))
|
||||
.push(Rule::horizontal(38))
|
||||
.push(Row::new().spacing(10).push(text_input).push(button))
|
||||
.push(slider)
|
||||
.push(progress_bar)
|
||||
|
|
@ -132,7 +132,7 @@ impl Sandbox for Styling {
|
|||
.height(Length::Units(100))
|
||||
.align_items(Alignment::Center)
|
||||
.push(scrollable)
|
||||
.push(Rule::vertical(38).style(self.theme))
|
||||
.push(Rule::vertical(38))
|
||||
.push(
|
||||
Column::new()
|
||||
.width(Length::Shrink)
|
||||
|
|
@ -159,7 +159,7 @@ impl Sandbox for Styling {
|
|||
}
|
||||
|
||||
mod style {
|
||||
use iced::{checkbox, progress_bar, rule, scrollable, text_input};
|
||||
use iced::{checkbox, progress_bar, scrollable, text_input};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Theme {
|
||||
|
|
@ -213,19 +213,8 @@ mod style {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Theme> for Box<dyn rule::StyleSheet> {
|
||||
fn from(theme: Theme) -> Self {
|
||||
match theme {
|
||||
Theme::Light => Default::default(),
|
||||
Theme::Dark => dark::Rule.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod dark {
|
||||
use iced::{
|
||||
checkbox, progress_bar, rule, scrollable, text_input, Color,
|
||||
};
|
||||
use iced::{checkbox, progress_bar, scrollable, text_input, Color};
|
||||
|
||||
const SURFACE: Color = Color::from_rgb(
|
||||
0x40 as f32 / 255.0,
|
||||
|
|
@ -374,18 +363,5 @@ mod style {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rule;
|
||||
|
||||
impl rule::StyleSheet for Rule {
|
||||
fn style(&self) -> rule::Style {
|
||||
rule::Style {
|
||||
color: SURFACE,
|
||||
width: 2,
|
||||
radius: 1.0,
|
||||
fill_mode: rule::FillMode::Padded(15),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue