Skip to main content

FractionalOffset

Struct FractionalOffset 

Source
pub struct FractionalOffset {
    pub x: f64,
    pub y: f64,
}
Expand description

An offset that’s expressed as a fraction of a Size.

FractionalOffset(1.0, 0.0) represents the top right of the Size.

FractionalOffset(0.0, 1.0) represents the bottom left of the Size.

FractionalOffset(0.5, 2.0) represents a point half way across the Size, below the bottom of the rectangle by the height of the Size.

The FractionalOffset class specifies offsets in terms of a distance from the top left, regardless of the crate::TextDirection.

§Design discussion

FractionalOffset and Alignment are two different representations of the same information: the location within a rectangle relative to the size of the rectangle. The difference between the two classes is in the coordinate system they use to represent the location.

FractionalOffset uses a coordinate system with an origin in the top-left corner of the rectangle whereas Alignment uses a coordinate system with an origin in the center of the rectangle.

See also:

  • Alignment, which uses a coordinate system based on the center of the rectangle instead of the top left corner of the rectangle.

Fields§

§x: f64

The distance fraction in the horizontal direction in Alignment coordinates (dx * 2 - 1).

§y: f64

The distance fraction in the vertical direction in Alignment coordinates (dy * 2 - 1).

Implementations§

Source§

impl FractionalOffset

Source

pub const TOP_LEFT: FractionalOffset

The top left corner.

Source

pub const TOP_CENTER: FractionalOffset

The center point along the top edge.

Source

pub const TOP_RIGHT: FractionalOffset

The top right corner.

Source

pub const CENTER_LEFT: FractionalOffset

The center point along the left edge.

Source

pub const CENTER: FractionalOffset

The center point, both horizontally and vertically.

Source

pub const CENTER_RIGHT: FractionalOffset

The center point along the right edge.

Source

pub const BOTTOM_LEFT: FractionalOffset

The bottom left corner.

Source

pub const BOTTOM_CENTER: FractionalOffset

The center point along the bottom edge.

Source

pub const BOTTOM_RIGHT: FractionalOffset

The bottom right corner.

Source

pub const fn new(dx: f64, dy: f64) -> FractionalOffset

Creates a fractional offset.

Source

pub fn from_offset_and_size(offset: Offset, size: Size) -> FractionalOffset

Creates a fractional offset from a specific offset and size.

The returned FractionalOffset describes the position of the Offset in the Size, as a fraction of the Size.

Source

pub fn from_offset_and_rect(offset: Offset, rect: Rect) -> FractionalOffset

Creates a fractional offset from a specific offset and rectangle.

The offset is assumed to be relative to the same origin as the rectangle.

If the offset is relative to the top left of the rectangle, use from_offset_and_size instead, passing rect.size().

The returned FractionalOffset describes the position of the Offset in the Rect, as a fraction of the Rect.

Source

pub const fn dx(&self) -> f64

The distance fraction in the horizontal direction.

A value of 0.0 corresponds to the leftmost edge. A value of 1.0 corresponds to the rightmost edge. Values are not limited to that range; negative values represent positions to the left of the left edge, and values greater than 1.0 represent positions to the right of the right edge.

Source

pub const fn dy(&self) -> f64

The distance fraction in the vertical direction.

A value of 0.0 corresponds to the topmost edge. A value of 1.0 corresponds to the bottommost edge. Values are not limited to that range; negative values represent positions above the top, and values greater than 1.0 represent positions below the bottom.

Source

pub fn truncating_div(&self, other: f64) -> FractionalOffset

Integer divides the FractionalOffset in each dimension by the given factor.

Source

pub fn lerp( a: Option<FractionalOffset>, b: Option<FractionalOffset>, t: f64, ) -> Option<FractionalOffset>

Linearly interpolate between two FractionalOffsets.

If either is null, this function interpolates from FractionalOffset::CENTER.

Trait Implementations§

Source§

impl Add for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the + operator.
Source§

fn add(self, other: FractionalOffset) -> FractionalOffset

Performs the + operation. Read more
Source§

impl Add<Alignment> for FractionalOffset

Source§

type Output = Alignment

The resulting type after applying the + operator.
Source§

fn add(self, other: Alignment) -> Alignment

Performs the + operation. Read more
Source§

impl Clone for FractionalOffset

Source§

fn clone(&self) -> FractionalOffset

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 FractionalOffset

Source§

impl Debug for FractionalOffset

Source§

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

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

impl Div<f64> for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the / operator.
Source§

fn div(self, other: f64) -> FractionalOffset

Performs the / operation. Read more
Source§

impl From<FractionalOffset> for Alignment

Source§

fn from(offset: FractionalOffset) -> Alignment

Converts to this type from the input type.
Source§

impl Mul<f64> for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the * operator.
Source§

fn mul(self, other: f64) -> FractionalOffset

Performs the * operation. Read more
Source§

impl Neg for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the - operator.
Source§

fn neg(self) -> FractionalOffset

Performs the unary - operation. Read more
Source§

impl PartialEq for FractionalOffset

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Alignment> for FractionalOffset

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<FractionalOffset> for Alignment

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Rem<f64> for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the % operator.
Source§

fn rem(self, other: f64) -> FractionalOffset

Performs the % operation. Read more
Source§

impl StructuralPartialEq for FractionalOffset

Source§

impl Sub for FractionalOffset

Source§

type Output = FractionalOffset

The resulting type after applying the - operator.
Source§

fn sub(self, other: FractionalOffset) -> FractionalOffset

Performs the - operation. Read more
Source§

impl Sub<Alignment> for FractionalOffset

Source§

type Output = Alignment

The resulting type after applying the - operator.
Source§

fn sub(self, other: Alignment) -> Alignment

Performs the - operation. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,