Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: sky/sdk/lib/rendering/box.dart

Issue 1227093010: Add an AspectRatio widget for doing proportional height sizing (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/sdk/lib/rendering/box.dart
diff --git a/sky/sdk/lib/rendering/box.dart b/sky/sdk/lib/rendering/box.dart
index 2c5a228658f6c7b7d46dfae72ea260c3f2c1df4b..7f9c914ddbe0bf3257b443777a52a698d6ad4478 100644
--- a/sky/sdk/lib/rendering/box.dart
+++ b/sky/sdk/lib/rendering/box.dart
@@ -591,6 +591,52 @@ class RenderConstrainedBox extends RenderProxyBox {
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n';
}
+class RenderAspectRatio extends RenderProxyBox {
+ RenderAspectRatio({
+ RenderBox child,
+ double aspectRatio
+ }) : super(child), _aspectRatio = aspectRatio {
+ assert(_aspectRatio != null);
+ }
+
+ double _aspectRatio;
+ double get aspectRatio => _aspectRatio;
+ void set aspectRatio (double value) {
+ assert(value != null);
+ if (_aspectRatio == value)
+ return;
+ _aspectRatio = value;
+ markNeedsLayout();
+ }
+
+ double getMinIntrinsicHeight(BoxConstraints constraints) {
+ return _applyAspectRatio(constraints).height;
+ }
+
+ double getMaxIntrinsicHeight(BoxConstraints constraints) {
+ return _applyAspectRatio(constraints).height;
+ }
+
+ Size _applyAspectRatio(BoxConstraints constraints) {
+ double width = constraints.constrainWidth();
+ double height = constraints.constrainHeight(width / _aspectRatio);
+ return new Size(width, height);
+ }
+
+ bool get sizedByParent => true;
+
+ void performResize() {
+ size = _applyAspectRatio(constraints);
+ }
+
+ void performLayout() {
+ if (child != null)
+ child.layout(new BoxConstraints.tight(size));
+ }
+
+ String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}aspectRatio: ${aspectRatio}\n';
+}
+
class RenderShrinkWrapWidth extends RenderProxyBox {
// This class will attempt to size its child to the child's maximum

Powered by Google App Engine
This is Rietveld 408576698