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 givenBoxFitdiscipline.- The catalog of layout widgets.
Dart’s named constructors are the associated functions rotate,
translate, scale, and flip.
Fields§
§key: Option<KeyRef>§transform: Matrix4The 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: boolWhether 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
impl Transform
Sourcepub fn new(transform: Matrix4) -> Transform
pub fn new(transform: Matrix4) -> Transform
Creates a widget that transforms its child; Dart’s optional named arguments are the setters.
Sourcepub fn rotate(angle: f64) -> Transform
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.
Sourcepub fn translate(offset: Offset) -> Transform
pub fn translate(offset: Offset) -> Transform
Creates a widget that transforms its child using a translation.
The offset argument specifies the translation.
Sourcepub fn scale(
scale: Option<f64>,
scale_x: Option<f64>,
scale_y: Option<f64>,
) -> Transform
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.
Sourcepub fn flip(flip_x: bool, flip_y: bool) -> Transform
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.
Sourcepub fn alignment(self, alignment: AlignmentGeometry) -> Transform
pub fn alignment(self, alignment: AlignmentGeometry) -> Transform
Dart Transform(alignment:).
Sourcepub fn transform_hit_tests(self, transform_hit_tests: bool) -> Transform
pub fn transform_hit_tests(self, transform_hit_tests: bool) -> Transform
Dart Transform(transformHitTests:).
Sourcepub fn filter_quality(self, filter_quality: FilterQuality) -> Transform
pub fn filter_quality(self, filter_quality: FilterQuality) -> Transform
Dart Transform(filterQuality:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> Transform
pub fn child<K>(self, child: impl IntoWidget<K>) -> Transform
Dart Transform(child:).
Trait Implementations§
Source§impl RenderObjectWidget for Transform
impl RenderObjectWidget for Transform
Source§type RenderObject = RenderTransform
type RenderObject = RenderTransform
covariant RenderObject parameter type.Source§fn create_render_object(
&self,
app: &mut App,
context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
context: BuildContext,
render_object: RenderHandle<RenderTransform>,
)
fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderTransform>, )
create_render_object. Read moreSource§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
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>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.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
impl Move for Transform
impl Unpin for Transform
impl UnsafeUnpin for Transformwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.