Struct Border

Source
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: EdgeInsets

Requested per-edge thicknesses in logical pixels.

§colors: EdgeColors

Per-edge linear-RGBA colors.

§style: BorderStyle

Stroke pattern; BorderStyle::None disables all layout thickness.

Implementations§

Source§

impl Border

Source

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);
Source

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());
Source

pub const fn solid(width: f32, color: Color) -> Self

Alias for Self::new.

§Examples
use ailloli_ui_core::style::{Border, Color};
assert_eq!(Border::solid(2.0, Color::WHITE), Border::new(2.0, Color::WHITE));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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());
Source

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());
Source

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));
Source

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));
Source

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));
Source

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));

Trait Implementations§

Source§

impl Clone for Border

Source§

fn clone(&self) -> Border

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Border

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Border

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Border

Source§

fn eq(&self, other: &Border) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Border

Source§

impl StructuralPartialEq for Border

Auto Trait Implementations§

§

impl Freeze for Border

§

impl RefUnwindSafe for Border

§

impl Send for Border

§

impl Sync for Border

§

impl Unpin for Border

§

impl UnwindSafe for Border

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.