Add LayoutControl.transform for Matrix4 transformations and RotatedBox control#6198
Add LayoutControl.transform for Matrix4 transformations and RotatedBox control#6198FeodorFitsner wants to merge 7 commits intomainfrom
LayoutControl.transform for Matrix4 transformations and RotatedBox control#6198Conversation
Introduce native support for flipping and arbitrary matrix transforms across Dart and Python SDKs. Dart: extend LayoutControl to apply flip and generic Transform, replace AnimatedRotation/Scale/Slide with TweenAnimationBuilder+Transform to honor origin, transformHitTests and filterQuality, add fractional translate helper, and add parsers/details (FlipDetails, TransformDetails, Matrix4Recording) to transforms utilities. Python: add Flip, Transform and recorded Matrix4 types (with recording/multiplication APIs), export them, update LayoutControl typing and docs, and include examples (flip.py, matrix4_transform.py) plus mkdocs entries. This enables richer transform semantics and consistent serialization/replay of Matrix4 operations.
Replace manual size-based FractionalTranslate implementation with FractionalTranslation and conditionally wrap it in Transform.translate to apply filterQuality only when provided. Add and reorganize layout control examples: rename animated_offset to animate_offset and tweak animation params; add new examples offset.py, rotate.py, scale.py; add __main__ guards to flip and matrix4_transform examples. Update layoutcontrol docs to include example snippets and reference golden images. Add many golden images and new integration tests (controls and examples) to cover flip/rotate/scale/offset and various Matrix4 transforms.
Reorganize example controls into a new layout_control folder: rename bursting_flet.py, image_slideshow.py, and rocket.py under sdk/python/examples/controls/layout_control. Remove obsolete form_controls_misc.py. Add icon-192.png asset under layout_control/assets and update bursting_flet.py to use the new 'icon-192.png' image path.
Wrap FilterQuality type hints in string literals across transform controls (Scale, Rotate, Offset, Flip, Transform) to use forward references and avoid runtime/name-resolution issues with the type. This is a typing-only change and does not alter runtime behavior.
Introduce a new RotatedBox control across the codebase. - Flutter host: add RotatedBoxControl widget (packages/flet/lib/src/controls/rotated_box.dart) and register it in flet_core_extension. - Python SDK: add control wrapper (flet.controls.core.rotated_box.RotatedBox), export it in flet.__init__, and include API fields (quarter_turns, content). - Docs: add controls/rotatedbox.md and reference the example from layoutcontrol.md; update mkdocs navigation. - Examples & tests: add example (sdk/python/examples/controls/rotated_box/basic.py), integration tests, and golden images for screenshots. RotatedBox rotates its content by integral quarter turns before layout (affecting measured size).
Update RotationDetails, ScaleDetails and OffsetDetails to use optional parameters with sensible defaults (alignment defaults to Alignment.center, transformHitTests defaults to true, origin and filterQuality are nullable, scale/scaleX/scaleY made optional). Remove redundant explicit defaults from parse helpers (parseRotationDetails, parseScale, OffsetDetails.fromValue) so defaults are provided by the constructors. This centralizes default behavior and simplifies parsing logic in packages/flet/lib/src/utils/transforms.dart.
Deploying flet-docs with
|
| Latest commit: |
d2e317d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9628181d.flet-docs.pages.dev |
| Branch Preview URL: | https://matrix-transform.flet-docs.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR extends Flet’s layout transform capabilities across Python and Flutter by adding flip/matrix-based transforms (via a recorded Matrix4 API) and introducing a RotatedBox control that rotates before layout.
Changes:
- Add new transform configuration types in Python (
Flip,Matrix4,Transform) and expose them onLayoutControl(flip,transform). - Implement Flutter-side parsing and rendering for the new transform properties, plus add a new
RotatedBoxcontrol implementation. - Add docs, examples, and screenshot-based integration tests (including new golden images) covering flip, Matrix4 transforms, and RotatedBox.
Reviewed changes
Copilot reviewed 27 out of 43 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/transform.py | Adds Python-side Flip, Matrix4 recording, and Transform, plus extends rotate/scale/offset options. |
| sdk/python/packages/flet/src/flet/controls/layout_control.py | Exposes new flip and transform properties on LayoutControl and updates docs text. |
| sdk/python/packages/flet/src/flet/controls/core/rotated_box.py | Adds Python RotatedBox control API (quarter turns before layout). |
| sdk/python/packages/flet/src/flet/init.py | Exports RotatedBox, Flip, Matrix4, Transform at package top-level. |
| sdk/python/packages/flet/mkdocs.yml | Adds nav entries for new docs pages (RotatedBox, Flip, Matrix4, Transform). |
| sdk/python/packages/flet/docs/types/transform.md | New doc stub for flet.Transform. |
| sdk/python/packages/flet/docs/types/matrix4.md | New doc stub for flet.Matrix4. |
| sdk/python/packages/flet/docs/types/flip.md | New doc stub for flet.Flip. |
| sdk/python/packages/flet/docs/controls/rotatedbox.md | Adds RotatedBox control documentation page + example + image. |
| sdk/python/packages/flet/docs/controls/layoutcontrol.md | Expands LayoutControl docs with examples/images for flip/rotate/RotatedBox/scale/offset/matrix4. |
| sdk/python/examples/controls/rotated_box/basic.py | Adds RotatedBox example demonstrating layout impact vs paint-time rotate. |
| sdk/python/examples/controls/rotated_box/init.py | Adds example package marker. |
| sdk/python/examples/controls/layout_control/flip.py | Adds interactive flip example. |
| sdk/python/examples/controls/layout_control/rotate.py | Adds rotate example using extended rotate options. |
| sdk/python/examples/controls/layout_control/scale.py | Adds scale example using extended scale options. |
| sdk/python/examples/controls/layout_control/offset.py | Adds offset example using extended offset options. |
| sdk/python/examples/controls/layout_control/matrix4_transform.py | Adds Matrix4 recording/replay example. |
| sdk/python/examples/controls/layout_control/rocket.py | Adds/updates example using rotate/scale animations. |
| sdk/python/examples/controls/layout_control/image_slideshow.py | Adds/updates example using animated positioning. |
| sdk/python/examples/controls/layout_control/animate_offset.py | Tweaks offset animation parameters/curve for demo. |
| sdk/python/examples/controls/layout_control/bursting_flet.py | Adjusts example asset path reference. |
| sdk/python/examples/controls/layout_control/assets/icon-192.png | Adds example asset image. |
| sdk/python/packages/flet/integration_tests/examples/core/test_rotated_box.py | Adds example screenshot test for RotatedBox example app. |
| sdk/python/packages/flet/integration_tests/examples/core/test_layout_control.py | Adds example screenshot tests for flip and Matrix4 transform example apps. |
| sdk/python/packages/flet/integration_tests/controls/core/test_rotated_box.py | Adds control-level screenshot test for RotatedBox. |
| sdk/python/packages/flet/integration_tests/controls/core/test_layout_control.py | Adds control-level screenshot tests for flip/rotate/scale/offset/matrix4 scenarios. |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/rotated_box/rotated_box.png | Adds golden image for RotatedBox control test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/flip.png | Adds golden image for flip test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/rotate.png | Adds golden image for rotate test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/scale.png | Adds golden image for scale test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/matrix4_perspective_tilt.png | Adds golden image for Matrix4 perspective test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/matrix4_mirrored_spin.png | Adds golden image for Matrix4 mirror+spin test (macOS). |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/layout_control/matrix4_multiply_chain.png | Adds golden image for Matrix4 multiply-chain test (macOS). |
| packages/flet/lib/src/utils/transforms.dart | Adds Flutter-side parsing for flip/transform and Matrix4 recording replay; extends rotate/scale/offset parsing. |
| packages/flet/lib/src/controls/base_controls.dart | Wires new flip/transform wrappers into LayoutControl; refactors rotate/scale/offset animations and adds filter/hit-test/origin support. |
| packages/flet/lib/src/flet_core_extension.dart | Registers RotatedBox control mapping. |
| packages/flet/lib/src/controls/rotated_box.dart | Implements Flutter RotatedBox control widget wrapper. |
| sdk/python/examples/controls/form_controls_misc.py | Removes a form controls misc example file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (filterQuality == null) { | ||
| return translated; | ||
| } | ||
|
|
||
| return Transform.translate( | ||
| offset: Offset.zero, | ||
| transformHitTests: transformHitTests, | ||
| filterQuality: filterQuality, | ||
| child: translated, | ||
| ); |
There was a problem hiding this comment.
_fractionalTranslate() wraps FractionalTranslation in Transform.translate(offset: Offset.zero) when filterQuality is set. With an identity transform, filterQuality is effectively a no-op, so Offset.filter_quality won’t actually change rendering. Consider applying a real Transform (e.g., compute pixel offset via LayoutBuilder and use Transform.translate), or document that filter_quality isn’t supported for fractional offsets.
| if (filterQuality == null) { | |
| return translated; | |
| } | |
| return Transform.translate( | |
| offset: Offset.zero, | |
| transformHitTests: transformHitTests, | |
| filterQuality: filterQuality, | |
| child: translated, | |
| ); | |
| // Note: filterQuality is not applied for fractional translations because | |
| // there is no non-identity Transform; the value is currently ignored. | |
| return translated; |
Deploying flet-examples with
|
| Latest commit: |
d2e317d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://87027621.flet-examples.pages.dev |
| Branch Preview URL: | https://matrix-transform.flet-examples.pages.dev |
Return FractionalTranslation directly and remove the conditional Transform.translate wrapper. The change adds a comment clarifying that FractionalTranslation scales translations by the child's size and that filterQuality does not apply (no bitmap transform), eliminating redundant code and simplifying the layout logic.
Close #6195
Fix #1653
Summary by Sourcery
Add new Flip and Matrix4-based Transform capabilities to layout controls, along with a RotatedBox control, and update layout transforms, docs, examples, and tests accordingly.
New Features:
Enhancements:
Tests: