silk.geometry.insets.
Distances inward from the four edges of a box, over any number type.
When to use#
Use Insets for margins, padding, borders, or any other amount that grows or shrinks a
rectangle on each side. silk.geometry.rect.Rect.inflate applies one to a rectangle.
Details#
An insets value is a Copy struct with public top, right, bottom, and left fields,
generic over its number type T. top applies to the minimum y edge and bottom to the
maximum y edge, which matches a y-down space such as CSS or SVG. insets + insets adds each
side, and &a == &b compares every side when T: Equal.
Examples#
Sum padding and a border#
import silk.geometry.insets { Insets }
pub fn main() -> i32 {
let padding = Insets<f64>.uniform(8.0)
let border = Insets<f64>.new(1.0, 2.0, 1.0, 2.0)
let total = padding + border
if total.horizontal() != 20.0 || total.vertical() != 18.0 {
return 1
}
return 0
}Import as Insets with import silk.geometry.insets { Insets }.
Public declarations: 1.
Insets#
pub struct Insets<T>The distances of number type T from the four edges of a box.
When to use#
Use Insets for margins, padding, borders, or safe areas. Pass one to
silk.geometry.rect.Rect.inflate to grow a rectangle, or negate the sides to shrink it.
Details#
The fields are public. top applies to the minimum y edge and bottom to the maximum y edge,
as in CSS and SVG. insets + insets adds each side, and &a == &b compares every side, when
T has the operator.
Field top#
pub top: TThe distance from the minimum y edge.
Field right#
pub right: TThe distance from the maximum x edge.
Field bottom#
pub bottom: TThe distance from the maximum y edge.
Field left#
pub left: TThe distance from the minimum x edge.
Implementation Copy for Insets<T>#
impl<T: Copy> Copy for Insets<T>Implementation Insets<T>#
impl<T> Insets<T>Associated function new#
pub fn new(top: T, right: T, bottom: T, left: T) -> Insets<T>Returns the insets with top, right, bottom, and left, in the CSS order.
Implementation Insets<T>#
impl<T: Copy> Insets<T>Associated function uniform#
pub fn uniform(value: T) -> Insets<T>Returns the insets whose four sides are all value.
Implementation Insets<T>#
impl<T: Zero> Insets<T>Associated function zero#
pub fn zero() -> Insets<T>Returns the insets whose four sides are zero.
Implementation Insets<T>#
impl<T: Copy + Add<T, T>> Insets<T>Method horizontal#
pub fn horizontal(self: Self) -> TReturns left + right, the total inset along the x axis.
Method vertical#
pub fn vertical(self: Self) -> TReturns top + bottom, the total inset along the y axis.
Implementation Add<Insets<T>, Insets<T>> for Insets<T>#
impl<T: Add<T, T>> Add<Insets<T>, Insets<T>> for Insets<T>Operation add#
fn add(left: Self, right: Self) -> SelfImplementation Equal for Insets<T>#
impl<T: Equal> Equal for Insets<T>Operation equals#
fn equals(left: &Self, right: &Self) -> boolCategory: Geometry.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.