Implement theme styling for Rule
This commit is contained in:
parent
6f69df3d41
commit
c275fde67a
8 changed files with 86 additions and 123 deletions
|
|
@ -1,6 +1,27 @@
|
|||
//! Display a horizontal or vertical rule for dividing content.
|
||||
use iced_core::Color;
|
||||
|
||||
/// The appearance of a rule.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Appearance {
|
||||
/// The color of the rule.
|
||||
pub color: Color,
|
||||
/// The width (thickness) of the rule line.
|
||||
pub width: u16,
|
||||
/// The radius of the line corners.
|
||||
pub radius: f32,
|
||||
/// The [`FillMode`] of the rule.
|
||||
pub fill_mode: FillMode,
|
||||
}
|
||||
|
||||
/// A set of rules that dictate the style of a rule.
|
||||
pub trait StyleSheet {
|
||||
type Style: Default + Copy;
|
||||
|
||||
/// Produces the style of a rule.
|
||||
fn style(&self, style: Self::Style) -> Appearance;
|
||||
}
|
||||
|
||||
/// The fill mode of a rule.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum FillMode {
|
||||
|
|
@ -64,56 +85,3 @@ impl FillMode {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The appearance of a rule.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Style {
|
||||
/// The color of the rule.
|
||||
pub color: Color,
|
||||
/// The width (thickness) of the rule line.
|
||||
pub width: u16,
|
||||
/// The radius of the line corners.
|
||||
pub radius: f32,
|
||||
/// The [`FillMode`] of the rule.
|
||||
pub fill_mode: FillMode,
|
||||
}
|
||||
|
||||
impl std::default::Default for Style {
|
||||
fn default() -> Self {
|
||||
Style {
|
||||
color: [0.6, 0.6, 0.6, 0.6].into(),
|
||||
width: 1,
|
||||
radius: 0.0,
|
||||
fill_mode: FillMode::Full,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of rules that dictate the style of a rule.
|
||||
pub trait StyleSheet {
|
||||
/// Produces the style of a rule.
|
||||
fn style(&self) -> Style;
|
||||
}
|
||||
|
||||
struct Default;
|
||||
|
||||
impl StyleSheet for Default {
|
||||
fn style(&self) -> Style {
|
||||
Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::default::Default for Box<dyn StyleSheet + 'a> {
|
||||
fn default() -> Self {
|
||||
Box::new(Default)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
|
||||
where
|
||||
T: 'a + StyleSheet,
|
||||
{
|
||||
fn from(style: T) -> Self {
|
||||
Box::new(style)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::application;
|
|||
use crate::button;
|
||||
use crate::pane_grid;
|
||||
use crate::radio;
|
||||
use crate::rule;
|
||||
use crate::slider;
|
||||
use crate::toggler;
|
||||
|
||||
|
|
@ -279,3 +280,21 @@ impl pane_grid::StyleSheet for Theme {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Rule
|
||||
*/
|
||||
impl rule::StyleSheet for Theme {
|
||||
type Style = ();
|
||||
|
||||
fn style(&self, _style: Self::Style) -> rule::Appearance {
|
||||
let palette = self.extended_palette();
|
||||
|
||||
rule::Appearance {
|
||||
color: palette.background.strong.color,
|
||||
width: 1,
|
||||
radius: 0.0,
|
||||
fill_mode: rule::FillMode::Full,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue