Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7a7110b2
Commit
7a7110b2
authored
Jul 17, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #57 Flex needs to understand baselines
parent
d6232c3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
6 deletions
+82
-6
align_items.dart
packages/flutter/example/rendering/align_items.dart
+58
-0
stock_row.dart
packages/flutter/example/stocks/lib/stock_row.dart
+7
-5
flex.dart
packages/flutter/lib/rendering/flex.dart
+17
-1
No files found.
packages/flutter/example/rendering/align_items.dart
0 → 100644
View file @
7a7110b2
// 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
);
void
addRow
(
FlexAlignItems
align
)
{
TextStyle
style
=
const
TextStyle
(
color:
const
Color
(
0xFF000000
));
RenderParagraph
paragraph
=
new
RenderParagraph
(
new
InlineStyle
(
style
,
[
new
InlineText
(
"
${align}
"
)]));
table
.
add
(
new
RenderPadding
(
child:
paragraph
,
padding:
new
EdgeDims
.
only
(
top:
20.0
)));
var
row
=
new
RenderFlex
(
direction:
FlexDirection
.
horizontal
);
style
=
new
TextStyle
(
fontSize:
15.0
,
color:
const
Color
(
0xFF000000
));
row
.
add
(
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFFCCCC
)),
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
(
0xFFCCFFCC
)),
child:
new
RenderParagraph
(
new
InlineStyle
(
style
,
[
new
InlineText
(
'foo foo foo'
)]))
));
style
=
new
TextStyle
(
fontSize:
25.0
,
color:
const
Color
(
0xFF000000
));
row
.
add
(
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFCCCCFF
)),
child:
new
RenderParagraph
(
new
InlineStyle
(
style
,
[
new
InlineText
(
'foo foo foo foo'
)]))
));
row
.
add
(
new
RenderSolidColorBox
(
const
Color
(
0xFFCCFFFF
),
desiredSize:
new
Size
(
30.0
,
40.0
)));
row
.
alignItems
=
align
;
table
.
add
(
row
);
row
.
parentData
.
flex
=
1
;
}
addRow
(
FlexAlignItems
.
start
);
addRow
(
FlexAlignItems
.
end
);
addRow
(
FlexAlignItems
.
center
);
addRow
(
FlexAlignItems
.
stretch
);
addRow
(
FlexAlignItems
.
baseline
);
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
);
}
packages/flutter/example/stocks/lib/stock_row.dart
View file @
7a7110b2
...
...
@@ -26,10 +26,6 @@ class StockRow extends Component {
if
(
stock
.
percentChange
>
0
)
changeInPrice
=
"+"
+
changeInPrice
;
List
<
Widget
>
children
=
[
new
Container
(
child:
new
StockArrow
(
percentChange:
stock
.
percentChange
),
margin:
const
EdgeDims
.
only
(
right:
5.0
)
),
new
Flexible
(
child:
new
Text
(
stock
.
symbol
),
flex:
2
...
...
@@ -58,7 +54,13 @@ class StockRow extends Component {
bottom:
new
BorderSide
(
color:
Theme
.
of
(
this
).
dividerColor
)
)
),
child:
new
Flex
(
children
)
child:
new
Flex
([
new
Container
(
child:
new
StockArrow
(
percentChange:
stock
.
percentChange
),
margin:
const
EdgeDims
.
only
(
right:
5.0
)
),
new
Flex
(
children
,
alignItems:
FlexAlignItems
.
baseline
)
])
)
);
}
...
...
packages/flutter/lib/rendering/flex.dart
View file @
7a7110b2
...
...
@@ -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
;
...
...
@@ -397,6 +404,15 @@ 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
;
if
(
_direction
==
FlexDirection
.
horizontal
)
{
// TODO(jackson): Support for non-alphabetic baselines
double
distance
=
child
.
getDistanceToBaseline
(
TextBaseline
.
alphabetic
,
onlyReal:
true
);
if
(
distance
!=
null
)
childCrossPosition
=
maxBaselineDistance
-
distance
;
}
break
;
}
switch
(
_direction
)
{
case
FlexDirection
.
horizontal
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment