-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #57 Flex needs to understand baselines #95
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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'; | ||
|
||
import 'package:sky/painting/text_style.dart'; | ||
import 'package:sky/rendering/box.dart'; | ||
import 'package:sky/rendering/flex.dart'; | ||
import 'package:sky/rendering/object.dart'; | ||
import 'package:sky/rendering/paragraph.dart'; | ||
import 'package:sky/rendering/sky_binding.dart'; | ||
|
||
import 'solid_color_box.dart'; | ||
|
||
void main() { | ||
var table = new RenderFlex(direction: FlexDirection.vertical); | ||
|
||
for(FlexAlignItems alignItems in FlexAlignItems.values) { | ||
TextStyle style = const TextStyle(color: const Color(0xFF000000)); | ||
RenderParagraph paragraph = new RenderParagraph(new InlineStyle(style, [new InlineText("${alignItems}")])); | ||
table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0))); | ||
var row = new RenderFlex(alignItems: alignItems); | ||
|
||
style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000)); | ||
row.add(new RenderDecoratedBox( | ||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FFFCCCC)), | ||
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')])) | ||
)); | ||
style = new TextStyle(fontSize: 10.0, color: const Color(0xFF000000)); | ||
row.add(new RenderDecoratedBox( | ||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)), | ||
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')])) | ||
)); | ||
var subrow = new RenderFlex(alignItems: alignItems); | ||
style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000)); | ||
subrow.add(new RenderDecoratedBox( | ||
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)), | ||
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo foo')])) | ||
)); | ||
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: new Size(30.0, 40.0))); | ||
row.add(subrow); | ||
table.add(row); | ||
row.parentData.flex = 1; | ||
} | ||
|
||
RenderDecoratedBox root = new RenderDecoratedBox( | ||
decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)), | ||
child: new RenderPadding(child: table, padding: new EdgeDims.symmetric(vertical: 50.0)) | ||
); | ||
|
||
new SkyBinding(root: root); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ enum FlexAlignItems { | |
end, | ||
center, | ||
stretch, | ||
baseline, | ||
} | ||
|
||
typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints); | ||
|
@@ -315,6 +316,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl | |
// Steps 4-5. Distribute remaining space to flexible children. | ||
double spacePerFlex = totalFlex > 0 ? (freeSpace / totalFlex) : 0.0; | ||
double usedSpace = 0.0; | ||
double maxBaselineDistance = 0.0; | ||
child = firstChild; | ||
while (child != null) { | ||
int flex = _getFlex(child); | ||
|
@@ -337,6 +339,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl | |
usedSpace += _getMainSize(child); | ||
crossSize = math.max(crossSize, _getCrossSize(child)); | ||
} | ||
if (alignItems == FlexAlignItems.baseline) { | ||
// TODO(jackson): Support for non-alphabetic baselines | ||
double distance = child.getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true); | ||
if (distance != null) | ||
maxBaselineDistance = math.max(maxBaselineDistance, distance); | ||
} | ||
assert(child.parentData is FlexBoxParentData); | ||
child = child.parentData.nextSibling; | ||
} | ||
|
@@ -345,7 +353,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl | |
double remainingSpace = math.max(0.0, freeSpace - usedSpace); | ||
double leadingSpace; | ||
double betweenSpace; | ||
child = firstChild; | ||
switch (_justifyContent) { | ||
case FlexJustifyContent.start: | ||
leadingSpace = 0.0; | ||
|
@@ -380,7 +387,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl | |
break; | ||
} | ||
|
||
// Position elements. For now, center the flex items in the cross direction | ||
// Position elements | ||
double childMainPosition = leadingSpace; | ||
child = firstChild; | ||
while (child != null) { | ||
|
@@ -397,6 +404,16 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl | |
case FlexAlignItems.center: | ||
childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0; | ||
break; | ||
case FlexAlignItems.baseline: | ||
childCrossPosition = 0.0; | ||
// TODO(jackson): Support for vertical baselines | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forget vertical text. |
||
if (_direction == FlexDirection.horizontal) { | ||
// TODO(jackson): Support for non-alphabetic baselines | ||
double distance = child.getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get the baseline to use earlier |
||
if (distance != null) | ||
childCrossPosition = maxBaselineDistance - distance; | ||
} | ||
break; | ||
} | ||
switch (_direction) { | ||
case FlexDirection.horizontal: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the baseline to use from the default text style, maybe?