mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Bumps the Dart version to 3.8 across the repo (excluding engine/src/flutter/third_party) and applies formatting updates from Dart 3.8. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
152 lines
4.4 KiB
Dart
152 lines
4.4 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/// @docImport 'proxy_box.dart';
|
|
library;
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:vector_math/vector_math_64.dart' show Matrix4;
|
|
|
|
import 'box.dart';
|
|
import 'layer.dart';
|
|
import 'object.dart';
|
|
|
|
const double _kQuarterTurnsInRadians = math.pi / 2.0;
|
|
|
|
/// Rotates its child by a integral number of quarter turns.
|
|
///
|
|
/// Unlike [RenderTransform], which applies a transform just prior to painting,
|
|
/// this object applies its rotation prior to layout, which means the entire
|
|
/// rotated box consumes only as much space as required by the rotated child.
|
|
class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderBox> {
|
|
/// Creates a rotated render box.
|
|
RenderRotatedBox({required int quarterTurns, RenderBox? child}) : _quarterTurns = quarterTurns {
|
|
this.child = child;
|
|
}
|
|
|
|
/// The number of clockwise quarter turns the child should be rotated.
|
|
int get quarterTurns => _quarterTurns;
|
|
int _quarterTurns;
|
|
set quarterTurns(int value) {
|
|
if (_quarterTurns == value) {
|
|
return;
|
|
}
|
|
_quarterTurns = value;
|
|
markNeedsLayout();
|
|
}
|
|
|
|
bool get _isVertical => quarterTurns.isOdd;
|
|
|
|
@override
|
|
double computeMinIntrinsicWidth(double height) {
|
|
if (child == null) {
|
|
return 0.0;
|
|
}
|
|
return _isVertical ? child!.getMinIntrinsicHeight(height) : child!.getMinIntrinsicWidth(height);
|
|
}
|
|
|
|
@override
|
|
double computeMaxIntrinsicWidth(double height) {
|
|
if (child == null) {
|
|
return 0.0;
|
|
}
|
|
return _isVertical ? child!.getMaxIntrinsicHeight(height) : child!.getMaxIntrinsicWidth(height);
|
|
}
|
|
|
|
@override
|
|
double computeMinIntrinsicHeight(double width) {
|
|
if (child == null) {
|
|
return 0.0;
|
|
}
|
|
return _isVertical ? child!.getMinIntrinsicWidth(width) : child!.getMinIntrinsicHeight(width);
|
|
}
|
|
|
|
@override
|
|
double computeMaxIntrinsicHeight(double width) {
|
|
if (child == null) {
|
|
return 0.0;
|
|
}
|
|
return _isVertical ? child!.getMaxIntrinsicWidth(width) : child!.getMaxIntrinsicHeight(width);
|
|
}
|
|
|
|
Matrix4? _paintTransform;
|
|
|
|
@override
|
|
@protected
|
|
Size computeDryLayout(covariant BoxConstraints constraints) {
|
|
if (child == null) {
|
|
return constraints.smallest;
|
|
}
|
|
final Size childSize = child!.getDryLayout(_isVertical ? constraints.flipped : constraints);
|
|
return _isVertical ? Size(childSize.height, childSize.width) : childSize;
|
|
}
|
|
|
|
@override
|
|
void performLayout() {
|
|
_paintTransform = null;
|
|
if (child != null) {
|
|
child!.layout(_isVertical ? constraints.flipped : constraints, parentUsesSize: true);
|
|
size = _isVertical ? Size(child!.size.height, child!.size.width) : child!.size;
|
|
_paintTransform = Matrix4.identity()
|
|
..translateByDouble(size.width / 2.0, size.height / 2.0, 0, 1)
|
|
..rotateZ(_kQuarterTurnsInRadians * (quarterTurns % 4))
|
|
..translateByDouble(-child!.size.width / 2.0, -child!.size.height / 2.0, 0, 1);
|
|
} else {
|
|
size = constraints.smallest;
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
|
assert(_paintTransform != null || debugNeedsLayout || child == null);
|
|
if (child == null || _paintTransform == null) {
|
|
return false;
|
|
}
|
|
return result.addWithPaintTransform(
|
|
transform: _paintTransform,
|
|
position: position,
|
|
hitTest: (BoxHitTestResult result, Offset position) {
|
|
return child!.hitTest(result, position: position);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _paintChild(PaintingContext context, Offset offset) {
|
|
context.paintChild(child!, offset);
|
|
}
|
|
|
|
@override
|
|
void paint(PaintingContext context, Offset offset) {
|
|
if (child != null) {
|
|
_transformLayer.layer = context.pushTransform(
|
|
needsCompositing,
|
|
offset,
|
|
_paintTransform!,
|
|
_paintChild,
|
|
oldLayer: _transformLayer.layer,
|
|
);
|
|
} else {
|
|
_transformLayer.layer = null;
|
|
}
|
|
}
|
|
|
|
final LayerHandle<TransformLayer> _transformLayer = LayerHandle<TransformLayer>();
|
|
|
|
@override
|
|
void dispose() {
|
|
_transformLayer.layer = null;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void applyPaintTransform(RenderBox child, Matrix4 transform) {
|
|
if (_paintTransform != null) {
|
|
transform.multiply(_paintTransform!);
|
|
}
|
|
super.applyPaintTransform(child, transform);
|
|
}
|
|
}
|