feat(divider): add functions for divider style variants of a Rule
This commit is contained in:
parent
b3a3c9c29a
commit
9a095e4d94
4 changed files with 42 additions and 32 deletions
|
|
@ -652,6 +652,8 @@ impl progress_bar::StyleSheet for Theme {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum Rule {
|
pub enum Rule {
|
||||||
Default,
|
Default,
|
||||||
|
LightDivider,
|
||||||
|
HeavyDivider,
|
||||||
Custom(fn(&Theme) -> rule::Appearance),
|
Custom(fn(&Theme) -> rule::Appearance),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -674,6 +676,24 @@ impl rule::StyleSheet for Theme {
|
||||||
radius: 0.0,
|
radius: 0.0,
|
||||||
fill_mode: rule::FillMode::Full,
|
fill_mode: rule::FillMode::Full,
|
||||||
},
|
},
|
||||||
|
Rule::LightDivider => {
|
||||||
|
let cosmic = &self.cosmic().primary;
|
||||||
|
rule::Appearance {
|
||||||
|
color: cosmic.divider.into(),
|
||||||
|
width: 1,
|
||||||
|
radius: 0.0,
|
||||||
|
fill_mode: rule::FillMode::Padded(10),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rule::HeavyDivider => {
|
||||||
|
let cosmic = &self.cosmic().primary;
|
||||||
|
rule::Appearance {
|
||||||
|
color: cosmic.divider.into(),
|
||||||
|
width: 4,
|
||||||
|
radius: 4.0,
|
||||||
|
fill_mode: rule::FillMode::Full,
|
||||||
|
}
|
||||||
|
}
|
||||||
Rule::Custom(f) => f(self),
|
Rule::Custom(f) => f(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// Copyright 2022 System76 <info@system76.com>
|
// Copyright 2022 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use crate::widget::horizontal_rule;
|
use crate::{theme, widget::divider, Element};
|
||||||
use crate::{theme, Element};
|
|
||||||
use apply::Apply;
|
use apply::Apply;
|
||||||
use iced::{Background, Color};
|
use iced::{Background, Color};
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ impl<'a, Message: 'static> ListColumn<'a, Message> {
|
||||||
#[allow(clippy::should_implement_trait)]
|
#[allow(clippy::should_implement_trait)]
|
||||||
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
||||||
if !self.children.is_empty() {
|
if !self.children.is_empty() {
|
||||||
self.children.push(horizontal_rule(10).into());
|
self.children.push(divider::horizontal::light().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.children.push(item.into());
|
self.children.push(item.into());
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,6 @@ pub use scrollable::*;
|
||||||
mod text;
|
mod text;
|
||||||
pub use text::{text, Text};
|
pub use text::{text, Text};
|
||||||
|
|
||||||
pub mod separator;
|
|
||||||
pub use separator::{horizontal_rule, vertical_rule};
|
|
||||||
|
|
||||||
pub mod spin_button;
|
pub mod spin_button;
|
||||||
pub use spin_button::{spin_button, SpinButton};
|
pub use spin_button::{spin_button, SpinButton};
|
||||||
|
|
||||||
|
|
@ -56,3 +53,23 @@ pub use view_switcher::vertical as vertical_view_switcher;
|
||||||
|
|
||||||
pub mod warning;
|
pub mod warning;
|
||||||
pub use warning::*;
|
pub use warning::*;
|
||||||
|
|
||||||
|
/// An element to distinguish a boundary between two elements.
|
||||||
|
pub mod divider {
|
||||||
|
/// Horizontal variant of a divider.
|
||||||
|
pub mod horizontal {
|
||||||
|
use iced::widget::{horizontal_rule, Rule};
|
||||||
|
|
||||||
|
/// Horizontal divider with light thickness
|
||||||
|
#[must_use]
|
||||||
|
pub fn light() -> Rule<crate::Renderer> {
|
||||||
|
horizontal_rule(4).style(crate::theme::Rule::LightDivider)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Horizontal divider with heavy thickness.
|
||||||
|
#[must_use]
|
||||||
|
pub fn heavy() -> Rule<crate::Renderer> {
|
||||||
|
horizontal_rule(10).style(crate::theme::Rule::HeavyDivider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2022 System76 <info@system76.com>
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
use crate::iced::widget;
|
|
||||||
use crate::{theme, Renderer, Theme};
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn horizontal_rule(size: u16) -> widget::Rule<Renderer> {
|
|
||||||
widget::horizontal_rule(size).style(theme::Rule::Custom(separator_style))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn vertical_rule(size: u16) -> widget::Rule<Renderer> {
|
|
||||||
widget::vertical_rule(size).style(theme::Rule::Custom(separator_style))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
fn separator_style(theme: &Theme) -> widget::rule::Appearance {
|
|
||||||
let cosmic = &theme.cosmic().primary;
|
|
||||||
widget::rule::Appearance {
|
|
||||||
color: cosmic.divider.into(),
|
|
||||||
width: 1,
|
|
||||||
radius: 0.0,
|
|
||||||
fill_mode: widget::rule::FillMode::Padded(10),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue