summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/border.rs54
-rw-r--r--core/src/element.rs12
-rw-r--r--core/src/lib.rs6
-rw-r--r--core/src/renderer.rs21
-rw-r--r--core/src/shadow.rs14
5 files changed, 94 insertions, 13 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 8b510218..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,9 +538,12 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
- border_color: color,
- border_width: 1.0,
- border_radius: 0.0.into(),
+ 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 864df6e6..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;
@@ -36,7 +37,6 @@ pub mod window;
mod angle;
mod background;
-mod border_radius;
mod color;
mod content_fit;
mod element;
@@ -46,6 +46,7 @@ mod padding;
mod pixels;
mod point;
mod rectangle;
+mod shadow;
mod shell;
mod size;
mod vector;
@@ -53,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;
@@ -70,6 +71,7 @@ pub use pixels::Pixels;
pub use point::Point;
pub use rectangle::Rectangle;
pub use renderer::Renderer;
+pub use shadow::Shadow;
pub use shell::Shell;
pub use size::Size;
pub use text::Text;
diff --git a/core/src/renderer.rs b/core/src/renderer.rs
index 1b327e56..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, 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,14 +37,21 @@ 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 [`Shadow`] of the [`Quad`].
+ pub shadow: Shadow,
+}
- /// The border color of the [`Quad`].
- pub border_color: Color,
+impl Default for Quad {
+ fn default() -> Self {
+ Self {
+ bounds: Rectangle::with_size(Size::ZERO),
+ border: Border::default(),
+ shadow: Shadow::default(),
+ }
+ }
}
/// The styling attributes of a [`Renderer`].
diff --git a/core/src/shadow.rs b/core/src/shadow.rs
new file mode 100644
index 00000000..803101ed
--- /dev/null
+++ b/core/src/shadow.rs
@@ -0,0 +1,14 @@
+use crate::{Color, Vector};
+
+/// A shadow.
+#[derive(Debug, Clone, Copy, PartialEq, Default)]
+pub struct Shadow {
+ /// The color of the shadow.
+ pub color: Color,
+
+ /// The offset of the shadow.
+ pub offset: Vector,
+
+ /// The blur radius of the shadow.
+ pub blur_radius: f32,
+}