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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | sky/sdk/lib/framework/layout2.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math'; 5 import 'dart:math';
6 import 'dart:sky'; 6 import 'dart:sky';
7 import 'package:sky/framework/layout2.dart'; 7 import 'package:sky/framework/layout2.dart';
8 8
9 class RenderSolidColor extends RenderDecoratedBox { 9 class RenderSolidColor extends RenderDecoratedBox {
10 final double desiredHeight;
11 final double desiredWidth;
10 final int backgroundColor; 12 final int backgroundColor;
11 13
12 RenderSolidColor(int backgroundColor) 14 RenderSolidColor(int backgroundColor, { double desiredHeight: double.INFINITY,
13 : super(new BoxDecoration(backgroundColor: backgroundColor)), 15 double desiredWidth: double.INFINITY } )
14 backgroundColor = backgroundColor; 16 : 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
17 desiredWidth = desiredWidth,
18 backgroundColor = backgroundColor,
19 super(new BoxDecoration(backgroundColor: backgroundColor));
15 20
16 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { 21 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
17 return new BoxDimensions.withConstraints(constraints, height: 200.0); 22 return new BoxDimensions.withConstraints(constraints,
23 height: desiredHeight,
24 width: desiredWidth);
18 } 25 }
19 26
20 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { 27 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
21 width = constraints.constrainWidth(constraints.maxWidth); 28 width = constraints.constrainWidth(desiredWidth);
22 height = constraints.constrainHeight(200.0); 29 height = constraints.constrainHeight(desiredHeight);
23 layoutDone(); 30 layoutDone();
24 } 31 }
25 32
26 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) { 33 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) {
27 if (event.type == 'pointerdown') { 34 if (event.type == 'pointerdown') {
28 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000)); 35 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000));
29 return true; 36 return true;
30 } 37 }
31 38
32 if (event.type == 'pointerup') { 39 if (event.type == 'pointerup') {
(...skipping 16 matching lines...) Expand all
49 bool handleEvent(Event event) { 56 bool handleEvent(Event event) {
50 if (event is! PointerEvent) 57 if (event is! PointerEvent)
51 return false; 58 return false;
52 return renderView.handlePointer(event, x: event.x, y: event.y); 59 return renderView.handlePointer(event, x: event.x, y: event.y);
53 } 60 }
54 61
55 void main() { 62 void main() {
56 view.setEventCallback(handleEvent); 63 view.setEventCallback(handleEvent);
57 view.setBeginFrameCallback(beginFrame); 64 view.setBeginFrameCallback(beginFrame);
58 65
59 var root = new RenderBlock( 66 var root = new RenderFlex(
60 decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF), 67 direction: FlexDirection.Vertical,
68 decoration: new BoxDecoration(backgroundColor: 0xFF000000));
69
70 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) {
71 RenderNode child = new RenderSolidColor(backgroundColor);
72 parent.add(child);
73 child.parentData.flex = flex;
74 }
75
76 // Yellow bar at top
77 addFlexChild(root, 0xFFFFFF00, flex: 1);
78
79 // Turquoise box
80 root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 100.0));
81
82 // Green and cyan render block with padding
83 var renderBlock = new RenderBlock(
84 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF),
61 padding: const EdgeDims(10.0, 10.0, 10.0, 10.0)); 85 padding: const EdgeDims(10.0, 10.0, 10.0, 10.0));
62 86
63 root.add(new RenderSolidColor(0xFF00FF00)); 87 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredW idth: 100.0));
64 root.add(new RenderSolidColor(0xFF0000FF)); 88 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desired Width: 50.0));
89
90 root.add(renderBlock);
91
92 var row = new RenderFlex(
93 direction: FlexDirection.Horizontal,
94 decoration: new BoxDecoration(backgroundColor: 0xFF333333));
95
96 // Purple and blue cells
97 addFlexChild(row, 0x77FF00FF, flex: 1);
98 addFlexChild(row, 0xFF0000FF, flex: 2);
99
100 root.add(row);
101 row.parentData.flex = 3;
65 102
66 renderView = new RenderView(root: root); 103 renderView = new RenderView(root: root);
67 renderView.layout(newWidth: view.width, newHeight: view.height); 104 renderView.layout(newWidth: view.width, newHeight: view.height);
68 105
69 view.scheduleFrame(); 106 view.scheduleFrame();
70 } 107 }
OLDNEW
« 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