Introduce Border struct analogous to Shadow

This commit is contained in:
Héctor Ramón Jiménez 2024-01-20 13:29:25 +01:00
parent 4d502012b3
commit 25f182f933
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
44 changed files with 382 additions and 424 deletions

54
core/src/border.rs Normal file
View file

@ -0,0 +1,54 @@
//! Draw lines around containers.
use crate::Color;
/// A border.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Border {
/// The color of the border.
pub color: Color,
/// The width of the border.
pub width: f32,
/// The radius of the border.
pub radius: Radius,
}
impl Border {
/// Creates a new default [`Border`] with the given [`Radius`].
pub fn with_radius(radius: impl Into<Radius>) -> Self {
Self {
radius: radius.into(),
..Self::default()
}
}
}
/// The border radii for the corners of a graphics primitive in the order:
/// top-left, top-right, bottom-right, bottom-left.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Radius([f32; 4]);
impl From<f32> for Radius {
fn from(w: f32) -> Self {
Self([w; 4])
}
}
impl From<u8> for Radius {
fn from(w: u8) -> Self {
Self([f32::from(w); 4])
}
}
impl From<[f32; 4]> for Radius {
fn from(radi: [f32; 4]) -> Self {
Self(radi)
}
}
impl From<Radius> for [f32; 4] {
fn from(radi: Radius) -> Self {
radi.0
}
}

View file

@ -6,7 +6,8 @@ use crate::renderer;
use crate::widget;
use crate::widget::tree::{self, Tree};
use crate::{
Clipboard, Color, Layout, Length, Rectangle, Shell, Size, Vector, Widget,
Border, Clipboard, Color, Layout, Length, Rectangle, Shell, Size, Vector,
Widget,
};
use std::any::Any;
@ -537,8 +538,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border_color: color,
border_width: 1.0,
border: Border {
color,
width: 1.0,
..Border::default()
},
..renderer::Quad::default()
},
Color::TRANSPARENT,

View file

@ -17,6 +17,7 @@
rustdoc::broken_intra_doc_links
)]
pub mod alignment;
pub mod border;
pub mod clipboard;
pub mod event;
pub mod font;
@ -27,7 +28,6 @@ pub mod layout;
pub mod mouse;
pub mod overlay;
pub mod renderer;
pub mod shadow;
pub mod svg;
pub mod text;
pub mod time;
@ -37,7 +37,6 @@ pub mod window;
mod angle;
mod background;
mod border_radius;
mod color;
mod content_fit;
mod element;
@ -47,6 +46,7 @@ mod padding;
mod pixels;
mod point;
mod rectangle;
mod shadow;
mod shell;
mod size;
mod vector;
@ -54,7 +54,7 @@ mod vector;
pub use alignment::Alignment;
pub use angle::{Degrees, Radians};
pub use background::Background;
pub use border_radius::BorderRadius;
pub use border::Border;
pub use clipboard::Clipboard;
pub use color::Color;
pub use content_fit::ContentFit;

View file

@ -5,7 +5,7 @@ mod null;
#[cfg(debug_assertions)]
pub use null::Null;
use crate::{Background, BorderRadius, Color, Rectangle, Shadow, Size, Vector};
use crate::{Background, Border, Color, Rectangle, Shadow, Size, Vector};
/// A component that can be used by widgets to draw themselves on a screen.
pub trait Renderer: Sized {
@ -37,27 +37,19 @@ pub struct Quad {
/// The bounds of the [`Quad`].
pub bounds: Rectangle,
/// The border radius of the [`Quad`].
pub border_radius: BorderRadius,
/// The [`Border`] of the [`Quad`].
pub border: Border,
/// The border width of the [`Quad`].
pub border_width: f32,
/// The border color of the [`Quad`].
pub border_color: Color,
/// The shadow of the [`Quad`].
pub shadow: Option<Shadow>,
/// The [`Shadow`] of the [`Quad`].
pub shadow: Shadow,
}
impl Default for Quad {
fn default() -> Self {
Self {
bounds: Rectangle::with_size(Size::ZERO),
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
shadow: None,
border: Border::default(),
shadow: Shadow::default(),
}
}
}

View file

@ -1,15 +1,14 @@
//! Shadow
use crate::{Color, Vector};
/// A shadow
#[derive(Debug, Clone, Copy, PartialEq)]
/// A shadow.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Shadow {
/// The color of the shadow
/// The color of the shadow.
pub color: Color,
/// The offset of the shadow
/// The offset of the shadow.
pub offset: Vector,
/// The blur radius of the shadow
/// The blur radius of the shadow.
pub blur_radius: f32,
}

View file

@ -3,8 +3,8 @@ mod quad {
use iced::advanced::layout::{self, Layout};
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
use iced::{mouse, Shadow};
use iced::{Color, Element, Length, Rectangle, Size};
use iced::mouse;
use iced::{Border, Color, Element, Length, Rectangle, Shadow, Size};
pub struct CustomQuad {
size: f32,
@ -62,10 +62,12 @@ mod quad {
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border_radius: self.radius.into(),
border_width: self.border_width,
border_color: Color::from_rgb(1.0, 0.0, 0.0),
shadow: Some(self.shadow),
border: Border {
radius: self.radius.into(),
width: self.border_width,
color: Color::from_rgb(1.0, 0.0, 0.0),
},
shadow: self.shadow,
},
Color::BLACK,
);

View file

@ -13,7 +13,7 @@ mod circle {
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
use iced::mouse;
use iced::{Color, Element, Length, Rectangle, Size};
use iced::{Border, Color, Element, Length, Rectangle, Size};
pub struct Circle {
radius: f32,
@ -62,7 +62,7 @@ mod circle {
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border_radius: self.radius.into(),
border: Border::with_radius(self.radius),
..renderer::Quad::default()
},
Color::BLACK,

View file

@ -231,10 +231,7 @@ mod modal {
use iced::alignment::Alignment;
use iced::event;
use iced::mouse;
use iced::{
BorderRadius, Color, Element, Event, Length, Point, Rectangle, Size,
Vector,
};
use iced::{Color, Element, Event, Length, Point, Rectangle, Size, Vector};
/// A widget that centers a modal element over some base element
pub struct Modal<'a, Message, Renderer> {
@ -474,7 +471,6 @@ mod modal {
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border_radius: BorderRadius::default(),
..renderer::Quad::default()
},
Color {

View file

@ -348,7 +348,7 @@ fn view_controls<'a>(
mod style {
use iced::widget::container;
use iced::Theme;
use iced::{Border, Theme};
pub fn title_bar_active(theme: &Theme) -> container::Appearance {
let palette = theme.extended_palette();
@ -375,8 +375,11 @@ mod style {
container::Appearance {
background: Some(palette.background.weak.color.into()),
border_width: 2.0,
border_color: palette.background.strong.color,
border: Border {
width: 2.0,
color: palette.background.strong.color,
..Border::default()
},
..Default::default()
}
}
@ -386,8 +389,11 @@ mod style {
container::Appearance {
background: Some(palette.background.weak.color.into()),
border_width: 2.0,
border_color: palette.primary.strong.color,
border: Border {
width: 2.0,
color: palette.primary.strong.color,
..Border::default()
},
..Default::default()
}
}

View file

@ -1,10 +1,14 @@
use iced::executor;
use iced::theme;
use iced::widget::scrollable::{Properties, Scrollbar, Scroller};
use iced::widget::{
button, column, container, horizontal_space, progress_bar, radio, row,
scrollable, slider, text, vertical_space,
};
use iced::{executor, theme, Alignment, Color};
use iced::{Application, Command, Element, Length, Settings, Theme};
use iced::{
Alignment, Application, Border, Color, Command, Element, Length, Settings,
Theme,
};
use once_cell::sync::Lazy;
@ -373,14 +377,10 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle {
background: style
.active(&theme::Scrollable::default())
.background,
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::default(),
border: Border::with_radius(2),
scroller: Scroller {
color: Color::from_rgb8(250, 85, 134),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::default(),
border: Border::with_radius(2),
},
}
} else {

View file

@ -78,11 +78,7 @@ impl<T: Damage> Damage for Primitive<T> {
// damage bounds (?)
raw.clip_bounds.expand(1.5)
}
Self::Quad {
bounds,
shadow: Some(shadow),
..
} => {
Self::Quad { bounds, shadow, .. } if shadow.color.a > 0.0 => {
let bounds_with_shadow = Rectangle {
x: bounds.x + shadow.offset.x.min(0.0) - shadow.blur_radius,
y: bounds.y + shadow.offset.y.min(0.0) - shadow.blur_radius,

View file

@ -4,7 +4,7 @@ use crate::core::image;
use crate::core::svg;
use crate::core::text;
use crate::core::{
Background, Color, Font, Pixels, Point, Rectangle, Shadow, Vector,
Background, Border, Color, Font, Pixels, Point, Rectangle, Shadow, Vector,
};
use crate::text::editor;
use crate::text::paragraph;
@ -67,14 +67,10 @@ pub enum Primitive<T> {
bounds: Rectangle,
/// The background of the quad
background: Background,
/// The border radii of the quad
border_radius: [f32; 4],
/// The border width of the quad
border_width: f32,
/// The border color of the quad
border_color: Color,
/// The [`Border`] of the quad
border: Border,
/// The [`Shadow`] of the quad
shadow: Option<Shadow>,
shadow: Shadow,
},
/// An image primitive
Image {

View file

@ -124,9 +124,7 @@ impl<B: Backend, T> iced_core::Renderer for Renderer<B, T> {
self.primitives.push(Primitive::Quad {
bounds: quad.bounds,
background: background.into(),
border_radius: quad.border_radius.into(),
border_width: quad.border_width,
border_color: quad.border_color,
border: quad.border,
shadow: quad.shadow,
});
}

View file

@ -188,11 +188,12 @@ pub mod multi_window;
pub use style::theme;
pub use crate::core::alignment;
pub use crate::core::border;
pub use crate::core::color;
pub use crate::core::gradient;
pub use crate::core::{
color, Alignment, Background, BorderRadius, Color, ContentFit, Degrees,
Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size,
Vector,
Alignment, Background, Border, Color, ContentFit, Degrees, Gradient,
Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size, Vector,
};
pub mod clipboard {

View file

@ -1,5 +1,5 @@
//! Change the apperance of a button.
use iced_core::{Background, BorderRadius, Color, Vector};
use iced_core::{Background, Border, Color, Vector};
/// The appearance of a button.
#[derive(Debug, Clone, Copy)]
@ -8,12 +8,8 @@ pub struct Appearance {
pub shadow_offset: Vector,
/// The [`Background`] of the button.
pub background: Option<Background>,
/// The border radius of the button.
pub border_radius: BorderRadius,
/// The border width of the button.
pub border_width: f32,
/// The border [`Color`] of the button.
pub border_color: Color,
/// The [`Border`] of the butoon.
pub border: Border,
/// The text [`Color`] of the button.
pub text_color: Color,
}
@ -23,9 +19,7 @@ impl std::default::Default for Appearance {
Self {
shadow_offset: Vector::default(),
background: None,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::default(),
text_color: Color::BLACK,
}
}

View file

@ -1,5 +1,5 @@
//! Change the appearance of a checkbox.
use iced_core::{Background, BorderRadius, Color};
use iced_core::{Background, Border, Color};
/// The appearance of a checkbox.
#[derive(Debug, Clone, Copy)]
@ -8,12 +8,8 @@ pub struct Appearance {
pub background: Background,
/// The icon [`Color`] of the checkbox.
pub icon_color: Color,
/// The border radius of the checkbox.
pub border_radius: BorderRadius,
/// The border width of the checkbox.
pub border_width: f32,
/// The border [`Color`] of the checkbox.
pub border_color: Color,
/// The [`Border`] of hte checkbox.
pub border: Border,
/// The text [`Color`] of the checkbox.
pub text_color: Option<Color>,
}

View file

@ -1,19 +1,15 @@
//! Change the appearance of a container.
use crate::core::{Background, BorderRadius, Color, Pixels};
use crate::core::{Background, Border, Color, Pixels};
/// The appearance of a container.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Default)]
pub struct Appearance {
/// The text [`Color`] of the container.
pub text_color: Option<Color>,
/// The [`Background`] of the container.
pub background: Option<Background>,
/// The border radius of the container.
pub border_radius: BorderRadius,
/// The border width of the container.
pub border_width: f32,
/// The border [`Color`] of the container.
pub border_color: Color,
/// The [`Border`] of the container.
pub border: Border,
}
impl Appearance {
@ -25,8 +21,11 @@ impl Appearance {
width: impl Into<Pixels>,
) -> Self {
Self {
border_color: color.into(),
border_width: width.into().0,
border: Border {
color: color.into(),
width: width.into().0,
..Border::default()
},
..self
}
}
@ -40,18 +39,6 @@ impl Appearance {
}
}
impl std::default::Default for Appearance {
fn default() -> Self {
Self {
text_color: None,
background: None,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
}
/// A set of rules that dictate the [`Appearance`] of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].

View file

@ -1,5 +1,5 @@
//! Change the appearance of menus.
use iced_core::{Background, BorderRadius, Color};
use iced_core::{Background, Border, Color};
/// The appearance of a menu.
#[derive(Debug, Clone, Copy)]
@ -8,12 +8,8 @@ pub struct Appearance {
pub text_color: Color,
/// The [`Background`] of the menu.
pub background: Background,
/// The border width of the menu.
pub border_width: f32,
/// The border radius of the menu.
pub border_radius: BorderRadius,
/// The border [`Color`] of the menu.
pub border_color: Color,
/// The [`Border`] of the menu.
pub border: Border,
/// The text [`Color`] of a selected option in the menu.
pub selected_text_color: Color,
/// The background [`Color`] of a selected option in the menu.

View file

@ -1,17 +1,13 @@
//! Change the appearance of a pane grid.
use iced_core::{Background, BorderRadius, Color};
use iced_core::{Background, Border, Color};
/// The appearance of the hovered region of a pane grid.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the hovered pane region.
/// The [`Background`] of the pane region.
pub background: Background,
/// The border width of the hovered pane region.
pub border_width: f32,
/// The border [`Color`] of the hovered pane region.
pub border_color: Color,
/// The border radius of the hovered pane region.
pub border_radius: BorderRadius,
/// The [`Border`] of the pane region.
pub border: Border,
}
/// A line.

View file

@ -1,5 +1,5 @@
//! Change the appearance of a pick list.
use iced_core::{Background, BorderRadius, Color};
use iced_core::{Background, Border, Color};
/// The appearance of a pick list.
#[derive(Debug, Clone, Copy)]
@ -12,12 +12,8 @@ pub struct Appearance {
pub handle_color: Color,
/// The [`Background`] of the pick list.
pub background: Background,
/// The border radius of the pick list.
pub border_radius: BorderRadius,
/// The border width of the pick list.
pub border_width: f32,
/// The border color of the pick list.
pub border_color: Color,
/// The [`Border`] of the pick list.
pub border: Border,
}
/// A set of rules that dictate the style of a container.

View file

@ -1,5 +1,6 @@
//! Change the appearance of a progress bar.
use iced_core::{Background, BorderRadius};
use crate::core::border;
use crate::core::Background;
/// The appearance of a progress bar.
#[derive(Debug, Clone, Copy)]
@ -9,7 +10,7 @@ pub struct Appearance {
/// The [`Background`] of the bar of the progress bar.
pub bar: Background,
/// The border radius of the progress bar.
pub border_radius: BorderRadius,
pub border_radius: border::Radius,
}
/// A set of rules that dictate the style of a progress bar.

View file

@ -1,5 +1,6 @@
//! Change the appearance of a rule.
use iced_core::{BorderRadius, Color};
use crate::core::border;
use crate::core::Color;
/// The appearance of a rule.
#[derive(Debug, Clone, Copy)]
@ -9,7 +10,7 @@ pub struct Appearance {
/// The width (thickness) of the rule line.
pub width: u16,
/// The radius of the line corners.
pub radius: BorderRadius,
pub radius: border::Radius,
/// The [`FillMode`] of the rule.
pub fill_mode: FillMode,
}

View file

@ -1,17 +1,13 @@
//! Change the appearance of a scrollable.
use iced_core::{Background, BorderRadius, Color};
use crate::core::{Background, Border, Color};
/// The appearance of a scrollable.
#[derive(Debug, Clone, Copy)]
pub struct Scrollbar {
/// The [`Background`] of a scrollable.
pub background: Option<Background>,
/// The border radius of a scrollable.
pub border_radius: BorderRadius,
/// The border width of a scrollable.
pub border_width: f32,
/// The border [`Color`] of a scrollable.
pub border_color: Color,
/// The [`Border`] of a scrollable.
pub border: Border,
/// The appearance of the [`Scroller`] of a scrollable.
pub scroller: Scroller,
}
@ -21,12 +17,8 @@ pub struct Scrollbar {
pub struct Scroller {
/// The [`Color`] of the scroller.
pub color: Color,
/// The border radius of the scroller.
pub border_radius: BorderRadius,
/// The border width of the scroller.
pub border_width: f32,
/// The border [`Color`] of the scroller.
pub border_color: Color,
/// The [`Border`] of the scroller.
pub border: Border,
}
/// A set of rules that dictate the style of a scrollable.

View file

@ -1,5 +1,6 @@
//! Change the apperance of a slider.
use iced_core::{BorderRadius, Color};
use crate::core::border;
use crate::core::Color;
/// The appearance of a slider.
#[derive(Debug, Clone, Copy)]
@ -18,7 +19,7 @@ pub struct Rail {
/// The width of the stroke of a slider rail.
pub width: f32,
/// The border radius of the corners of the rail.
pub border_radius: BorderRadius,
pub border_radius: border::Radius,
}
/// The appearance of the handle of a slider.
@ -47,7 +48,7 @@ pub enum HandleShape {
/// The width of the rectangle.
width: u16,
/// The border radius of the corners of the rectangle.
border_radius: BorderRadius,
border_radius: border::Radius,
},
}

View file

@ -1,17 +1,13 @@
//! Change the appearance of a text editor.
use crate::core::{Background, BorderRadius, Color};
use crate::core::{Background, Border, Color};
/// The appearance of a text input.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the text input.
/// The [`Background`] of the text editor.
pub background: Background,
/// The border radius of the text input.
pub border_radius: BorderRadius,
/// The border width of the text input.
pub border_width: f32,
/// The border [`Color`] of the text input.
pub border_color: Color,
/// The [`Border`] of the text editor.
pub border: Border,
}
/// A set of rules that dictate the style of a text input.

View file

@ -1,17 +1,13 @@
//! Change the appearance of a text input.
use iced_core::{Background, BorderRadius, Color};
use iced_core::{Background, Border, Color};
/// The appearance of a text input.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the text input.
pub background: Background,
/// The border radius of the text input.
pub border_radius: BorderRadius,
/// The border width of the text input.
pub border_width: f32,
/// The border [`Color`] of the text input.
pub border_color: Color,
/// The [`Border`] of the text input.
pub border: Border,
/// The icon [`Color`] of the text input.
pub icon_color: Color,
}

View file

@ -21,7 +21,7 @@ use crate::text_editor;
use crate::text_input;
use crate::toggler;
use iced_core::{Background, Color, Vector};
use crate::core::{Background, Border, Color, Vector};
use std::fmt;
use std::rc::Rc;
@ -199,7 +199,7 @@ impl button::StyleSheet for Theme {
let palette = self.extended_palette();
let appearance = button::Appearance {
border_radius: 2.0.into(),
border: Border::with_radius(2),
..button::Appearance::default()
};
@ -388,9 +388,11 @@ fn checkbox_appearance(
base.color
}),
icon_color,
border_radius: 2.0.into(),
border_width: 1.0,
border_color: accent.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: accent.color,
},
text_color: None,
}
}
@ -431,9 +433,7 @@ impl container::StyleSheet for Theme {
container::Appearance {
text_color: None,
background: Some(palette.background.weak.color.into()),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::with_radius(2),
}
}
Container::Custom(custom) => custom.appearance(self),
@ -555,9 +555,11 @@ impl menu::StyleSheet for Theme {
menu::Appearance {
text_color: palette.background.weak.text,
background: palette.background.weak.color.into(),
border_width: 1.0,
border_radius: 0.0.into(),
border_color: palette.background.strong.color,
border: Border {
width: 1.0,
radius: 0.0.into(),
color: palette.background.strong.color,
},
selected_text_color: palette.primary.strong.text,
selected_background: palette.primary.strong.color.into(),
}
@ -602,9 +604,11 @@ impl pick_list::StyleSheet for Theme {
background: palette.background.weak.color.into(),
placeholder_color: palette.background.strong.color,
handle_color: palette.background.weak.text,
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.strong.color,
},
}
}
PickList::Custom(custom, _) => custom.active(self),
@ -621,9 +625,11 @@ impl pick_list::StyleSheet for Theme {
background: palette.background.weak.color.into(),
placeholder_color: palette.background.strong.color,
handle_color: palette.background.weak.text,
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.primary.strong.color,
},
}
}
PickList::Custom(custom, _) => custom.hovered(self),
@ -776,9 +782,11 @@ impl pane_grid::StyleSheet for Theme {
a: 0.5,
..palette.primary.base.color
}),
border_width: 2.0,
border_color: palette.primary.strong.color,
border_radius: 0.0.into(),
border: Border {
width: 2.0,
color: palette.primary.strong.color,
radius: 0.0.into(),
},
}
}
PaneGrid::Custom(custom) => custom.hovered_region(self),
@ -986,14 +994,10 @@ impl scrollable::StyleSheet for Theme {
scrollable::Scrollbar {
background: Some(palette.background.weak.color.into()),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::with_radius(2),
scroller: scrollable::Scroller {
color: palette.background.strong.color,
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::with_radius(2),
},
}
}
@ -1013,14 +1017,10 @@ impl scrollable::StyleSheet for Theme {
scrollable::Scrollbar {
background: Some(palette.background.weak.color.into()),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::with_radius(2),
scroller: scrollable::Scroller {
color: palette.primary.strong.color,
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border::with_radius(2),
},
}
} else {
@ -1120,9 +1120,11 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.strong.color,
},
icon_color: palette.background.weak.text,
}
}
@ -1136,9 +1138,11 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.base.text,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.base.text,
},
icon_color: palette.background.weak.text,
}
}
@ -1152,9 +1156,11 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.primary.strong.color,
},
icon_color: palette.background.weak.text,
}
}
@ -1198,9 +1204,11 @@ impl text_input::StyleSheet for Theme {
text_input::Appearance {
background: palette.background.weak.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.strong.color,
},
icon_color: palette.background.strong.color,
}
}
@ -1236,9 +1244,11 @@ impl text_editor::StyleSheet for Theme {
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.strong.color,
},
}
}
@ -1251,9 +1261,11 @@ impl text_editor::StyleSheet for Theme {
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.base.text,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.base.text,
},
}
}
@ -1266,9 +1278,11 @@ impl text_editor::StyleSheet for Theme {
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.primary.strong.color,
},
}
}
@ -1311,9 +1325,11 @@ impl text_editor::StyleSheet for Theme {
text_editor::Appearance {
background: palette.background.weak.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
border: Border {
radius: 2.0.into(),
width: 1.0,
color: palette.background.strong.color,
},
}
}

View file

@ -152,9 +152,7 @@ impl Backend {
Primitive::Quad {
bounds,
background,
border_radius,
border_width,
border_color,
border,
shadow,
} => {
let physical_bounds = (*bounds + translation) * scale_factor;
@ -173,11 +171,12 @@ impl Backend {
.post_scale(scale_factor, scale_factor);
// Make sure the border radius is not larger than the bounds
let border_width = border_width
let border_width = border
.width
.min(bounds.width / 2.0)
.min(bounds.height / 2.0);
let mut fill_border_radius = *border_radius;
let mut fill_border_radius = <[f32; 4]>::from(border.radius);
for radius in &mut fill_border_radius {
*radius = (*radius)
.min(bounds.width / 2.0)
@ -185,92 +184,78 @@ impl Backend {
}
let path = rounded_rectangle(*bounds, fill_border_radius);
if let Some(shadow) = shadow {
if shadow.color.a > 0.0 {
let shadow_bounds = (Rectangle {
x: bounds.x + shadow.offset.x - shadow.blur_radius,
y: bounds.y + shadow.offset.y - shadow.blur_radius,
width: bounds.width + shadow.blur_radius * 2.0,
height: bounds.height + shadow.blur_radius * 2.0,
} + translation)
* scale_factor;
if shadow.color.a > 0.0 {
let shadow_bounds = (Rectangle {
x: bounds.x + shadow.offset.x - shadow.blur_radius,
y: bounds.y + shadow.offset.y - shadow.blur_radius,
width: bounds.width + shadow.blur_radius * 2.0,
height: bounds.height + shadow.blur_radius * 2.0,
} + translation)
* scale_factor;
let radii = fill_border_radius
.into_iter()
.map(|radius| radius * scale_factor)
.collect::<Vec<_>>();
let (x, y, width, height) = (
shadow_bounds.x as u32,
shadow_bounds.y as u32,
shadow_bounds.width as u32,
shadow_bounds.height as u32,
);
let half_width = physical_bounds.width / 2.0;
let half_height = physical_bounds.height / 2.0;
let radii = fill_border_radius
.into_iter()
.map(|radius| radius * scale_factor)
.collect::<Vec<_>>();
let (x, y, width, height) = (
shadow_bounds.x as u32,
shadow_bounds.y as u32,
shadow_bounds.width as u32,
shadow_bounds.height as u32,
);
let half_width = physical_bounds.width / 2.0;
let half_height = physical_bounds.height / 2.0;
let colors = (y..y + height)
.flat_map(|y| {
(x..x + width)
.map(move |x| (x as f32, y as f32))
let colors = (y..y + height)
.flat_map(|y| {
(x..x + width).map(move |x| (x as f32, y as f32))
})
.filter_map(|(x, y)| {
Size::from_wh(half_width, half_height).map(|size| {
let shadow_distance = rounded_box_sdf(
Vector::new(
x - physical_bounds.position().x
- (shadow.offset.x * scale_factor)
- half_width,
y - physical_bounds.position().y
- (shadow.offset.y * scale_factor)
- half_height,
),
size,
&radii,
);
let shadow_alpha = 1.0
- smoothstep(
-shadow.blur_radius * scale_factor,
shadow.blur_radius * scale_factor,
shadow_distance,
);
let mut color = into_color(shadow.color);
color.apply_opacity(shadow_alpha);
color.to_color_u8().premultiply()
})
.filter_map(|(x, y)| {
Size::from_wh(half_width, half_height).map(
|size| {
let shadow_distance = rounded_box_sdf(
Vector::new(
x - physical_bounds
.position()
.x
- (shadow.offset.x
* scale_factor)
- half_width,
y - physical_bounds
.position()
.y
- (shadow.offset.y
* scale_factor)
- half_height,
),
size,
&radii,
);
let shadow_alpha = 1.0
- smoothstep(
-shadow.blur_radius
* scale_factor,
shadow.blur_radius
* scale_factor,
shadow_distance,
);
})
.collect();
let mut color =
into_color(shadow.color);
color.apply_opacity(shadow_alpha);
color.to_color_u8().premultiply()
},
)
})
.collect();
if let Some(pixmap) = tiny_skia::IntSize::from_wh(
width, height,
if let Some(pixmap) = tiny_skia::IntSize::from_wh(
width, height,
)
.and_then(|size| {
tiny_skia::Pixmap::from_vec(
bytemuck::cast_vec(colors),
size,
)
.and_then(|size| {
tiny_skia::Pixmap::from_vec(
bytemuck::cast_vec(colors),
size,
)
}) {
pixels.draw_pixmap(
x as i32,
y as i32,
pixmap.as_ref(),
&tiny_skia::PixmapPaint::default(),
tiny_skia::Transform::default(),
None,
);
}
}) {
pixels.draw_pixmap(
x as i32,
y as i32,
pixmap.as_ref(),
&tiny_skia::PixmapPaint::default(),
tiny_skia::Transform::default(),
None,
);
}
}
@ -344,7 +329,7 @@ impl Backend {
};
// Make sure the border radius is correct
let mut border_radius = *border_radius;
let mut border_radius = <[f32; 4]>::from(border.radius);
let mut is_simple_border = true;
for radius in &mut border_radius {
@ -370,7 +355,7 @@ impl Backend {
&border_path,
&tiny_skia::Paint {
shader: tiny_skia::Shader::SolidColor(
into_color(*border_color),
into_color(border.color),
),
anti_alias: true,
..tiny_skia::Paint::default()
@ -426,7 +411,7 @@ impl Backend {
&border_radius_path,
&tiny_skia::Paint {
shader: tiny_skia::Shader::SolidColor(
into_color(*border_color),
into_color(border.color),
),
anti_alias: true,
..tiny_skia::Paint::default()

View file

@ -12,9 +12,7 @@ pub use text::Text;
use crate::core;
use crate::core::alignment;
use crate::core::{
Color, Font, Pixels, Point, Rectangle, Shadow, Size, Vector,
};
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector};
use crate::graphics;
use crate::graphics::color;
use crate::graphics::Viewport;
@ -197,28 +195,20 @@ impl<'a> Layer<'a> {
Primitive::Quad {
bounds,
background,
border_radius,
border_width,
border_color,
border,
shadow,
} => {
let layer = &mut layers[current_layer];
let shadow = shadow.unwrap_or_else(|| Shadow {
color: Color::TRANSPARENT,
offset: Vector::ZERO,
blur_radius: 0.0,
});
let quad = Quad {
position: [
bounds.x + translation.x,
bounds.y + translation.y,
],
size: [bounds.width, bounds.height],
border_color: color::pack(*border_color),
border_radius: *border_radius,
border_width: *border_width,
border_color: color::pack(border.color),
border_radius: border.radius.into(),
border_width: border.width,
shadow_color: shadow.color.into_linear(),
shadow_offset: shadow.offset.into(),
shadow_blur_radius: shadow.blur_radius,

View file

@ -11,7 +11,7 @@ use crate::core::widget::tree::{self, Tree};
use crate::core::widget::Operation;
use crate::core::{
Background, Clipboard, Color, Element, Layout, Length, Padding, Rectangle,
Shell, Size, Vector, Widget,
Shell, Size, Widget,
};
pub use iced_style::button::{Appearance, StyleSheet};
@ -391,29 +391,11 @@ where
style_sheet.active(style)
};
if styling.background.is_some() || styling.border_width > 0.0 {
if styling.shadow_offset != Vector::default() {
// TODO: Implement proper shadow support
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + styling.shadow_offset.x,
y: bounds.y + styling.shadow_offset.y,
..bounds
},
border_radius: styling.border_radius,
..renderer::Quad::default()
},
Background::Color([0.0, 0.0, 0.0, 0.5].into()),
);
}
if styling.background.is_some() || styling.border.width > 0.0 {
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: styling.border_radius,
border_width: styling.border_width,
border_color: styling.border_color,
border: styling.border,
..renderer::Quad::default()
},
styling

View file

@ -284,9 +284,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: custom_style.border_radius,
border_width: custom_style.border_width,
border_color: custom_style.border_color,
border: custom_style.border,
..renderer::Quad::default()
},
custom_style.background,

View file

@ -337,13 +337,11 @@ pub fn draw_background<Renderer>(
) where
Renderer: crate::core::Renderer,
{
if appearance.background.is_some() || appearance.border_width > 0.0 {
if appearance.background.is_some() || appearance.border.width > 0.0 {
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance

View file

@ -10,7 +10,7 @@ use crate::core::text::{self, Text};
use crate::core::touch;
use crate::core::widget::Tree;
use crate::core::{
Clipboard, Length, Padding, Pixels, Point, Rectangle, Size, Vector,
Border, Clipboard, Length, Padding, Pixels, Point, Rectangle, Size, Vector,
};
use crate::core::{Element, Shell, Widget};
use crate::scrollable::{self, Scrollable};
@ -306,9 +306,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_color: appearance.border_color,
border_width: appearance.border_width,
border_radius: appearance.border_radius,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,
@ -513,11 +511,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + appearance.border_width,
width: bounds.width - appearance.border_width * 2.0,
x: bounds.x + appearance.border.width,
width: bounds.width - appearance.border.width * 2.0,
..bounds
},
border_radius: appearance.border_radius,
border: Border::with_radius(appearance.border.radius),
..renderer::Quad::default()
},
appearance.selected_background,

View file

@ -917,10 +917,7 @@ pub fn draw<Renderer, T>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: hovered_region_style
.border_radius,
border_width: hovered_region_style.border_width,
border_color: hovered_region_style.border_color,
border: hovered_region_style.border,
..renderer::Quad::default()
},
theme.hovered_region(style).background,
@ -948,9 +945,7 @@ pub fn draw<Renderer, T>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: hovered_region_style.border_radius,
border_width: hovered_region_style.border_width,
border_color: hovered_region_style.border_color,
border: hovered_region_style.border,
..renderer::Quad::default()
},
theme.hovered_region(style).background,

View file

@ -653,9 +653,7 @@ pub fn draw<'a, T, Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_color: style.border_color,
border_width: style.border_width,
border_radius: style.border_radius,
border: style.border,
..renderer::Quad::default()
},
style.background,

View file

@ -3,7 +3,7 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{Element, Layout, Length, Rectangle, Size, Widget};
use crate::core::{Border, Element, Layout, Length, Rectangle, Size, Widget};
use std::ops::RangeInclusive;
@ -130,7 +130,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle { ..bounds },
border_radius: style.border_radius,
border: Border::with_radius(style.border_radius),
..renderer::Quad::default()
},
style.background,
@ -143,7 +143,7 @@ where
width: active_progress_width,
..bounds
},
border_radius: style.border_radius,
border: Border::with_radius(style.border_radius),
..renderer::Quad::default()
},
style.bar,

View file

@ -9,7 +9,8 @@ use crate::core::touch;
use crate::core::widget;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Rectangle, Shell, Size, Widget,
Border, Clipboard, Element, Layout, Length, Pixels, Rectangle, Shell, Size,
Widget,
};
pub use iced_style::radio::{Appearance, StyleSheet};
@ -311,9 +312,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: (size / 2.0).into(),
border_width: custom_style.border_width,
border_color: custom_style.border_color,
border: Border {
radius: (size / 2.0).into(),
width: custom_style.border_width,
color: custom_style.border_color,
},
..renderer::Quad::default()
},
custom_style.background,
@ -328,7 +331,7 @@ where
width: bounds.width - dot_size,
height: bounds.height - dot_size,
},
border_radius: (dot_size / 2.0).into(),
border: Border::with_radius(dot_size / 2.0),
..renderer::Quad::default()
},
custom_style.dot_color,

View file

@ -3,7 +3,9 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{Element, Layout, Length, Pixels, Rectangle, Size, Widget};
use crate::core::{
Border, Element, Layout, Length, Pixels, Rectangle, Size, Widget,
};
pub use crate::style::rule::{Appearance, FillMode, StyleSheet};
@ -122,7 +124,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.radius,
border: Border::with_radius(style.radius),
..renderer::Quad::default()
},
style.color,

View file

@ -903,15 +903,13 @@ pub fn draw<Renderer>(
if scrollbar.bounds.width > 0.0
&& scrollbar.bounds.height > 0.0
&& (style.background.is_some()
|| (style.border_color != Color::TRANSPARENT
&& style.border_width > 0.0))
|| (style.border.color != Color::TRANSPARENT
&& style.border.width > 0.0))
{
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
border: style.border,
..renderer::Quad::default()
},
style
@ -924,15 +922,13 @@ pub fn draw<Renderer>(
if scrollbar.scroller.bounds.width > 0.0
&& scrollbar.scroller.bounds.height > 0.0
&& (style.scroller.color != Color::TRANSPARENT
|| (style.scroller.border_color != Color::TRANSPARENT
&& style.scroller.border_width > 0.0))
|| (style.scroller.border.color != Color::TRANSPARENT
&& style.scroller.border.width > 0.0))
{
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.scroller.bounds,
border_radius: style.scroller.border_radius,
border_width: style.scroller.border_width,
border_color: style.scroller.border_color,
border: style.scroller.border,
..renderer::Quad::default()
},
style.scroller.color,

View file

@ -8,8 +8,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
Widget,
Border, Clipboard, Element, Layout, Length, Pixels, Point, Rectangle,
Shell, Size, Widget,
};
use std::ops::RangeInclusive;
@ -398,7 +398,7 @@ pub fn draw<T, R>(
width: offset + handle_width / 2.0,
height: style.rail.width,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,
@ -412,7 +412,7 @@ pub fn draw<T, R>(
width: bounds.width - offset - handle_width / 2.0,
height: style.rail.width,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
@ -426,9 +426,11 @@ pub fn draw<T, R>(
width: handle_width,
height: handle_height,
},
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
border: Border {
radius: handle_border_radius,
width: style.handle.border_width,
color: style.handle.border_color,
},
..renderer::Quad::default()
},
style.handle.color,

View file

@ -466,9 +466,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,

View file

@ -1082,9 +1082,7 @@ pub fn draw<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,

View file

@ -9,8 +9,8 @@ use crate::core::touch;
use crate::core::widget;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Size,
Widget,
Border, Clipboard, Element, Event, Layout, Length, Pixels, Rectangle,
Shell, Size, Widget,
};
pub use crate::style::toggler::{Appearance, StyleSheet};
@ -312,11 +312,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_background_bounds,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.background_border
.unwrap_or(style.background),
border: Border {
radius: border_radius.into(),
width: 1.0,
color: style.background_border.unwrap_or(style.background),
},
..renderer::Quad::default()
},
style.background,
@ -337,11 +337,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_foreground_bounds,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.foreground_border
.unwrap_or(style.foreground),
border: Border {
radius: border_radius.into(),
width: 1.0,
color: style.foreground_border.unwrap_or(style.foreground),
},
..renderer::Quad::default()
},
style.foreground,

View file

@ -13,7 +13,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Length, Pixels, Point, Rectangle, Shell, Size, Widget,
Border, Clipboard, Element, Length, Pixels, Point, Rectangle, Shell, Size,
Widget,
};
/// An vertical bar and a handle that selects a single value from a range of
@ -396,7 +397,7 @@ pub fn draw<T, R>(
width: style.rail.width,
height: offset + handle_width / 2.0,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
@ -410,7 +411,7 @@ pub fn draw<T, R>(
width: style.rail.width,
height: bounds.height - offset - handle_width / 2.0,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,
@ -424,9 +425,11 @@ pub fn draw<T, R>(
width: handle_height,
height: handle_width,
},
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
border: Border {
radius: handle_border_radius,
width: style.handle.border_width,
color: style.handle.border_color,
},
..renderer::Quad::default()
},
style.handle.color,