Introduce Border struct analogous to Shadow
This commit is contained in:
parent
4d502012b3
commit
25f182f933
44 changed files with 382 additions and 424 deletions
54
core/src/border.rs
Normal file
54
core/src/border.rs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue