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
ef866e00
Commit
ef866e00
authored
Nov 05, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace Align shrinkWrap parameter with widthFactor and heightFactor
parent
aaee3b93
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
41 deletions
+72
-41
scrollbar.dart
examples/widgets/scrollbar.dart
+2
-1
material_button.dart
packages/flutter/lib/src/material/material_button.dart
+1
-1
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+1
-1
shifted_box.dart
packages/flutter/lib/src/rendering/shifted_box.dart
+28
-25
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+10
-10
positioned_box_test.dart
packages/unit/test/rendering/positioned_box_test.dart
+30
-3
No files found.
examples/widgets/scrollbar.dart
View file @
ef866e00
...
@@ -33,7 +33,8 @@ class ScrollbarAppState extends State<ScrollbarApp> {
...
@@ -33,7 +33,8 @@ class ScrollbarAppState extends State<ScrollbarApp> {
Widget
scrollable
=
new
Container
(
Widget
scrollable
=
new
Container
(
margin:
new
EdgeDims
.
symmetric
(
horizontal:
6.0
),
// TODO(hansmuller) 6.0 should be based on _kScrollbarThumbWidth
margin:
new
EdgeDims
.
symmetric
(
horizontal:
6.0
),
// TODO(hansmuller) 6.0 should be based on _kScrollbarThumbWidth
child:
new
Center
(
child:
new
Center
(
shrinkWrap:
ShrinkWrap
.
both
,
widthFactor:
1.0
,
heightFactor:
1.0
,
child:
new
Container
(
child:
new
Container
(
width:
80.0
,
width:
80.0
,
height:
_itemExtent
*
5.0
,
height:
_itemExtent
*
5.0
,
...
...
packages/flutter/lib/src/material/material_button.dart
View file @
ef866e00
...
@@ -92,7 +92,7 @@ abstract class MaterialButtonState<T extends MaterialButton> extends State<T> {
...
@@ -92,7 +92,7 @@ abstract class MaterialButtonState<T extends MaterialButton> extends State<T> {
Widget
contents
=
new
Container
(
Widget
contents
=
new
Container
(
padding:
new
EdgeDims
.
symmetric
(
horizontal:
8.0
),
padding:
new
EdgeDims
.
symmetric
(
horizontal:
8.0
),
child:
new
Center
(
child:
new
Center
(
shrinkWrap:
ShrinkWrap
.
width
,
widthFactor:
1.0
,
child:
config
.
child
child:
config
.
child
)
)
);
);
...
...
packages/flutter/lib/src/material/tabs.dart
View file @
ef866e00
...
@@ -344,7 +344,7 @@ class Tab extends StatelessComponent {
...
@@ -344,7 +344,7 @@ class Tab extends StatelessComponent {
}
}
Container
centeredLabel
=
new
Container
(
Container
centeredLabel
=
new
Container
(
child:
new
Center
(
child:
labelContent
,
shrinkWrap:
ShrinkWrap
.
both
),
child:
new
Center
(
child:
labelContent
,
widthFactor:
1.0
,
heightFactor:
1.0
),
constraints:
new
BoxConstraints
(
minWidth:
_kMinTabWidth
),
constraints:
new
BoxConstraints
(
minWidth:
_kMinTabWidth
),
padding:
_kTabLabelPadding
padding:
_kTabLabelPadding
);
);
...
...
packages/flutter/lib/src/rendering/shifted_box.dart
View file @
ef866e00
...
@@ -143,13 +143,6 @@ class RenderPadding extends RenderShiftedBox {
...
@@ -143,13 +143,6 @@ class RenderPadding extends RenderShiftedBox {
}
}
}
}
enum
ShrinkWrap
{
width
,
height
,
both
,
none
}
class
RenderPositionedBox
extends
RenderShiftedBox
{
class
RenderPositionedBox
extends
RenderShiftedBox
{
// This box aligns a child box within itself. It's only useful for
// This box aligns a child box within itself. It's only useful for
...
@@ -161,12 +154,13 @@ class RenderPositionedBox extends RenderShiftedBox {
...
@@ -161,12 +154,13 @@ class RenderPositionedBox extends RenderShiftedBox {
RenderPositionedBox
({
RenderPositionedBox
({
RenderBox
child
,
RenderBox
child
,
FractionalOffset
alignment:
const
FractionalOffset
(
0.5
,
0.5
),
FractionalOffset
alignment:
const
FractionalOffset
(
0.5
,
0.5
),
ShrinkWrap
shrinkWrap:
ShrinkWrap
.
none
double
widthFactor
,
double
heightFactor
})
:
_alignment
=
alignment
,
})
:
_alignment
=
alignment
,
_shrinkWrap
=
shrinkWrap
,
_widthFactor
=
widthFactor
,
_heightFactor
=
heightFactor
,
super
(
child
)
{
super
(
child
)
{
assert
(
alignment
!=
null
);
assert
(
alignment
!=
null
);
assert
(
shrinkWrap
!=
null
);
}
}
FractionalOffset
get
alignment
=>
_alignment
;
FractionalOffset
get
alignment
=>
_alignment
;
...
@@ -179,31 +173,40 @@ class RenderPositionedBox extends RenderShiftedBox {
...
@@ -179,31 +173,40 @@ class RenderPositionedBox extends RenderShiftedBox {
markNeedsLayout
();
markNeedsLayout
();
}
}
ShrinkWrap
_shrinkWrap
;
double
_widthFactor
;
ShrinkWrap
get
shrinkWrap
=>
_shrinkWrap
;
double
get
widthFactor
=>
_widthFactor
;
void
set
shrinkWrap
(
ShrinkWrap
value
)
{
void
set
widthFactor
(
double
value
)
{
assert
(
value
!=
null
);
if
(
_widthFactor
==
value
)
if
(
_shrinkWrap
==
value
)
return
;
return
;
_
shrinkWrap
=
value
;
_
widthFactor
=
value
;
markNeedsLayout
();
markNeedsLayout
();
}
}
// These are only valid during performLayout() and paint(), since they rely on constraints which is only set after layout() is called.
double
_heightFactor
;
bool
get
_shinkWrapWidth
=>
_shrinkWrap
==
ShrinkWrap
.
width
||
_shrinkWrap
==
ShrinkWrap
.
both
||
constraints
.
maxWidth
==
double
.
INFINITY
;
double
get
heightFactor
=>
_heightFactor
;
bool
get
_shinkWrapHeight
=>
_shrinkWrap
==
ShrinkWrap
.
height
||
_shrinkWrap
==
ShrinkWrap
.
both
||
constraints
.
maxHeight
==
double
.
INFINITY
;
void
set
heightFactor
(
double
value
)
{
if
(
_heightFactor
==
value
)
return
;
_heightFactor
=
value
;
markNeedsLayout
();
}
void
performLayout
()
{
void
performLayout
()
{
final
bool
shrinkWrapWidth
=
widthFactor
!=
null
||
constraints
.
maxWidth
==
double
.
INFINITY
;
final
bool
shrinkWrapHeight
=
heightFactor
!=
null
||
constraints
.
maxHeight
==
double
.
INFINITY
;
if
(
child
!=
null
)
{
if
(
child
!=
null
)
{
child
.
layout
(
constraints
.
loosen
(),
parentUsesSize:
true
);
child
.
layout
(
constraints
.
loosen
(),
parentUsesSize:
true
);
size
=
constraints
.
constrain
(
new
Size
(
_shinkWrapWidth
?
child
.
size
.
width
:
double
.
INFINITY
,
final
Size
desiredSize
=
new
Size
(
child
.
size
.
width
*
(
_widthFactor
??
1.0
),
_shinkWrapHeight
?
child
.
size
.
height
:
double
.
INFINITY
));
child
.
size
.
height
*
(
_heightFactor
??
1.0
));
Offset
delta
=
size
-
child
.
size
;
size
=
constraints
.
constrain
(
new
Size
(
shrinkWrapWidth
?
desiredSize
.
width
:
double
.
INFINITY
,
shrinkWrapHeight
?
desiredSize
.
height
:
double
.
INFINITY
));
final
Offset
delta
=
size
-
desiredSize
;
final
BoxParentData
childParentData
=
child
.
parentData
;
final
BoxParentData
childParentData
=
child
.
parentData
;
childParentData
.
position
=
(
delta
.
scale
(
_alignment
.
x
,
_alignment
.
y
)
).
toPoint
();
childParentData
.
position
=
delta
.
scale
(
_alignment
.
x
,
_alignment
.
y
).
toPoint
();
}
else
{
}
else
{
size
=
constraints
.
constrain
(
new
Size
(
_sh
inkWrapWidth
?
0.0
:
double
.
INFINITY
,
size
=
constraints
.
constrain
(
new
Size
(
shr
inkWrapWidth
?
0.0
:
double
.
INFINITY
,
_sh
inkWrapHeight
?
0.0
:
double
.
INFINITY
));
shr
inkWrapHeight
?
0.0
:
double
.
INFINITY
));
}
}
}
}
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
ef866e00
...
@@ -48,7 +48,6 @@ export 'package:flutter/rendering.dart' show
...
@@ -48,7 +48,6 @@ export 'package:flutter/rendering.dart' show
Rect
,
Rect
,
ScrollDirection
,
ScrollDirection
,
Shape
,
Shape
,
ShrinkWrap
,
Size
,
Size
,
StyledTextSpan
,
StyledTextSpan
,
TextAlign
,
TextAlign
,
...
@@ -238,26 +237,27 @@ class Align extends OneChildRenderObjectWidget {
...
@@ -238,26 +237,27 @@ class Align extends OneChildRenderObjectWidget {
Align
({
Align
({
Key
key
,
Key
key
,
this
.
alignment
:
const
FractionalOffset
(
0.5
,
0.5
),
this
.
alignment
:
const
FractionalOffset
(
0.5
,
0.5
),
this
.
shrinkWrap
:
ShrinkWrap
.
none
,
this
.
widthFactor
,
this
.
heightFactor
,
Widget
child
Widget
child
})
:
super
(
key:
key
,
child:
child
)
{
})
:
super
(
key:
key
,
child:
child
);
assert
(
shrinkWrap
!=
null
);
}
final
FractionalOffset
alignment
;
final
FractionalOffset
alignment
;
final
ShrinkWrap
shrinkWrap
;
final
double
widthFactor
;
final
double
heightFactor
;
RenderPositionedBox
createRenderObject
()
=>
new
RenderPositionedBox
(
alignment:
alignment
,
shrinkWrap:
shrinkWrap
);
RenderPositionedBox
createRenderObject
()
=>
new
RenderPositionedBox
(
alignment:
alignment
,
widthFactor:
widthFactor
,
heightFactor:
heightFactor
);
void
updateRenderObject
(
RenderPositionedBox
renderObject
,
Align
oldWidget
)
{
void
updateRenderObject
(
RenderPositionedBox
renderObject
,
Align
oldWidget
)
{
renderObject
.
alignment
=
alignment
;
renderObject
.
alignment
=
alignment
;
renderObject
.
shrinkWrap
=
shrinkWrap
;
renderObject
.
widthFactor
=
widthFactor
;
renderObject
.
heightFactor
=
heightFactor
;
}
}
}
}
class
Center
extends
Align
{
class
Center
extends
Align
{
Center
({
Key
key
,
ShrinkWrap
shrinkWrap:
ShrinkWrap
.
none
,
Widget
child
})
Center
({
Key
key
,
widthFactor
,
heightFactor
,
Widget
child
})
:
super
(
key:
key
,
shrinkWrap:
shrinkWrap
,
child:
child
);
:
super
(
key:
key
,
widthFactor:
widthFactor
,
heightFactor:
heightFactor
,
child:
child
);
}
}
class
CustomOneChildLayout
extends
OneChildRenderObjectWidget
{
class
CustomOneChildLayout
extends
OneChildRenderObjectWidget
{
...
...
packages/unit/test/rendering/positioned_box_test.dart
View file @
ef866e00
...
@@ -21,22 +21,49 @@ void main() {
...
@@ -21,22 +21,49 @@ void main() {
additionalConstraints:
new
BoxConstraints
.
tight
(
new
Size
(
100.0
,
100.0
)),
additionalConstraints:
new
BoxConstraints
.
tight
(
new
Size
(
100.0
,
100.0
)),
child:
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
())
child:
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
())
);
);
RenderPositionedBox
positioner
=
new
RenderPositionedBox
(
child:
sizer
,
shrinkWrap:
ShrinkWrap
.
width
);
RenderPositionedBox
positioner
=
new
RenderPositionedBox
(
child:
sizer
,
widthFactor:
1.0
);
layout
(
positioner
,
constraints:
new
BoxConstraints
.
loose
(
new
Size
(
200.0
,
200.0
)));
layout
(
positioner
,
constraints:
new
BoxConstraints
.
loose
(
new
Size
(
200.0
,
200.0
)));
expect
(
positioner
.
size
.
width
,
equals
(
100.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
width
,
equals
(
100.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
height
,
equals
(
200.0
),
reason:
"positioner height"
);
expect
(
positioner
.
size
.
height
,
equals
(
200.0
),
reason:
"positioner height"
);
positioner
.
shrinkWrap
=
ShrinkWrap
.
height
;
positioner
.
widthFactor
=
null
;
positioner
.
heightFactor
=
1.0
;
pumpFrame
();
pumpFrame
();
expect
(
positioner
.
size
.
width
,
equals
(
200.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
width
,
equals
(
200.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
height
,
equals
(
100.0
),
reason:
"positioner height"
);
expect
(
positioner
.
size
.
height
,
equals
(
100.0
),
reason:
"positioner height"
);
positioner
.
shrinkWrap
=
ShrinkWrap
.
both
;
positioner
.
widthFactor
=
1.0
;
pumpFrame
();
pumpFrame
();
expect
(
positioner
.
size
.
width
,
equals
(
100.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
width
,
equals
(
100.0
),
reason:
"positioner width"
);
expect
(
positioner
.
size
.
height
,
equals
(
100.0
),
reason:
"positioner height"
);
expect
(
positioner
.
size
.
height
,
equals
(
100.0
),
reason:
"positioner height"
);
});
});
test
(
'RenderPositionedBox width and height factors'
,
()
{
RenderConstrainedBox
sizer
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tight
(
new
Size
(
100.0
,
100.0
)),
child:
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
())
);
RenderPositionedBox
positioner
=
new
RenderPositionedBox
(
child:
sizer
,
widthFactor:
1.0
,
heightFactor:
0.0
);
layout
(
positioner
,
constraints:
new
BoxConstraints
.
loose
(
new
Size
(
200.0
,
200.0
)));
expect
(
positioner
.
size
.
width
,
equals
(
100.0
));
expect
(
positioner
.
size
.
height
,
equals
(
0.0
));
positioner
.
widthFactor
=
0.5
;
positioner
.
heightFactor
=
0.5
;
pumpFrame
();
expect
(
positioner
.
size
.
width
,
equals
(
50.0
));
expect
(
positioner
.
size
.
height
,
equals
(
50.0
));
positioner
.
widthFactor
=
null
;
positioner
.
heightFactor
=
null
;
pumpFrame
();
expect
(
positioner
.
size
.
width
,
equals
(
200.0
));
expect
(
positioner
.
size
.
height
,
equals
(
200.0
));
});
}
}
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