pub struct Border {
pub widths: EdgeInsets,
pub colors: EdgeColors,
pub style: BorderStyle,
}Expand description
Layout-aware box border.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert!(Border::new(1.0, Color::WHITE).is_visible());Fields§
§widths: EdgeInsetsRequested per-edge thicknesses in logical pixels.
colors: EdgeColorsPer-edge linear-RGBA colors.
style: BorderStyleStroke pattern; BorderStyle::None disables all layout thickness.
Implementations§
Source§impl Border
impl Border
Sourcepub const fn new(width: f32, color: Color) -> Self
pub const fn new(width: f32, color: Color) -> Self
Creates a uniform solid border with the given width and color.
Width is stored verbatim; layout and visibility treat negative values as
zero through Self::layout_widths.
§Examples
use ailloli_ui_core::style::{Border, BorderStyle, Color};
assert_eq!(Border::new(2.0, Color::WHITE).style, BorderStyle::Solid);Sourcepub const fn none() -> Self
pub const fn none() -> Self
Creates a transparent zero-width BorderStyle::None border.
§Examples
use ailloli_ui_core::style::Border;
assert!(!Border::none().is_visible());Sourcepub fn with_width(self, width: f32) -> Self
pub fn with_width(self, width: f32) -> Self
Replaces all edge widths and enables BorderStyle::Solid when positive.
Zero or negative widths do not disable an already enabled style.
§Examples
use ailloli_ui_core::style::Border;
assert_eq!(Border::none().with_width(2.0).layout_widths().left, 2.0);Sourcepub fn with_color(self, color: Color) -> Self
pub fn with_color(self, color: Color) -> Self
Replaces all edge colors and may enable a previously disabled border.
Auto-enabling requires positive alpha and a positive sum of the raw widths. A transparent color does not disable an existing style.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::new(1.0, Color::BLACK).with_color(Color::WHITE).uniform_color(), Some(Color::WHITE));Sourcepub fn with_left(self, width: f32, color: Color) -> Self
pub fn with_left(self, width: f32, color: Color) -> Self
Replaces the left width/color and enables a disabled style if width is positive.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::none().with_left(2.0, Color::WHITE).layout_widths().left, 2.0);Sourcepub fn with_top(self, width: f32, color: Color) -> Self
pub fn with_top(self, width: f32, color: Color) -> Self
Replaces the top width/color and enables a disabled style if width is positive.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::none().with_top(2.0, Color::WHITE).layout_widths().top, 2.0);Sourcepub fn with_right(self, width: f32, color: Color) -> Self
pub fn with_right(self, width: f32, color: Color) -> Self
Replaces the right width/color and enables a disabled style if width is positive.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::none().with_right(2.0, Color::WHITE).layout_widths().right, 2.0);Sourcepub fn with_bottom(self, width: f32, color: Color) -> Self
pub fn with_bottom(self, width: f32, color: Color) -> Self
Replaces the bottom width/color and enables a disabled style if width is positive.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::none().with_bottom(2.0, Color::WHITE).layout_widths().bottom, 2.0);Sourcepub fn layout_widths(&self) -> EdgeInsets
pub fn layout_widths(&self) -> EdgeInsets
Returns non-negative per-edge layout thicknesses in logical pixels.
BorderStyle::None returns four zeros regardless of stored widths.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::new(-2.0, Color::WHITE).layout_widths().left, 0.0);Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Returns whether at least one edge has positive width and alpha.
A BorderStyle::None border is never visible.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert!(Border::new(1.0, Color::WHITE).is_visible());Sourcepub fn is_uniform(&self) -> bool
pub fn is_uniform(&self) -> bool
Returns whether effective widths and all four colors are exactly equal.
This can be true for an invisible uniform border.
§Examples
use ailloli_ui_core::style::Border;
assert!(Border::none().is_uniform());Sourcepub fn uniform_width(&self) -> Option<f32>
pub fn uniform_width(&self) -> Option<f32>
Returns one effective width when all four layout widths are exactly equal.
BorderStyle::None therefore returns Some(0.0).
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::new(2.0, Color::WHITE).uniform_width(), Some(2.0));Sourcepub fn uniform_color(&self) -> Option<Color>
pub fn uniform_color(&self) -> Option<Color>
Returns one color when all four stored colors are exactly equal.
§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::new(2.0, Color::WHITE).uniform_color(), Some(Color::WHITE));Sourcepub fn deflate_rect(&self, rect: Rect) -> Rect
pub fn deflate_rect(&self, rect: Rect) -> Rect
Insets a rectangle by effective border widths.
The returned width and height are floored at zero; its origin still advances by the left and top widths when the border exceeds the box.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::new(2.0, Color::WHITE).deflate_rect(Rect::new(0.0, 0.0, 10.0, 10.0)), Rect::new(2.0, 2.0, 6.0, 6.0));Sourcepub fn inner_radius(&self, radius: Radius) -> Radius
pub fn inner_radius(&self, radius: Radius) -> Radius
Derives non-negative radii for the border’s inner contour.
Each outer corner subtracts the greater adjacent effective edge width.
§Examples
use ailloli_ui_core::style::{Border, Color, Radius};
assert_eq!(Border::new(2.0, Color::WHITE).inner_radius(Radius::uniform(5.0)), Radius::uniform(3.0));