pub struct Rect {
pub left: f32,
pub top: f32,
pub right: f32,
pub bottom: f32,
}Expand description
A rectangle in user coordinates.
Fields§
§left: f32§top: f32§right: f32§bottom: f32Implementations§
Source§impl Rect
impl Rect
pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Rect
pub fn from_size(width: f32, height: f32) -> Rect
pub fn width(&self) -> f32
pub fn height(&self) -> f32
pub fn is_empty(&self) -> bool
Sourcepub fn outset(self, reach: f32) -> Rect
pub fn outset(self, reach: f32) -> Rect
The same rectangle, grown by reach on every side.
What a blur needs from the bounds of what it blurs: the result spreads outward, so a target sized to the content alone cuts the halo off square at the edge – the failure looking exactly like a shadow with a straight side. Written once because it was written out twice, four lines at a time, and a third place needs it with one side extended further.
Sourcepub fn to_rounded_path(self, radius: f32) -> Path
pub fn to_rounded_path(self, radius: f32) -> Path
This rectangle with its corners rounded to radius.
The radius is clamped to half the shorter side. Larger is not an error worth refusing – a caller asking for a fully rounded end usually says so by passing something enormous – and left unclamped the corner arcs would overlap and the outline would cross itself, which fills as something nobody asked for. Clamped, the shape degenerates to a stadium and then a circle, which is what asking for a huge radius means.
A radius at or below zero gives the plain rectangle, so a caller can pass a radius that happens to be zero without special-casing it.
Sourcepub fn to_rounded_path_with_radii(self, radii: [[f32; 2]; 4]) -> Path
pub fn to_rounded_path_with_radii(self, radii: [[f32; 2]; 4]) -> Path
This rectangle with each corner rounded to its own pair of radii.
The eight numbers dart:ui’s RRect carries, in upstream’s order:
top-left, top-right, bottom-left, bottom-right, each an x radius and a
y radius. Self::to_rounded_path is this with all four the same and
circular, and goes through the same code.
Sourcepub fn add_rounded_outline(self, path: &mut PathBuilder, radii: [[f32; 2]; 4])
pub fn add_rounded_outline(self, path: &mut PathBuilder, radii: [[f32; 2]; 4])
Add this rectangle’s rounded outline to a path already being built.
Self::to_rounded_path_with_radii is this and nothing else when the
path holds one contour. It is public for the case that one cannot
serve: a shape made of two of these – the ring drawDRRect fills, or a
caller’s own compound outline – needs both contours in one path, and a
path built from two paths is not something this crate offers.
The radii are fitted on the way in, so a
caller passing radii that overrun a side gets the same scaling
drawRRect would apply rather than an outline that crosses itself.