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
b58f850e
Commit
b58f850e
authored
Aug 27, 2015
by
Eric Seidel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a Widget wrapper around Grid and test RenderGrid
@abarth
parent
0d4b9970
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
5 deletions
+71
-5
grid.dart
packages/flutter/lib/rendering/grid.dart
+15
-4
basic.dart
packages/flutter/lib/widgets/basic.dart
+16
-1
grid_test.dart
packages/unit/test/rendering/grid_test.dart
+40
-0
No files found.
packages/flutter/lib/rendering/grid.dart
View file @
b58f850e
...
...
@@ -10,11 +10,14 @@ class GridParentData extends BoxParentData with ContainerParentDataMixin<RenderB
class
GridMetrics
{
// Grid is width-in, height-out. We fill the max width and adjust height
// accordingly.
factory
GridMetrics
({
double
width
,
int
childCount
,
double
c
hildExtent
})
{
factory
GridMetrics
({
double
width
,
int
childCount
,
double
maxC
hildExtent
})
{
assert
(
width
!=
null
);
assert
(
childCount
!=
null
);
assert
(
childExtent
!=
null
);
int
childrenPerRow
=
(
width
/
childExtent
).
floor
()
+
1
;
assert
(
maxChildExtent
!=
null
);
double
childExtent
=
maxChildExtent
;
int
childrenPerRow
=
(
width
/
childExtent
).
floor
();
// If the child extent divides evenly into the width use that, otherwise + 1
if
(
width
/
childExtent
!=
childrenPerRow
.
toDouble
())
childrenPerRow
+=
1
;
double
totalPadding
=
0.0
;
if
(
childrenPerRow
*
childExtent
>
width
)
{
// TODO(eseidel): We should snap to pixel bounderies.
...
...
@@ -50,6 +53,14 @@ class RenderGrid extends RenderBox with ContainerRenderObjectMixin<RenderBox, Gr
double
_maxChildExtent
;
bool
_hasVisualOverflow
=
false
;
double
get
maxChildExtent
=>
_maxChildExtent
;
void
set
maxChildExtent
(
double
value
)
{
if
(
_maxChildExtent
!=
value
)
{
_maxChildExtent
=
value
;
markNeedsLayout
();
}
}
void
setupParentData
(
RenderBox
child
)
{
if
(
child
.
parentData
is
!
GridParentData
)
child
.
parentData
=
new
GridParentData
();
...
...
@@ -93,7 +104,7 @@ class RenderGrid extends RenderBox with ContainerRenderObjectMixin<RenderBox, Gr
return
new
GridMetrics
(
width:
constraints
.
maxWidth
,
childCount:
childCount
,
c
hildExtent:
_maxChildExtent
maxC
hildExtent:
_maxChildExtent
);
}
...
...
packages/flutter/lib/widgets/basic.dart
View file @
b58f850e
...
...
@@ -14,6 +14,7 @@ import 'package:sky/painting/paragraph_painter.dart';
import
'package:sky/rendering/block.dart'
;
import
'package:sky/rendering/box.dart'
;
import
'package:sky/rendering/flex.dart'
;
import
'package:sky/rendering/grid.dart'
;
import
'package:sky/rendering/image.dart'
;
import
'package:sky/rendering/object.dart'
;
import
'package:sky/rendering/paragraph.dart'
;
...
...
@@ -454,6 +455,21 @@ class Stack extends MultiChildRenderObjectWrapper {
RenderStack
get
renderObject
=>
super
.
renderObject
;
}
class
Grid
extends
MultiChildRenderObjectWrapper
{
Grid
(
List
<
Widget
>
children
,
{
Key
key
,
this
.
maxChildExtent
})
:
super
(
key:
key
,
children:
children
);
final
double
maxChildExtent
;
RenderGrid
createNode
()
=>
new
RenderGrid
(
maxChildExtent:
maxChildExtent
);
RenderGrid
get
renderObject
=>
super
.
renderObject
;
void
syncRenderObject
(
Widget
old
)
{
super
.
syncRenderObject
(
old
);
renderObject
.
maxChildExtent
=
maxChildExtent
;
}
}
class
Positioned
extends
ParentDataNode
{
Positioned
({
Key
key
,
...
...
@@ -495,7 +511,6 @@ class Flex extends MultiChildRenderObjectWrapper {
renderObject
.
alignItems
=
alignItems
;
renderObject
.
textBaseline
=
textBaseline
;
}
}
class
Row
extends
Flex
{
...
...
packages/unit/test/rendering/grid_test.dart
0 → 100644
View file @
b58f850e
import
'package:sky/rendering.dart'
;
import
'package:test/test.dart'
;
import
'rendering_tester.dart'
;
void
main
(
)
{
test
(
'Basic grid layout test'
,
()
{
List
<
RenderBox
>
children
=
[
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
()),
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
()),
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
()),
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
())
];
RenderBox
grid
=
new
RenderGrid
(
children:
children
,
maxChildExtent:
100.0
);
RenderingTester
tester
=
layout
(
grid
,
constraints:
const
BoxConstraints
(
maxWidth:
200.0
));
children
.
forEach
((
child
)
{
expect
(
child
.
size
.
width
,
equals
(
100.0
),
reason:
"child width"
);
expect
(
child
.
size
.
height
,
equals
(
100.0
),
reason:
"child height"
);
});
expect
(
grid
.
size
.
width
,
equals
(
200.0
),
reason:
"grid width"
);
expect
(
grid
.
size
.
height
,
equals
(
200.0
),
reason:
"grid height"
);
expect
(
grid
.
needsLayout
,
equals
(
false
));
grid
.
maxChildExtent
=
60.0
;
expect
(
grid
.
needsLayout
,
equals
(
true
));
tester
.
pumpFrame
(
phase:
EnginePhase
.
layout
);
children
.
forEach
((
child
)
{
expect
(
child
.
size
.
width
,
equals
(
50.0
),
reason:
"child width"
);
expect
(
child
.
size
.
height
,
equals
(
50.0
),
reason:
"child height"
);
});
expect
(
grid
.
size
.
width
,
equals
(
200.0
),
reason:
"grid width"
);
expect
(
grid
.
size
.
height
,
equals
(
50.0
),
reason:
"grid height"
);
});
}
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