mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
docs: Clarify Transform.rotate origin interaction with alignment (#163934)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This commit improves the documentation for Transform.rotate's origin property to clarify its interaction with the alignment property. Before: The documentation did not clearly explain how the origin offset interacts with the alignment property, potentially leading to confusion about the actual rotation point. After: The documentation now emphasizes that the origin offset is applied after the alignment transformation, and provides examples to avoid common misinterpretations. This change ensures developers can correctly position the rotation point. --------- Co-authored-by: Greg Price <gnprice@gmail.com>
This commit is contained in:
parent
5e74afc4da
commit
83c7108c99
@ -1722,15 +1722,50 @@ class Transform extends SingleChildRenderObjectWidget {
|
||||
/// The matrix to transform the child by during painting.
|
||||
final Matrix4 transform;
|
||||
|
||||
/// The origin of the coordinate system (relative to the upper left corner of
|
||||
/// this render object) in which to apply the matrix.
|
||||
/// 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 in this
|
||||
/// example, the child is rotated about its center, since [alignment]
|
||||
/// in [Transform.rotate] defaults to [Alignment.center]:
|
||||
///
|
||||
/// ```dart
|
||||
/// Transform.rotate(
|
||||
/// angle: math.pi,
|
||||
/// child: Container(
|
||||
/// width: 150.0,
|
||||
/// height: 150.0,
|
||||
/// color: Colors.blue,
|
||||
/// ),
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// However, in this example the [origin] offset is applied after the
|
||||
/// `alignment`, so the child rotates about its bottom-right corner:
|
||||
///
|
||||
/// ```dart
|
||||
/// Transform.rotate(
|
||||
/// angle: math.pi,
|
||||
/// origin: const Offset(75.0, 75.0),
|
||||
/// child: Container(
|
||||
/// width: 150.0,
|
||||
/// height: 150.0,
|
||||
/// color: Colors.blue,
|
||||
/// ),
|
||||
/// )
|
||||
/// ```
|
||||
final Offset? origin;
|
||||
|
||||
/// The alignment of the origin, relative to the size of the box.
|
||||
///
|
||||
/// When this and [origin] are both null, the origin is the upper-left corner
|
||||
/// of this render object.
|
||||
/// The default for this field is null for some constructors,
|
||||
/// and [Alignment.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.
|
||||
///
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user