Skip to main content

FocusRingMetrics

Struct FocusRingMetrics 

Source
pub struct FocusRingMetrics {
    pub thickness: f32,
    pub offset: f32,
    pub corner_radius: f32,
    pub color: Color,
    pub secondary_color: Option<Color>,
    pub style: FocusRingStyle,
}
Expand description

Metrics and styling parameters for rendering a native-grade visual focus ring conforming to platform guidelines and WCAG 2.4.7 / 2.4.11 / 2.4.13 requirements.

Fields§

§thickness: f32

Border thickness of the focus ring in pixels.

§offset: f32

Distance (gap) between the widget outer boundary and the focus ring. Positive values place the ring outside the widget; negative values inset it.

§corner_radius: f32

Corner rounding radius for rounded focus rings in pixels.

§color: Color

Primary stroke color of the focus ring.

§secondary_color: Option<Color>

Optional secondary contrasting color (used for dual-tone high-contrast rings or dotted alternating pixels).

§style: FocusRingStyle

Visual pattern of the focus indicator.

Implementations§

Source§

impl FocusRingMetrics

Source

pub const fn win32() -> Self

Preset conforming to modern Windows 11 Fluent Design guidelines (2px solid accent ring with 1px margin).

Source

pub const fn win32_classic() -> Self

Preset conforming to classic Windows Win32 DrawFocusRect (1px dotted black outline, 0px offset).

Source

pub const fn gtk() -> Self

Preset conforming to Linux GTK4 / GNOME Adwaita guidelines (2px solid accent ring with 2px offset).

Source

pub const fn cocoa() -> Self

Preset conforming to macOS AppKit / Cocoa focus halo standards (3px prominent halo with 1px offset).

Source

pub const fn high_contrast() -> Self

Preset conforming to WCAG 2.4.11 / 2.4.13 High Contrast requirements (dual-tone contrasting double ring).

Source

pub fn with_thickness(self, thickness: f32) -> Self

Sets the stroke thickness in pixels.

Source

pub fn with_offset(self, offset: f32) -> Self

Sets the offset gap from the widget boundary.

Source

pub fn with_corner_radius(self, corner_radius: f32) -> Self

Sets the corner rounding radius.

Source

pub fn with_color(self, color: Color) -> Self

Sets the primary stroke color.

Source

pub fn with_secondary_color(self, secondary: Color) -> Self

Sets an optional secondary contrasting color.

Source

pub fn with_style(self, style: FocusRingStyle) -> Self

Sets the visual style pattern.

Source

pub fn compute_outer_bounds(&self, widget_bounds: FocusRect) -> FocusRect

Computes the outer bounding rectangle enclosing the entire focus ring.

Source

pub fn compute_inner_bounds(&self, widget_bounds: FocusRect) -> FocusRect

Computes the inner edge rectangle enclosed by the focus ring.

Source

pub fn compute_ring_rect(&self, widget_bounds: FocusRect) -> FocusRect

Computes the midline stroke rectangle used for rendering lines/borders.

Source

pub fn relative_luminance(color: Color) -> f64

Calculates the WCAG 2.1 relative luminance of an sRGB color ($0.0 \le L \le 1.0$).

Source

pub fn contrast_ratio(c1: Color, c2: Color) -> f64

Computes the WCAG 2.1 contrast ratio between two colors ($1.0 \le \text{ratio} \le 21.0$).

Source

pub fn meets_wcag_contrast(&self, background: Color) -> bool

Returns true if the focus ring color achieves at least a 3.0:1 contrast ratio against the provided background color (WCAG 2.1 Success Criterion 1.4.11 / 2.4.11).

Trait Implementations§

Source§

impl Clone for FocusRingMetrics

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for FocusRingMetrics

Source§

impl Debug for FocusRingMetrics

Source§

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

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

impl Default for FocusRingMetrics

Source§

fn default() -> Self

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

impl PartialEq for FocusRingMetrics

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FocusRingMetrics

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.