Skip to main content

Transform

Struct Transform 

Source
pub struct Transform {
    pub key: Option<KeyRef>,
    pub transform: Matrix4,
    pub origin: Option<Offset>,
    pub alignment: Option<AlignmentGeometry>,
    pub transform_hit_tests: bool,
    pub filter_quality: Option<FilterQuality>,
    pub child: Option<WidgetRef>,
}
Expand description

A widget that applies a transformation before painting its child.

Unlike RotatedBox, which applies a rotation prior to layout, this object applies its transformation just prior to painting, which means the transformation is not taken into account when calculating how much space this widget’s child (and thus this widget) consumes.

This example rotates and skews an orange box containing text, keeping the top right corner pinned to its original position.

ColoredBox::new(Color::BLACK).child(
    Transform::new(skew_y)
        .alignment(AlignmentGeometry::TOP_RIGHT)
        .child(Text::new("Apartment for rent!")),
)

See also:

  • RotatedBox, which rotates the child widget during layout, not just during painting.
  • FractionalTranslation, which applies a translation to the child that is relative to the child’s size.
  • FittedBox, which sizes and positions its child widget to fit the parent according to a given BoxFit discipline.
  • The catalog of layout widgets.

Dart’s named constructors are the associated functions rotate, translate, scale, and flip.

Fields§

§key: Option<KeyRef>§transform: Matrix4

The matrix to transform the child by during painting.

§origin: Option<Offset>

The origin of the coordinate system in which to apply the matrix, described relative to the point given by alignment.

Setting an origin is equivalent to conjugating the transform matrix by a translation. This property is provided just for convenience.

This offset is applied in addition to any alignment transformation, so a rotate with no origin turns the child about its center, while Transform::rotate(PI).origin(Offset::new(75.0, 75.0)) on a 150x150 child turns it about its bottom-right corner.

§alignment: Option<AlignmentGeometry>

The alignment of the origin, relative to the size of the box.

When this and origin are both None, the origin is the upper-left corner of this render object. The default for this field is None for some constructors, and AlignmentGeometry::CENTER for others.

This is equivalent to setting an origin based on the size of the box. If it is specified at the same time as the origin, both are applied.

An AlignmentDirectional::CENTER_START value is the same as an Alignment whose x value is -1.0 if Directionality::of returns TextDirection::Ltr, and 1.0 if it returns TextDirection::Rtl. Similarly AlignmentDirectional::CENTER_END is the same as an Alignment whose x value is 1.0 if Directionality::of returns TextDirection::Ltr, and -1.0 if it returns TextDirection::Rtl.

§transform_hit_tests: bool

Whether to transform registered hits into the child’s resulting coordinate system.

When true, hit coordinates within the parent’s bounds are transformed to match where the child appears visually after any transformation such as translation, rotation, scaling, or skewing.

When false, hit coordinates are not transformed, potentially causing taps to register in a different location relative to the child’s visual position.

Important: Even when transform_hit_tests is true, children cannot receive events outside the parent’s bounds. Hit testing always starts with the parent’s own bounds check in RenderBox::hit_test. If the pointer is outside the parent’s bounds, RenderBox::hit_test_children is not invoked and the children are not considered for hit testing.

Defaults to true.

§filter_quality: Option<FilterQuality>

The filter quality with which to apply the transform as a bitmap operation.

The transform will be applied by re-rendering the child if filter_quality is None, otherwise it controls the quality of an ImageFilter.matrix applied to a bitmap rendering of the child.

§child: Option<WidgetRef>

Implementations§

Source§

impl Transform

Source

pub fn new(transform: Matrix4) -> Transform

Creates a widget that transforms its child; Dart’s optional named arguments are the setters.

Source

pub fn rotate(angle: f64) -> Transform

Creates a widget that transforms its child using a rotation around the center.

The angle argument gives the rotation in clockwise radians.

See also:

  • RotationTransition, which animates changes in rotation smoothly over a given duration.
Source

pub fn translate(offset: Offset) -> Transform

Creates a widget that transforms its child using a translation.

The offset argument specifies the translation.

Source

pub fn scale( scale: Option<f64>, scale_x: Option<f64>, scale_y: Option<f64>, ) -> Transform

Creates a widget that scales its child along the 2D plane.

The scale_x argument provides the scalar by which to multiply the x axis, and the scale_y argument provides the scalar by which to multiply the y axis. Either may be None, in which case the scaling factor for that axis defaults to 1.0.

For convenience, to scale the child uniformly, instead of providing scale_x and scale_y, the scale parameter may be used.

At least one of scale, scale_x, and scale_y must be non-None. If scale is provided, the other two must be None.

The alignment controls the origin of the scale; by default, this is the center of the box.

See also:

  • ScaleTransition, which animates changes in scale smoothly over a given duration.
Source

pub fn flip(flip_x: bool, flip_y: bool) -> Transform

Creates a widget that mirrors its child about the widget’s center point.

If flip_x is true, the child widget will be flipped horizontally.

If flip_y is true, the child widget will be flipped vertically.

If both are true, the child widget will be flipped both vertically and horizontally, equivalent to a 180 degree rotation.

Source

pub fn key(self, key: KeyRef) -> Transform

Dart Transform(key:).

Source

pub fn origin(self, origin: Offset) -> Transform

Dart Transform(origin:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> Transform

Dart Transform(alignment:).

Source

pub fn transform_hit_tests(self, transform_hit_tests: bool) -> Transform

Dart Transform(transformHitTests:).

Source

pub fn filter_quality(self, filter_quality: FilterQuality) -> Transform

Dart Transform(filterQuality:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> Transform

Dart Transform(child:).

Trait Implementations§

Source§

impl Debug for Transform

Source§

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

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

impl RenderObjectWidget for Transform

Source§

type RenderObject = RenderTransform

The render object this widget creates; Dart’s covariant RenderObject parameter type.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject

Creates an instance of the RenderObject class that this widget represents, using the configuration described by this widget. Read more
Source§

fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderTransform>, )

Copies the configuration described by this widget to the given render object, which will be of the same type as returned by this object’s create_render_object. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn to_string_short(&self) -> String

Dart’s toStringShort, for a widget that names itself apart from its type, as SizedBox.expand does; see Widget::to_string_short.
Source§

fn debug_check_constructor(&self)

Source§

fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )

Dart’s debugVisitOnstageChildren of the element this widget makes, for a widget whose Dart element subclass overrides it only to hide children (_OffstageElement, _IndexedStackElement): calls visitor for each of children, in order, that is onstage. Waft’s generic single- and multi-child elements stand in for those subclasses and ask their widget here; an element of a widget’s own overrides Element::debug_visit_onstage_children instead.
Source§

fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )

A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object’s create_render_object.
Source§

impl SingleChildRenderObjectWidget for Transform

Source§

fn child(&self) -> Option<&WidgetRef>

The widget below this widget in the tree.
Source§

fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement
where Self: Sized,

Creates the element that manages this widget’s child. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Transform

§

impl !Send for Transform

§

impl !Sync for Transform

§

impl !UnwindSafe for Transform

§

impl Forget for Transform

§

impl Freeze for Transform
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for Transform

§

impl Unpin for Transform
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Transform
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

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> 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<W> IntoWidget<SingleChildRenderObjectKind> for W

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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>