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

Unified Diff: sky/sdk/example/rendering/flex.dart

Issue 1232063006: Remove "RenderBlock" class from examples that use it without giving it unrestricted height. (Closed) Base URL: https://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
« no previous file with comments | « sky/sdk/example/rendering/baseline.dart ('k') | sky/tests/raw/box_layout.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/example/rendering/flex.dart
diff --git a/sky/sdk/example/rendering/flex.dart b/sky/sdk/example/rendering/flex.dart
new file mode 100644
index 0000000000000000000000000000000000000000..702dbc7d0c308e660fb6a2c4f438a7a7eb2ea6db
--- /dev/null
+++ b/sky/sdk/example/rendering/flex.dart
@@ -0,0 +1,93 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:sky' as sky;
+
+import 'package:sky/rendering/box.dart';
+import 'package:sky/rendering/flex.dart';
+import 'package:sky/rendering/sky_binding.dart';
+
+class RenderSolidColor extends RenderDecoratedBox {
+ final sky.Size desiredSize;
+ final sky.Color backgroundColor;
+
+ RenderSolidColor(sky.Color backgroundColor, { this.desiredSize: sky.Size.infinite })
+ : backgroundColor = backgroundColor,
+ super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) {
+ }
+
+ double getMinIntrinsicWidth(BoxConstraints constraints) {
+ return constraints.constrainWidth(desiredSize.width);
+ }
+
+ double getMaxIntrinsicWidth(BoxConstraints constraints) {
+ return constraints.constrainWidth(desiredSize.width);
+ }
+
+ double getMinIntrinsicHeight(BoxConstraints constraints) {
+ return constraints.constrainHeight(desiredSize.height);
+ }
+
+ double getMaxIntrinsicHeight(BoxConstraints constraints) {
+ return constraints.constrainHeight(desiredSize.height);
+ }
+
+ void performLayout() {
+ size = constraints.constrain(desiredSize);
+ }
+
+ void handleEvent(sky.Event event, BoxHitTestEntry entry) {
+ if (event.type == 'pointerdown')
+ decoration = new BoxDecoration(backgroundColor: const sky.Color(0xFFFF0000));
+ else if (event.type == 'pointerup')
+ decoration = new BoxDecoration(backgroundColor: backgroundColor);
+ }
+}
+
+RenderBox buildFlexExample() {
+ RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
+
+ RenderDecoratedBox root = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)),
+ child: flexRoot
+ );
+
+ void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
+ RenderSolidColor child = new RenderSolidColor(backgroundColor);
+ parent.add(child);
+ child.parentData.flex = flex;
+ }
+
+ // Yellow bar at top
+ addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1);
+
+ // Turquoise box
+ flexRoot.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSize: new sky.Size(100.0, 100.0)));
+
+ var renderDecoratedBlock = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF))
+ );
+
+ flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: renderDecoratedBlock));
+
+ var row = new RenderFlex(direction: FlexDirection.horizontal);
+
+ // Purple and blue cells
+ addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1);
+ addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2);
+
+ var decoratedRow = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)),
+ child: row
+ );
+
+ flexRoot.add(decoratedRow);
+ decoratedRow.parentData.flex = 3;
+
+ return root;
+}
+
+void main() {
+ new SkyBinding(root: buildFlexExample());
+}
« no previous file with comments | « sky/sdk/example/rendering/baseline.dart ('k') | sky/tests/raw/box_layout.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698