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: f32Border thickness of the focus ring in pixels.
offset: f32Distance (gap) between the widget outer boundary and the focus ring. Positive values place the ring outside the widget; negative values inset it.
corner_radius: f32Corner rounding radius for rounded focus rings in pixels.
color: ColorPrimary 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: FocusRingStyleVisual pattern of the focus indicator.
Implementations§
Source§impl FocusRingMetrics
impl FocusRingMetrics
Sourcepub const fn win32() -> Self
pub const fn win32() -> Self
Preset conforming to modern Windows 11 Fluent Design guidelines (2px solid accent ring with 1px margin).
Sourcepub const fn win32_classic() -> Self
pub const fn win32_classic() -> Self
Preset conforming to classic Windows Win32 DrawFocusRect (1px dotted black outline, 0px offset).
Sourcepub const fn gtk() -> Self
pub const fn gtk() -> Self
Preset conforming to Linux GTK4 / GNOME Adwaita guidelines (2px solid accent ring with 2px offset).
Sourcepub const fn cocoa() -> Self
pub const fn cocoa() -> Self
Preset conforming to macOS AppKit / Cocoa focus halo standards (3px prominent halo with 1px offset).
Sourcepub const fn high_contrast() -> Self
pub const fn high_contrast() -> Self
Preset conforming to WCAG 2.4.11 / 2.4.13 High Contrast requirements (dual-tone contrasting double ring).
Sourcepub fn with_thickness(self, thickness: f32) -> Self
pub fn with_thickness(self, thickness: f32) -> Self
Sets the stroke thickness in pixels.
Sourcepub fn with_offset(self, offset: f32) -> Self
pub fn with_offset(self, offset: f32) -> Self
Sets the offset gap from the widget boundary.
Sourcepub fn with_corner_radius(self, corner_radius: f32) -> Self
pub fn with_corner_radius(self, corner_radius: f32) -> Self
Sets the corner rounding radius.
Sourcepub fn with_color(self, color: Color) -> Self
pub fn with_color(self, color: Color) -> Self
Sets the primary stroke color.
Sourcepub fn with_secondary_color(self, secondary: Color) -> Self
pub fn with_secondary_color(self, secondary: Color) -> Self
Sets an optional secondary contrasting color.
Sourcepub fn with_style(self, style: FocusRingStyle) -> Self
pub fn with_style(self, style: FocusRingStyle) -> Self
Sets the visual style pattern.
Sourcepub fn compute_outer_bounds(&self, widget_bounds: FocusRect) -> FocusRect
pub fn compute_outer_bounds(&self, widget_bounds: FocusRect) -> FocusRect
Computes the outer bounding rectangle enclosing the entire focus ring.
Sourcepub fn compute_inner_bounds(&self, widget_bounds: FocusRect) -> FocusRect
pub fn compute_inner_bounds(&self, widget_bounds: FocusRect) -> FocusRect
Computes the inner edge rectangle enclosed by the focus ring.
Sourcepub fn compute_ring_rect(&self, widget_bounds: FocusRect) -> FocusRect
pub fn compute_ring_rect(&self, widget_bounds: FocusRect) -> FocusRect
Computes the midline stroke rectangle used for rendering lines/borders.
Sourcepub fn relative_luminance(color: Color) -> f64
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$).
Sourcepub fn contrast_ratio(c1: Color, c2: Color) -> f64
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$).
Sourcepub fn meets_wcag_contrast(&self, background: Color) -> bool
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).