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
f6c9ab80
Commit
f6c9ab80
authored
Aug 06, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach Block how to layout horizontally
We'll need this for horizontally scrolling lists.
parent
5923d03c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
43 deletions
+82
-43
block.dart
packages/flutter/lib/rendering/block.dart
+82
-43
No files found.
packages/flutter/lib/rendering/block.dart
View file @
f6c9ab80
...
@@ -9,6 +9,10 @@ import 'package:sky/rendering/object.dart';
...
@@ -9,6 +9,10 @@ import 'package:sky/rendering/object.dart';
class
BlockParentData
extends
BoxParentData
with
ContainerParentDataMixin
<
RenderBox
>
{
}
class
BlockParentData
extends
BoxParentData
with
ContainerParentDataMixin
<
RenderBox
>
{
}
enum
BlockDirection
{
horizontal
,
vertical
}
typedef
double
_ChildSizingFunction
(
RenderBox
child
,
BoxConstraints
constraints
);
abstract
class
RenderBlockBase
extends
RenderBox
with
ContainerRenderObjectMixin
<
RenderBox
,
BlockParentData
>,
abstract
class
RenderBlockBase
extends
RenderBox
with
ContainerRenderObjectMixin
<
RenderBox
,
BlockParentData
>,
RenderBoxContainerDefaultsMixin
<
RenderBox
,
BlockParentData
>
{
RenderBoxContainerDefaultsMixin
<
RenderBox
,
BlockParentData
>
{
...
@@ -16,8 +20,9 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
...
@@ -16,8 +20,9 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
// uses the maximum width provided by the parent
// uses the maximum width provided by the parent
RenderBlockBase
({
RenderBlockBase
({
List
<
RenderBox
>
children
List
<
RenderBox
>
children
,
})
{
BlockDirection
direction:
BlockDirection
.
vertical
})
:
_direction
=
direction
{
addAll
(
children
);
addAll
(
children
);
}
}
...
@@ -26,93 +31,127 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
...
@@ -26,93 +31,127 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
child
.
parentData
=
new
BlockParentData
();
child
.
parentData
=
new
BlockParentData
();
}
}
double
_childrenHeight
;
BlockDirection
_direction
;
double
get
childrenHeight
=>
_childrenHeight
;
BlockDirection
get
direction
=>
_direction
;
void
set
direction
(
BlockDirection
value
)
{
if
(
_direction
!=
value
)
{
_direction
=
value
;
markNeedsLayout
();
}
}
bool
get
_isVertical
=>
_direction
==
BlockDirection
.
vertical
;
void
markNeedsLayout
()
{
BoxConstraints
_getInnerConstraints
(
BoxConstraints
constraints
)
{
_childrenHeight
=
null
;
if
(
_isVertical
)
super
.
markNeedsLayout
();
return
new
BoxConstraints
.
tightFor
(
width:
constraints
.
constrainWidth
(
constraints
.
maxWidth
));
return
new
BoxConstraints
.
tightFor
(
height:
constraints
.
constrainHeight
(
constraints
.
maxHeight
));
}
}
void
performLayout
()
{
void
performLayout
()
{
assert
(
constraints
is
BoxConstraints
);
BoxConstraints
innerConstraints
=
_getInnerConstraints
(
constraints
);
double
width
=
constraints
.
constrainWidth
(
constraints
.
maxWidth
);
double
position
=
0.0
;
BoxConstraints
innerConstraints
=
new
BoxConstraints
.
tightFor
(
width:
width
);
double
y
=
0.0
;
RenderBox
child
=
firstChild
;
RenderBox
child
=
firstChild
;
while
(
child
!=
null
)
{
while
(
child
!=
null
)
{
child
.
layout
(
innerConstraints
,
parentUsesSize:
true
);
child
.
layout
(
innerConstraints
,
parentUsesSize:
true
);
assert
(
child
.
parentData
is
BlockParentData
);
assert
(
child
.
parentData
is
BlockParentData
);
child
.
parentData
.
position
=
new
Point
(
0.0
,
y
);
child
.
parentData
.
position
=
_isVertical
?
new
Point
(
0.0
,
position
)
:
new
Point
(
position
,
0.0
);
y
+=
child
.
size
.
height
;
position
+=
_isVertical
?
child
.
size
.
height
:
child
.
size
.
width
;
child
=
child
.
parentData
.
nextSibling
;
child
=
child
.
parentData
.
nextSibling
;
}
}
_childrenHeight
=
y
;
}
}
}
}
class
RenderBlock
extends
RenderBlockBase
{
class
RenderBlock
extends
RenderBlockBase
{
// sizes itself to the height of its child stack
RenderBlock
({
List
<
RenderBox
>
children
,
RenderBlock
({
List
<
RenderBox
>
children
})
:
super
(
children:
children
);
BlockDirection
direction:
BlockDirection
.
vertical
})
:
super
(
children:
children
,
direction:
direction
);
double
getMinIntrinsicWidth
(
BoxConstraints
constraints
)
{
double
_getIntrinsicCrossAxis
(
BoxConstraints
constraints
,
_ChildSizingFunction
childSize
)
{
double
width
=
0.0
;
double
extent
=
0.0
;
BoxConstraints
innerConstraints
=
constraints
.
width
Constraints
();
BoxConstraints
innerConstraints
=
_isVertical
?
constraints
.
widthConstraints
()
:
constraints
.
height
Constraints
();
RenderBox
child
=
firstChild
;
RenderBox
child
=
firstChild
;
while
(
child
!=
null
)
{
while
(
child
!=
null
)
{
width
=
math
.
max
(
width
,
child
.
getMinIntrinsicWidth
(
innerConstraints
));
extent
=
math
.
max
(
extent
,
childSize
(
child
,
innerConstraints
));
assert
(
child
.
parentData
is
BlockParentData
);
assert
(
child
.
parentData
is
BlockParentData
);
child
=
child
.
parentData
.
nextSibling
;
child
=
child
.
parentData
.
nextSibling
;
}
}
return
width
;
return
extent
;
}
}
double
getMaxIntrinsicWidth
(
BoxConstraints
constraints
)
{
double
_getIntrinsicMainAxis
(
BoxConstraints
constraints
)
{
double
width
=
0.0
;
double
extent
=
0.0
;
BoxConstraints
innerConstraints
=
constraints
.
widthConstraints
(
);
BoxConstraints
innerConstraints
=
_getInnerConstraints
(
constraints
);
RenderBox
child
=
firstChild
;
RenderBox
child
=
firstChild
;
while
(
child
!=
null
)
{
while
(
child
!=
null
)
{
width
=
math
.
max
(
width
,
child
.
getMaxIntrinsicWidth
(
innerConstraints
));
double
childExtent
=
_isVertical
?
child
.
getMinIntrinsicHeight
(
innerConstraints
)
:
child
.
getMinIntrinsicWidth
(
innerConstraints
);
assert
(()
{
if
(
_isVertical
)
return
childExtent
==
child
.
getMaxIntrinsicHeight
(
innerConstraints
);
return
childExtent
==
child
.
getMaxIntrinsicWidth
(
innerConstraints
);
});
extent
+=
childExtent
;
assert
(
child
.
parentData
is
BlockParentData
);
assert
(
child
.
parentData
is
BlockParentData
);
child
=
child
.
parentData
.
nextSibling
;
child
=
child
.
parentData
.
nextSibling
;
}
}
return
width
;
return
extent
;
}
}
double
_getIntrinsicHeight
(
BoxConstraints
constraints
)
{
double
getMinIntrinsicWidth
(
BoxConstraints
constraints
)
{
double
height
=
0.0
;
if
(
_isVertical
)
{
double
width
=
constraints
.
constrainWidth
(
constraints
.
maxWidth
);
return
_getIntrinsicCrossAxis
(
constraints
,
BoxConstraints
innerConstraints
=
new
BoxConstraints
.
tightFor
(
width:
width
);
(
c
,
innerConstraints
)
=>
c
.
getMinIntrinsicWidth
(
innerConstraints
));
RenderBox
child
=
firstChild
;
}
while
(
child
!=
null
)
{
return
_getIntrinsicMainAxis
(
constraints
);
double
childHeight
=
child
.
getMinIntrinsicHeight
(
innerConstraints
);
}
assert
(
childHeight
==
child
.
getMaxIntrinsicHeight
(
innerConstraints
));
height
+=
childHeight
;
double
getMaxIntrinsicWidth
(
BoxConstraints
constraints
)
{
assert
(
child
.
parentData
is
BlockParentData
);
if
(
_isVertical
)
{
child
=
child
.
parentData
.
nextSibling
;
return
_getIntrinsicCrossAxis
(
constraints
,
(
c
,
innerConstraints
)
=>
c
.
getMaxIntrinsicWidth
(
innerConstraints
));
}
}
return
height
;
return
_getIntrinsicMainAxis
(
constraints
)
;
}
}
double
getMinIntrinsicHeight
(
BoxConstraints
constraints
)
{
double
getMinIntrinsicHeight
(
BoxConstraints
constraints
)
{
return
_getIntrinsicHeight
(
constraints
);
if
(
_isVertical
)
return
_getIntrinsicMainAxis
(
constraints
);
return
_getIntrinsicCrossAxis
(
constraints
,
(
c
,
innerConstraints
)
=>
c
.
getMinIntrinsicWidth
(
innerConstraints
));
}
}
double
getMaxIntrinsicHeight
(
BoxConstraints
constraints
)
{
double
getMaxIntrinsicHeight
(
BoxConstraints
constraints
)
{
return
_getIntrinsicHeight
(
constraints
);
if
(
_isVertical
)
return
_getIntrinsicMainAxis
(
constraints
);
return
_getIntrinsicCrossAxis
(
constraints
,
(
c
,
innerConstraints
)
=>
c
.
getMaxIntrinsicWidth
(
innerConstraints
));
}
}
double
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
double
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
return
defaultComputeDistanceToFirstActualBaseline
(
baseline
);
return
defaultComputeDistanceToFirstActualBaseline
(
baseline
);
}
}
double
get
_mainAxisExtent
{
RenderBox
child
=
lastChild
;
if
(
child
==
null
)
return
0.0
;
BoxParentData
parentData
=
child
.
parentData
;
return
_isVertical
?
parentData
.
position
.
y
+
child
.
size
.
height
:
parentData
.
position
.
x
+
child
.
size
.
width
;
}
void
performLayout
()
{
void
performLayout
()
{
assert
(
constraints
.
maxHeight
>=
double
.
INFINITY
);
assert
(
_isVertical
?
constraints
.
maxHeight
>=
double
.
INFINITY
:
constraints
.
maxWidth
>=
double
.
INFINITY
);
super
.
performLayout
();
super
.
performLayout
();
size
=
constraints
.
constrain
(
new
Size
(
constraints
.
maxWidth
,
childrenHeight
));
size
=
_isVertical
?
constraints
.
constrain
(
new
Size
(
constraints
.
maxWidth
,
_mainAxisExtent
))
:
constraints
.
constrain
(
new
Size
(
_mainAxisExtent
,
constraints
.
maxHeight
));
assert
(!
size
.
isInfinite
);
assert
(!
size
.
isInfinite
);
}
}
...
...
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