FractionalOffset class
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 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.
Historically, FractionalOffset predates Alignment. When we attempted to make a version of FractionalOffset that adapted to the TextDirection, we ran into difficulty because placing the origin in the top-left corner introduced a left-to-right bias that was hard to remove.
By placing the origin in the center, Alignment and AlignmentDirectional are able to use the same origin, which means we can use a linear function to resolve an AlignmentDirectional into an Alignment in both TextDirection.rtl and TextDirection.ltr.
Alignment is better for most purposes than FractionalOffset and should be used instead of FractionalOffset. We continue to implement FractionalOffset to support code that predates Alignment.
See also:
- Alignment, which uses a coordinate system based on the center of the rectangle instead of the top left corner of the rectangle.
- Inheritance
-
- Object
- AlignmentGeometry
- Alignment
- FractionalOffset
- Annotations
Constructors
- FractionalOffset(double dx, double dy)
-
Creates a fractional offset.
const
- FractionalOffset.fromOffsetAndRect(Offset offset, Rect rect)
-
Creates a fractional offset from a specific offset and rectangle.
factory
- FractionalOffset.fromOffsetAndSize(Offset offset, Size size)
-
Creates a fractional offset from a specific offset and size.
factory
Properties
- dx → double
-
The distance fraction in the horizontal direction.
no setter
- dy → double
-
The distance fraction in the vertical direction.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- x → double
-
The distance fraction in the horizontal direction.
finalinherited
- y → double
-
The distance fraction in the vertical direction.
finalinherited
Methods
-
add(
AlignmentGeometry other) → AlignmentGeometry -
Returns the sum of two AlignmentGeometry objects.
inherited
-
alongOffset(
Offset other) → Offset -
Returns the offset that is this fraction in the direction of the given offset.
inherited
-
alongSize(
Size other) → Offset -
Returns the offset that is this fraction within the given size.
inherited
-
inscribe(
Size size, Rect rect) → Rect -
Returns a rect of the given size, aligned within given rect as specified
by this alignment.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolve(
TextDirection? direction) → Alignment -
Convert this instance into an Alignment, which uses literal
coordinates (the
x
coordinate being explicitly a distance from the left).inherited -
toString(
) → String -
A string representation of this object.
override
-
withinRect(
Rect rect) → Offset -
Returns the point that is this fraction within the given rect.
inherited
Operators
-
operator %(
double other) → FractionalOffset -
Computes the remainder in each dimension by the given factor.
override
-
operator *(
double other) → FractionalOffset -
Scales the Alignment in each dimension by the given factor.
override
-
operator +(
Alignment other) → Alignment -
Returns the sum of two Alignments.
override
-
operator -(
Alignment other) → Alignment -
Returns the difference between two Alignments.
override
-
operator /(
double other) → FractionalOffset -
Divides the Alignment in each dimension by the given factor.
override
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator unary-(
) → FractionalOffset -
Returns the negation of the given Alignment.
override
-
operator ~/(
double other) → FractionalOffset -
Integer divides the Alignment in each dimension by the given factor.
override
Static Methods
-
lerp(
FractionalOffset? a, FractionalOffset? b, double t) → FractionalOffset? -
Linearly interpolate between two FractionalOffsets.
override
Constants
- bottomCenter → const FractionalOffset
- The center point along the bottom edge.
- bottomLeft → const FractionalOffset
- The bottom left corner.
- bottomRight → const FractionalOffset
- The bottom right corner.
- center → const FractionalOffset
- The center point, both horizontally and vertically.
- centerLeft → const FractionalOffset
- The center point along the left edge.
- centerRight → const FractionalOffset
- The center point along the right edge.
- topCenter → const FractionalOffset
- The center point along the top edge.
- topLeft → const FractionalOffset
- The top left corner.
- topRight → const FractionalOffset
- The top right corner.