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: f64The distance fraction in the horizontal direction in Alignment
coordinates (dx * 2 - 1).
y: f64The distance fraction in the vertical direction in Alignment
coordinates (dy * 2 - 1).
Implementations§
Source§impl FractionalOffset
impl FractionalOffset
Sourcepub const TOP_LEFT: FractionalOffset
pub const TOP_LEFT: FractionalOffset
The top left corner.
Sourcepub const TOP_CENTER: FractionalOffset
pub const TOP_CENTER: FractionalOffset
The center point along the top edge.
Sourcepub const TOP_RIGHT: FractionalOffset
pub const TOP_RIGHT: FractionalOffset
The top right corner.
Sourcepub const CENTER_LEFT: FractionalOffset
pub const CENTER_LEFT: FractionalOffset
The center point along the left edge.
Sourcepub const CENTER: FractionalOffset
pub const CENTER: FractionalOffset
The center point, both horizontally and vertically.
Sourcepub const CENTER_RIGHT: FractionalOffset
pub const CENTER_RIGHT: FractionalOffset
The center point along the right edge.
Sourcepub const BOTTOM_LEFT: FractionalOffset
pub const BOTTOM_LEFT: FractionalOffset
The bottom left corner.
Sourcepub const BOTTOM_CENTER: FractionalOffset
pub const BOTTOM_CENTER: FractionalOffset
The center point along the bottom edge.
Sourcepub const BOTTOM_RIGHT: FractionalOffset
pub const BOTTOM_RIGHT: FractionalOffset
The bottom right corner.
Sourcepub const fn new(dx: f64, dy: f64) -> FractionalOffset
pub const fn new(dx: f64, dy: f64) -> FractionalOffset
Creates a fractional offset.
Sourcepub fn from_offset_and_size(offset: Offset, size: Size) -> FractionalOffset
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.
Sourcepub fn from_offset_and_rect(offset: Offset, rect: Rect) -> FractionalOffset
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.
Sourcepub const fn dx(&self) -> f64
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.
Sourcepub const fn dy(&self) -> f64
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.
Sourcepub fn truncating_div(&self, other: f64) -> FractionalOffset
pub fn truncating_div(&self, other: f64) -> FractionalOffset
Integer divides the FractionalOffset in each dimension by the given
factor.
Sourcepub fn lerp(
a: Option<FractionalOffset>,
b: Option<FractionalOffset>,
t: f64,
) -> Option<FractionalOffset>
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
impl Add for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
+ operator.Source§fn add(self, other: FractionalOffset) -> FractionalOffset
fn add(self, other: FractionalOffset) -> FractionalOffset
+ operation. Read moreSource§impl Add<Alignment> for FractionalOffset
impl Add<Alignment> for FractionalOffset
Source§impl Clone for FractionalOffset
impl Clone for FractionalOffset
Source§fn clone(&self) -> FractionalOffset
fn clone(&self) -> FractionalOffset
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FractionalOffset
Source§impl Debug for FractionalOffset
impl Debug for FractionalOffset
Source§impl Div<f64> for FractionalOffset
impl Div<f64> for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
/ operator.Source§impl From<FractionalOffset> for Alignment
impl From<FractionalOffset> for Alignment
Source§fn from(offset: FractionalOffset) -> Alignment
fn from(offset: FractionalOffset) -> Alignment
Source§impl Mul<f64> for FractionalOffset
impl Mul<f64> for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
* operator.Source§impl Neg for FractionalOffset
impl Neg for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
- operator.Source§fn neg(self) -> FractionalOffset
fn neg(self) -> FractionalOffset
- operation. Read moreSource§impl PartialEq for FractionalOffset
impl PartialEq for FractionalOffset
Source§impl PartialEq<Alignment> for FractionalOffset
impl PartialEq<Alignment> for FractionalOffset
Source§impl PartialEq<FractionalOffset> for Alignment
impl PartialEq<FractionalOffset> for Alignment
Source§impl Rem<f64> for FractionalOffset
impl Rem<f64> for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
% operator.impl StructuralPartialEq for FractionalOffset
Source§impl Sub for FractionalOffset
impl Sub for FractionalOffset
Source§type Output = FractionalOffset
type Output = FractionalOffset
- operator.Source§fn sub(self, other: FractionalOffset) -> FractionalOffset
fn sub(self, other: FractionalOffset) -> FractionalOffset
- operation. Read more