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

Side by Side Diff: sky/sdk/lib/framework/rendering/flex.dart

Issue 1181533003: Support for alignItems (test incoming) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
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' as math; 5 import 'dart:math' as math;
6 import 'box.dart'; 6 import 'box.dart';
7 import 'object.dart'; 7 import 'object.dart';
8 8
9 class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend erBox> { 9 class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend erBox> {
10 int flex; 10 int flex;
11 11
12 void merge(FlexBoxParentData other) { 12 void merge(FlexBoxParentData other) {
13 if (other.flex != null) 13 if (other.flex != null)
14 flex = other.flex; 14 flex = other.flex;
15 super.merge(other); 15 super.merge(other);
16 } 16 }
17 17
18 String toString() => '${super.toString()}; flex=$flex'; 18 String toString() => '${super.toString()}; flex=$flex';
19 } 19 }
20 20
21 enum FlexDirection { horizontal, vertical } 21 enum FlexDirection { horizontal, vertical }
22
22 enum FlexJustifyContent { 23 enum FlexJustifyContent {
23 flexStart, 24 flexStart,
24 flexEnd, 25 flexEnd,
25 center, 26 center,
26 spaceBetween, 27 spaceBetween,
27 spaceAround, 28 spaceAround,
28 } 29 }
29 30
31 enum FlexAlignItems {
32 flexStart,
33 flexEnd,
34 center,
35 }
36
30 typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints) ; 37 typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints) ;
31 38
32 class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl exBoxParentData>, 39 class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl exBoxParentData>,
33 RenderBoxContainerDefaultsMixin<RenderBo x, FlexBoxParentData> { 40 RenderBoxContainerDefaultsMixin<RenderBo x, FlexBoxParentData> {
34 // lays out RenderBox children using flexible layout 41 // lays out RenderBox children using flexible layout
35 42
36 RenderFlex({ 43 RenderFlex({
37 FlexDirection direction: FlexDirection.horizontal, 44 FlexDirection direction: FlexDirection.horizontal,
38 FlexJustifyContent justifyContent: FlexJustifyContent.flexStart 45 FlexJustifyContent justifyContent: FlexJustifyContent.flexStart,
39 }) : _direction = direction, _justifyContent = justifyContent; 46 FlexAlignItems alignItems: FlexAlignItems.center
47 }) : _direction = direction, _justifyContent = justifyContent, _alignItems = a lignItems;
40 48
41 FlexDirection _direction; 49 FlexDirection _direction;
42 FlexDirection get direction => _direction; 50 FlexDirection get direction => _direction;
43 void set direction (FlexDirection value) { 51 void set direction (FlexDirection value) {
44 if (_direction != value) { 52 if (_direction != value) {
45 _direction = value; 53 _direction = value;
46 markNeedsLayout(); 54 markNeedsLayout();
47 } 55 }
48 } 56 }
49 57
50 FlexJustifyContent _justifyContent; 58 FlexJustifyContent _justifyContent;
51 FlexJustifyContent get justifyContent => _justifyContent; 59 FlexJustifyContent get justifyContent => _justifyContent;
52 void set justifyContent (FlexJustifyContent value) { 60 void set justifyContent (FlexJustifyContent value) {
53 if (_justifyContent != value) { 61 if (_justifyContent != value) {
54 _justifyContent = value; 62 _justifyContent = value;
55 markNeedsLayout(); 63 markNeedsLayout();
56 } 64 }
57 } 65 }
58 66
67 FlexAlignItems _alignItems;
68 FlexAlignItems get alignItems => _alignItems;
69 void set alignItems (FlexAlignItems value) {
70 if (_alignItems != value) {
71 _alignItems = value;
72 markNeedsLayout();
73 }
74 }
75
59 void setParentData(RenderBox child) { 76 void setParentData(RenderBox child) {
60 if (child.parentData is! FlexBoxParentData) 77 if (child.parentData is! FlexBoxParentData)
61 child.parentData = new FlexBoxParentData(); 78 child.parentData = new FlexBoxParentData();
62 } 79 }
63 80
64 double _getIntrinsicSize({ BoxConstraints constraints, 81 double _getIntrinsicSize({ BoxConstraints constraints,
65 FlexDirection sizingDirection, 82 FlexDirection sizingDirection,
66 _ChildSizingFunction childSize }) { 83 _ChildSizingFunction childSize }) {
67 // http://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/#intrinsic-sizes 84 // http://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/#intrinsic-sizes
68 if (_direction == sizingDirection) { 85 if (_direction == sizingDirection) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 case FlexDirection.vertical: 344 case FlexDirection.vertical:
328 size = constraints.constrain(new Size(crossSize, mainSize)); 345 size = constraints.constrain(new Size(crossSize, mainSize));
329 crossSize = size.width; 346 crossSize = size.width;
330 break; 347 break;
331 } 348 }
332 349
333 // Position elements. For now, center the flex items in the cross direction 350 // Position elements. For now, center the flex items in the cross direction
334 double childMainPosition = leadingSpace; 351 double childMainPosition = leadingSpace;
335 child = firstChild; 352 child = firstChild;
336 while (child != null) { 353 while (child != null) {
337 double childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0; 354 double childCrossPosition;
355 switch (_alignItems) {
356 case FlexAlignItems.flexStart:
357 childCrossPosition = 0.0;
358 break;
359 case FlexAlignItems.flexEnd:
360 childCrossPosition = crossSize - _getCrossSize(child);
361 break;
362 case FlexAlignItems.center:
363 childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0;
364 break;
365 }
338 switch (_direction) { 366 switch (_direction) {
339 case FlexDirection.horizontal: 367 case FlexDirection.horizontal:
340 child.parentData.position = new Point(childMainPosition, childCrossPos ition); 368 child.parentData.position = new Point(childMainPosition, childCrossPos ition);
341 break; 369 break;
342 case FlexDirection.vertical: 370 case FlexDirection.vertical:
343 child.parentData.position = new Point(childCrossPosition, childMainPos ition); 371 child.parentData.position = new Point(childCrossPosition, childMainPos ition);
344 break; 372 break;
345 } 373 }
346 childMainPosition += _getMainSize(child) + betweenSpace; 374 childMainPosition += _getMainSize(child) + betweenSpace;
347 child = child.parentData.nextSibling; 375 child = child.parentData.nextSibling;
348 } 376 }
349 } 377 }
350 378
351 void hitTestChildren(HitTestResult result, { Point position }) { 379 void hitTestChildren(HitTestResult result, { Point position }) {
352 defaultHitTestChildren(result, position: position); 380 defaultHitTestChildren(result, position: position);
353 } 381 }
354 382
355 void paint(RenderObjectDisplayList canvas) { 383 void paint(RenderObjectDisplayList canvas) {
356 defaultPaint(canvas); 384 defaultPaint(canvas);
357 } 385 }
358 } 386 }
OLDNEW
« sky/sdk/lib/framework/fn2.dart ('K') | « sky/sdk/lib/framework/fn2.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698