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

Unified Diff: sky/examples/raw/simple_render_tree.dart

Issue 1151293002: WIP Flexbox Layout Manager for Sky framework. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebasing onto master Created 5 years, 7 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 | « no previous file | sky/sdk/lib/framework/layout2.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/raw/simple_render_tree.dart
diff --git a/sky/examples/raw/simple_render_tree.dart b/sky/examples/raw/simple_render_tree.dart
index a9e559b0ac463e4a76993062457d67cc548bd9ee..019c185eb1e83939011624c4c6b629360179f782 100644
--- a/sky/examples/raw/simple_render_tree.dart
+++ b/sky/examples/raw/simple_render_tree.dart
@@ -7,19 +7,26 @@ import 'dart:sky';
import 'package:sky/framework/layout2.dart';
class RenderSolidColor extends RenderDecoratedBox {
+ final double desiredHeight;
+ final double desiredWidth;
final int backgroundColor;
- RenderSolidColor(int backgroundColor)
- : super(new BoxDecoration(backgroundColor: backgroundColor)),
- backgroundColor = backgroundColor;
+ RenderSolidColor(int backgroundColor, { double desiredHeight: double.INFINITY,
+ double desiredWidth: double.INFINITY })
+ : desiredHeight = desiredHeight,
sethladd 2015/05/23 03:14:10 Did you consider using this. in your constructor?
jackson 2015/05/23 03:47:43 Good call, I'll fix that. I'm new to Dart, as you
+ desiredWidth = desiredWidth,
+ backgroundColor = backgroundColor,
+ super(new BoxDecoration(backgroundColor: backgroundColor));
BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
- return new BoxDimensions.withConstraints(constraints, height: 200.0);
+ return new BoxDimensions.withConstraints(constraints,
+ height: desiredHeight,
+ width: desiredWidth);
}
void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
- width = constraints.constrainWidth(constraints.maxWidth);
- height = constraints.constrainHeight(200.0);
+ width = constraints.constrainWidth(desiredWidth);
+ height = constraints.constrainHeight(desiredHeight);
layoutDone();
}
@@ -56,12 +63,42 @@ void main() {
view.setEventCallback(handleEvent);
view.setBeginFrameCallback(beginFrame);
- var root = new RenderBlock(
- decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF),
+ var root = new RenderFlex(
+ direction: FlexDirection.Vertical,
+ decoration: new BoxDecoration(backgroundColor: 0xFF000000));
+
+ void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) {
+ RenderNode child = new RenderSolidColor(backgroundColor);
+ parent.add(child);
+ child.parentData.flex = flex;
+ }
+
+ // Yellow bar at top
+ addFlexChild(root, 0xFFFFFF00, flex: 1);
+
+ // Turquoise box
+ root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 100.0));
+
+ // Green and cyan render block with padding
+ var renderBlock = new RenderBlock(
+ decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF),
padding: const EdgeDims(10.0, 10.0, 10.0, 10.0));
- root.add(new RenderSolidColor(0xFF00FF00));
- root.add(new RenderSolidColor(0xFF0000FF));
+ renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredWidth: 100.0));
+ renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 50.0));
+
+ root.add(renderBlock);
+
+ var row = new RenderFlex(
+ direction: FlexDirection.Horizontal,
+ decoration: new BoxDecoration(backgroundColor: 0xFF333333));
+
+ // Purple and blue cells
+ addFlexChild(row, 0x77FF00FF, flex: 1);
+ addFlexChild(row, 0xFF0000FF, flex: 2);
+
+ root.add(row);
+ row.parentData.flex = 3;
renderView = new RenderView(root: root);
renderView.layout(newWidth: view.width, newHeight: view.height);
« no previous file with comments | « no previous file | sky/sdk/lib/framework/layout2.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698