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
7a2c38ab
Commit
7a2c38ab
authored
Feb 16, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1903 from abarth/auto_simplify
Simplify the AutoLayout API
parents
ce278e97
4408c820
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
183 additions
and
176 deletions
+183
-176
autolayout.dart
examples/layers/rendering/autolayout.dart
+21
-21
autolayout.dart
examples/layers/widgets/autolayout.dart
+42
-38
equation_member.dart
packages/cassowary/lib/equation_member.dart
+1
-1
expression.dart
packages/cassowary/lib/expression.dart
+2
-2
cassowary_test.dart
packages/cassowary/test/cassowary_test.dart
+11
-11
auto_layout.dart
packages/flutter/lib/src/rendering/auto_layout.dart
+101
-98
auto_layout.dart
packages/flutter/lib/src/widgets/auto_layout.dart
+5
-5
No files found.
examples/layers/rendering/autolayout.dart
View file @
7a2c38ab
...
...
@@ -9,38 +9,38 @@ import 'package:cassowary/cassowary.dart' as al;
import
'package:flutter/rendering.dart'
;
class
_MyAutoLayoutDelegate
extends
AutoLayoutDelegate
{
AutoLayout
Params
p1
=
new
AutoLayoutParams
();
AutoLayout
Params
p2
=
new
AutoLayoutParams
();
AutoLayout
Params
p3
=
new
AutoLayoutParams
();
AutoLayout
Params
p4
=
new
AutoLayoutParams
();
AutoLayout
Rect
p1
=
new
AutoLayoutRect
();
AutoLayout
Rect
p2
=
new
AutoLayoutRect
();
AutoLayout
Rect
p3
=
new
AutoLayoutRect
();
AutoLayout
Rect
p4
=
new
AutoLayoutRect
();
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Params
parentParams
)
{
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Rect
parent
)
{
return
<
al
.
Constraint
>[
// Sum of widths of each box must be equal to that of the container
(
p1
.
width
+
p2
.
width
+
p3
.
width
==
parentParams
.
width
)
as
al
.
Constraint
,
parent
.
width
.
equals
(
p1
.
width
+
p2
.
width
+
p3
.
width
)
,
// The boxes must be stacked left to right
p1
.
right
Edge
<=
p2
.
leftEdge
,
p2
.
right
Edge
<=
p3
.
leftEdge
,
p1
.
right
<=
p2
.
left
,
p2
.
right
<=
p3
.
left
,
// The widths of the first and the third boxes should be equal
(
p1
.
width
==
p3
.
width
)
as
al
.
Constraint
,
p1
.
width
.
equals
(
p3
.
width
)
,
// The width of the second box should be twice as much as that of the first
// and third
(
p2
.
width
*
al
.
cm
(
2.0
)
==
p1
.
width
)
as
al
.
Constraint
,
p1
.
width
.
equals
(
p2
.
width
*
al
.
cm
(
2.0
))
,
// The height of the three boxes should be equal to that of the container
(
p1
.
height
==
p2
.
height
)
as
al
.
Constraint
,
(
p2
.
height
==
p3
.
height
)
as
al
.
Constraint
,
(
p3
.
height
==
parentParams
.
height
)
as
al
.
Constraint
,
p1
.
height
.
equals
(
p2
.
height
)
,
p2
.
height
.
equals
(
p3
.
height
)
,
p3
.
height
.
equals
(
parent
.
height
)
,
// The fourth box should be half as wide as the second and must be attached
// to the right edge of the same (by its center)
(
p4
.
width
==
p2
.
width
/
al
.
cm
(
2.0
))
as
al
.
Constraint
,
(
p4
.
height
==
al
.
cm
(
50.0
))
as
al
.
Constraint
,
(
p4
.
horizontalCenter
==
p2
.
rightEdge
)
as
al
.
Constraint
,
(
p4
.
verticalCenter
==
p2
.
height
/
al
.
cm
(
2.0
))
as
al
.
Constraint
,
p4
.
width
.
equals
(
p2
.
width
/
al
.
cm
(
2.0
))
,
p4
.
height
.
equals
(
al
.
cm
(
50.0
))
,
p4
.
horizontalCenter
.
equals
(
p2
.
right
)
,
p4
.
verticalCenter
.
equals
(
p2
.
height
/
al
.
cm
(
2.0
))
,
];
}
...
...
@@ -76,10 +76,10 @@ void main() {
AutoLayoutParentData
parentData3
=
c3
.
parentData
;
AutoLayoutParentData
parentData4
=
c4
.
parentData
;
parentData1
.
params
=
delegate
.
p1
;
parentData2
.
params
=
delegate
.
p2
;
parentData3
.
params
=
delegate
.
p3
;
parentData4
.
params
=
delegate
.
p4
;
parentData1
.
rect
=
delegate
.
p1
;
parentData2
.
rect
=
delegate
.
p2
;
parentData3
.
rect
=
delegate
.
p3
;
parentData4
.
rect
=
delegate
.
p4
;
new
RenderingFlutterBinding
(
root:
root
);
}
examples/layers/widgets/autolayout.dart
View file @
7a2c38ab
...
...
@@ -8,58 +8,42 @@ import 'package:cassowary/cassowary.dart' as al;
import
'package:flutter/widgets.dart'
;
class
_MyAutoLayoutDelegate
extends
AutoLayoutDelegate
{
AutoLayout
Params
p1
=
new
AutoLayoutParams
();
AutoLayout
Params
p2
=
new
AutoLayoutParams
();
AutoLayout
Params
p3
=
new
AutoLayoutParams
();
AutoLayout
Params
p4
=
new
AutoLayoutParams
();
AutoLayout
Rect
p1
=
new
AutoLayoutRect
();
AutoLayout
Rect
p2
=
new
AutoLayoutRect
();
AutoLayout
Rect
p3
=
new
AutoLayoutRect
();
AutoLayout
Rect
p4
=
new
AutoLayoutRect
();
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Params
parentParams
)
{
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Rect
parent
)
{
return
<
al
.
Constraint
>[
// Sum of widths of each box must be equal to that of the container
(
p1
.
width
+
p2
.
width
+
p3
.
width
==
parentParams
.
width
)
as
al
.
Constraint
,
parent
.
width
.
equals
(
p1
.
width
+
p2
.
width
+
p3
.
width
)
,
// The boxes must be stacked left to right
p1
.
right
Edge
<=
p2
.
leftEdge
,
p2
.
right
Edge
<=
p3
.
leftEdge
,
p1
.
right
<=
p2
.
left
,
p2
.
right
<=
p3
.
left
,
// The widths of the first and the third boxes should be equal
(
p1
.
width
==
p3
.
width
)
as
al
.
Constraint
,
p1
.
width
.
equals
(
p3
.
width
)
,
// The width of the second box should be twice as much as that of the first
// and third
(
p2
.
width
*
al
.
cm
(
2.0
)
==
p1
.
width
)
as
al
.
Constraint
,
p1
.
width
.
equals
(
p2
.
width
*
al
.
cm
(
2.0
))
,
// The height of the three boxes should be equal to that of the container
(
p1
.
height
==
p2
.
height
)
as
al
.
Constraint
,
(
p2
.
height
==
p3
.
height
)
as
al
.
Constraint
,
(
p3
.
height
==
parentParams
.
height
)
as
al
.
Constraint
,
p1
.
height
.
equals
(
p2
.
height
)
,
p2
.
height
.
equals
(
p3
.
height
)
,
p3
.
height
.
equals
(
parent
.
height
)
,
// The fourth box should be half as wide as the second and must be attached
// to the right edge of the same (by its center)
(
p4
.
width
==
p2
.
width
/
al
.
cm
(
2.0
))
as
al
.
Constraint
,
(
p4
.
height
==
al
.
cm
(
50.0
))
as
al
.
Constraint
,
(
p4
.
horizontalCenter
==
p2
.
rightEdge
)
as
al
.
Constraint
,
(
p4
.
verticalCenter
==
p2
.
height
/
al
.
cm
(
2.0
))
as
al
.
Constraint
,
p4
.
width
.
equals
(
p2
.
width
/
al
.
cm
(
2.0
))
,
p4
.
height
.
equals
(
al
.
cm
(
50.0
))
,
p4
.
horizontalCenter
.
equals
(
p2
.
right
)
,
p4
.
verticalCenter
.
equals
(
p2
.
height
/
al
.
cm
(
2.0
))
,
];
}
bool
shouldUpdateConstraints
(
AutoLayoutDelegate
oldDelegate
)
=>
true
;
}
class
ColoredBox
extends
StatelessComponent
{
ColoredBox
({
Key
key
,
this
.
params
,
this
.
color
})
:
super
(
key:
key
);
final
AutoLayoutParams
params
;
final
Color
color
;
Widget
build
(
BuildContext
context
)
{
return
new
AutoLayoutChild
(
params:
params
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
color
)
)
);
}
bool
shouldUpdateConstraints
(
_MyAutoLayoutDelegate
oldDelegate
)
=>
true
;
}
class
ColoredBoxes
extends
StatefulComponent
{
...
...
@@ -73,10 +57,30 @@ class _ColoredBoxesState extends State<ColoredBoxes> {
return
new
AutoLayout
(
delegate:
delegate
,
children:
<
Widget
>[
new
ColoredBox
(
params:
delegate
.
p1
,
color:
const
Color
(
0xFFFF0000
)),
new
ColoredBox
(
params:
delegate
.
p2
,
color:
const
Color
(
0xFF00FF00
)),
new
ColoredBox
(
params:
delegate
.
p3
,
color:
const
Color
(
0xFF0000FF
)),
new
ColoredBox
(
params:
delegate
.
p4
,
color:
const
Color
(
0xFFFFFFFF
)),
new
AutoLayoutChild
(
rect:
delegate
.
p1
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
))
)
),
new
AutoLayoutChild
(
rect:
delegate
.
p2
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
))
)
),
new
AutoLayoutChild
(
rect:
delegate
.
p3
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF0000FF
))
)
),
new
AutoLayoutChild
(
rect:
delegate
.
p4
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFFFFFF
))
)
),
]
);
}
...
...
packages/cassowary/lib/equation_member.dart
View file @
7a2c38ab
...
...
@@ -15,7 +15,7 @@ abstract class _EquationMember {
Constraint
operator
<=(
_EquationMember
m
)
=>
asExpression
()
<=
m
;
operator
==(
_EquationMember
m
)
=>
asExpression
()
==
m
;
Constraint
equals
(
_EquationMember
m
)
=>
asExpression
().
equals
(
m
)
;
Expression
operator
+(
_EquationMember
m
)
=>
asExpression
()
+
m
;
...
...
packages/cassowary/lib/expression.dart
View file @
7a2c38ab
...
...
@@ -57,8 +57,8 @@ class Expression extends _EquationMember {
Constraint
operator
<=(
_EquationMember
value
)
=>
_createConstraint
(
value
,
Relation
.
lessThanOrEqualTo
);
operator
==
(
_EquationMember
value
)
=>
_createConstraint
(
value
,
Relation
.
equalTo
);
// analyzer says "Type check failed" // analyzer says "The return type 'Constraint' is not a 'bool', as defined by the method '=='"
Constraint
equals
(
_EquationMember
value
)
=>
_createConstraint
(
value
,
Relation
.
equalTo
);
Expression
operator
+(
_EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
...
...
packages/cassowary/test/cassowary_test.dart
View file @
7a2c38ab
...
...
@@ -243,7 +243,7 @@ void main() {
expect
(
c1
.
expression
.
constant
,
-
20.0
);
expect
(
c1
.
relation
,
Relation
.
greaterThanOrEqualTo
);
var
c2
=
(
right
-
left
==
cm
(
30.0
))
as
Constraint
;
var
c2
=
(
right
-
left
).
equals
(
cm
(
30.0
))
;
expect
(
c2
is
Constraint
,
true
);
expect
(
c2
.
expression
.
constant
,
-
30.0
);
expect
(
c2
.
relation
,
Relation
.
equalTo
);
...
...
@@ -438,7 +438,7 @@ void main() {
Solver
s
=
new
Solver
();
expect
(
s
.
addConstraint
((
right
+
left
==
mid
*
cm
(
2.0
))
as
Constraint
),
expect
(
s
.
addConstraint
((
right
+
left
).
equals
(
mid
*
cm
(
2.0
))
),
Result
.
success
);
expect
(
s
.
addConstraint
(
right
-
left
>=
cm
(
100.0
)),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
cm
(
0.0
)),
Result
.
success
);
...
...
@@ -460,7 +460,7 @@ void main() {
var
c
=
(
left
>=
cm
(
0.0
));
expect
(
s
.
addConstraints
([
(
left
+
right
==
cm
(
2.0
)
*
mid
)
as
Constraint
,
(
left
+
right
).
equals
(
cm
(
2.0
)
*
mid
)
,
(
right
-
left
>=
cm
(
100.0
)),
c
]),
Result
.
success
);
...
...
@@ -476,7 +476,7 @@ void main() {
Solver
s
=
new
Solver
();
expect
(
s
.
addConstraint
((
right
+
left
==
mid
*
cm
(
2.0
))
as
Constraint
),
expect
(
s
.
addConstraint
((
right
+
left
).
equals
(
mid
*
cm
(
2.0
))
),
Result
.
success
);
expect
(
s
.
addConstraint
(
right
-
left
>=
cm
(
100.0
)),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
cm
(
0.0
)),
Result
.
success
);
...
...
@@ -496,7 +496,7 @@ void main() {
var
right
=
new
Param
(
100.0
);
var
c1
=
right
>=
left
;
var
c2
=
right
<=
left
;
var
c3
=
(
right
==
left
)
as
Constraint
;
var
c3
=
right
.
equals
(
left
)
;
Solver
s
=
new
Solver
();
expect
(
s
.
addConstraint
(
c1
),
Result
.
success
);
...
...
@@ -519,9 +519,9 @@ void main() {
solver
.
suggestValueForVariable
(
container
.
variable
,
100.0
);
solver
.
addConstraint
((
p1
>=
cm
(
30.0
))
|
Priority
.
strong
);
solver
.
addConstraint
(
((
p1
==
p3
)
as
Constraint
)
|
Priority
.
medium
);
solver
.
addConstraint
(
(
p2
==
cm
(
2.0
)
*
p1
)
as
Constraint
);
solver
.
addConstraint
(
(
container
==
(
p1
+
p2
+
p3
))
as
Constraint
);
solver
.
addConstraint
(
p1
.
equals
(
p3
)
|
Priority
.
medium
);
solver
.
addConstraint
(
p2
.
equals
(
cm
(
2.0
)
*
p1
)
);
solver
.
addConstraint
(
container
.
equals
(
p1
+
p2
+
p3
)
);
solver
.
flushUpdates
();
...
...
@@ -541,7 +541,7 @@ void main() {
expect
(
s
.
addEditVariable
(
mid
.
variable
,
Priority
.
strong
),
Result
.
success
);
expect
(
s
.
addConstraint
((
mid
*
cm
(
2.0
)
==
left
+
right
)
as
Constraint
),
expect
(
s
.
addConstraint
((
mid
*
cm
(
2.0
)
).
equals
(
left
+
right
)
),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
cm
(
0.0
)),
Result
.
success
);
...
...
@@ -565,7 +565,7 @@ void main() {
expect
(
s
.
addEditVariable
(
mid
.
variable
,
Priority
.
strong
),
Result
.
success
);
expect
(
s
.
addConstraint
((
mid
*
cm
(
2.0
)
==
left
+
right
)
as
Constraint
),
expect
(
s
.
addConstraint
((
mid
*
cm
(
2.0
)
).
equals
(
left
+
right
)
),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
cm
(
10.0
)),
Result
.
success
);
...
...
@@ -590,7 +590,7 @@ void main() {
Param
left
=
new
Param
();
Param
right
=
new
Param
();
expect
(
(
left
==
right
).
runtimeType
,
Constraint
);
expect
(
left
.
equals
(
right
).
runtimeType
,
Constraint
);
});
test
(
'bulk_add_edit_variables'
,
()
{
...
...
packages/flutter/lib/src/rendering/auto_layout.dart
View file @
7a2c38ab
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/widgets/auto_layout.dart
View file @
7a2c38ab
...
...
@@ -7,7 +7,7 @@ import 'package:flutter/rendering.dart';
import
'framework.dart'
;
export
'package:flutter/rendering.dart'
show
AutoLayout
Params
,
AutoLayout
Rect
,
AutoLayoutDelegate
;
class
AutoLayout
extends
MultiChildRenderObjectWidget
{
...
...
@@ -27,16 +27,16 @@ class AutoLayout extends MultiChildRenderObjectWidget {
}
class
AutoLayoutChild
extends
ParentDataWidget
<
AutoLayout
>
{
AutoLayoutChild
({
Key
key
,
this
.
params
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
AutoLayoutChild
({
AutoLayoutRect
rect
,
Widget
child
})
:
rect
=
rect
,
super
(
key:
new
ObjectKey
(
rect
)
,
child:
child
);
final
AutoLayout
Params
params
;
final
AutoLayout
Rect
rect
;
void
applyParentData
(
RenderObject
renderObject
)
{
assert
(
renderObject
.
parentData
is
AutoLayoutParentData
);
final
AutoLayoutParentData
parentData
=
renderObject
.
parentData
;
// AutoLayoutParentData filters out redundant writes and marks needs layout
// as appropriate.
parentData
.
params
=
params
;
parentData
.
rect
=
rect
;
}
}
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