diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/border.rs | 54 | ||||
-rw-r--r-- | core/src/element.rs | 10 | ||||
-rw-r--r-- | core/src/lib.rs | 6 | ||||
-rw-r--r-- | core/src/renderer.rs | 22 | ||||
-rw-r--r-- | core/src/shadow.rs | 11 |
5 files changed, 76 insertions, 27 deletions
diff --git a/core/src/border.rs b/core/src/border.rs new file mode 100644 index 00000000..21823341 --- /dev/null +++ b/core/src/border.rs @@ -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 + } +} diff --git a/core/src/element.rs b/core/src/element.rs index e57ad777..4d4bfa36 100644 --- a/core/src/element.rs +++ b/core/src/element.rs @@ -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, diff --git a/core/src/lib.rs b/core/src/lib.rs index b326d0f3..bbc973f0 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 1ca62559..a2a66aa8 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -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(), } } } diff --git a/core/src/shadow.rs b/core/src/shadow.rs index de8ce1c3..803101ed 100644 --- a/core/src/shadow.rs +++ b/core/src/shadow.rs @@ -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, } |