pub struct FocusRing {
pub color: [u8; 4],
pub width: f32,
pub offset: f32,
pub radius: f32,
}Expand description
Visual properties for a focus ring, consumed by renderers.
Describes the outline drawn around the currently-focused widget. All measurements are in logical pixels.
Fields§
§color: [u8; 4]Colour of the ring in RGBA byte order [r, g, b, a].
width: f32Stroke width in logical pixels.
offset: f32Outset distance from the widget’s bounding box in logical pixels.
radius: f32Corner radius of the ring in logical pixels (0.0 = sharp corners).
Implementations§
Source§impl FocusRing
impl FocusRing
Sourcepub fn ring_rect(
&self,
x: f32,
y: f32,
width: f32,
height: f32,
) -> (f32, f32, f32, f32)
pub fn ring_rect( &self, x: f32, y: f32, width: f32, height: f32, ) -> (f32, f32, f32, f32)
Compute the bounding rectangle for the ring given the widget’s bounding
box (x, y, width, height) in logical pixels.
Returns (rx, ry, rw, rh) where the ring is outset by self.offset on
all sides and the stroke of self.width is applied further outward.
This is the rectangle that a renderer should stroke / outline.
§Note for renderers
The returned rectangle is the outer boundary of the ring stroke.
Renderers should stroke the rectangle inward by self.width / 2.0 to
position the stroke centrally on the boundary.
§Example
use oxiui_accessibility::FocusRing;
let ring = FocusRing { width: 2.0, offset: 2.0, ..Default::default() };
let (rx, ry, rw, rh) = ring.ring_rect(10.0, 20.0, 100.0, 30.0);
// outset by offset (2) + half width (1) on each side
assert_eq!(rx, 10.0 - 2.0 - 1.0);
assert_eq!(ry, 20.0 - 2.0 - 1.0);
assert_eq!(rw, 100.0 + (2.0 + 1.0) * 2.0);
assert_eq!(rh, 30.0 + (2.0 + 1.0) * 2.0);Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Returns true when the ring should be rendered (i.e. it has a non-zero
stroke width and a non-fully-transparent colour).
Renderers may skip drawing the ring when this returns false.
§Example
use oxiui_accessibility::FocusRing;
let visible = FocusRing::default();
assert!(visible.is_visible());
let invisible = FocusRing { color: [0, 0, 0, 0], ..Default::default() };
assert!(!invisible.is_visible());Trait Implementations§
impl StructuralPartialEq for FocusRing
Auto Trait Implementations§
impl Freeze for FocusRing
impl RefUnwindSafe for FocusRing
impl Send for FocusRing
impl Sync for FocusRing
impl Unpin for FocusRing
impl UnsafeUnpin for FocusRing
impl UnwindSafe for FocusRing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more