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
4408c820
Commit
4408c820
authored
Feb 15, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename AutoLayoutParams to AutoLayoutRect
This object represents a rect the auto-layout system.
parent
c7d71d8a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
61 deletions
+62
-61
autolayout.dart
examples/layers/rendering/autolayout.dart
+9
-9
autolayout.dart
examples/layers/widgets/autolayout.dart
+9
-9
cassowary_test.dart
packages/cassowary/test/cassowary_test.dart
+11
-11
auto_layout.dart
packages/flutter/lib/src/rendering/auto_layout.dart
+28
-27
auto_layout.dart
packages/flutter/lib/src/widgets/auto_layout.dart
+5
-5
No files found.
examples/layers/rendering/autolayout.dart
View file @
4408c820
...
...
@@ -9,12 +9,12 @@ 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
parent
)
{
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Rect
parent
)
{
return
<
al
.
Constraint
>[
// Sum of widths of each box must be equal to that of the container
parent
.
width
.
equals
(
p1
.
width
+
p2
.
width
+
p3
.
width
),
...
...
@@ -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 @
4408c820
...
...
@@ -8,12 +8,12 @@ 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
parent
)
{
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Rect
parent
)
{
return
<
al
.
Constraint
>[
// Sum of widths of each box must be equal to that of the container
parent
.
width
.
equals
(
p1
.
width
+
p2
.
width
+
p3
.
width
),
...
...
@@ -58,25 +58,25 @@ class _ColoredBoxesState extends State<ColoredBoxes> {
delegate:
delegate
,
children:
<
Widget
>[
new
AutoLayoutChild
(
params
:
delegate
.
p1
,
rect
:
delegate
.
p1
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
))
)
),
new
AutoLayoutChild
(
params
:
delegate
.
p2
,
rect
:
delegate
.
p2
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
))
)
),
new
AutoLayoutChild
(
params
:
delegate
.
p3
,
rect
:
delegate
.
p3
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF0000FF
))
)
),
new
AutoLayoutChild
(
params
:
delegate
.
p4
,
rect
:
delegate
.
p4
,
child:
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFFFFFF
))
)
...
...
packages/cassowary/test/cassowary_test.dart
View file @
4408c820
...
...
@@ -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 @
4408c820
...
...
@@ -10,8 +10,8 @@ import 'object.dart';
/// Hosts the edge parameters and vends useful methods to construct expressions
/// for constraints. Also sets up and manages implicit constraints and edit
/// variables.
class
AutoLayout
Params
{
AutoLayout
Params
()
{
class
AutoLayout
Rect
{
AutoLayout
Rect
()
{
_left
=
new
al
.
Param
();
_right
=
new
al
.
Param
();
_top
=
new
al
.
Param
();
...
...
@@ -34,7 +34,7 @@ class AutoLayoutParams {
al
.
Expression
get
horizontalCenter
=>
(
_left
+
_right
)
/
al
.
cm
(
2.0
);
al
.
Expression
get
verticalCenter
=>
(
_top
+
_bottom
)
/
al
.
cm
(
2.0
);
List
<
al
.
Constraint
>
contains
(
AutoLayout
Params
other
)
{
List
<
al
.
Constraint
>
contains
(
AutoLayout
Rect
other
)
{
return
<
al
.
Constraint
>[
other
.
left
>=
left
,
other
.
right
<=
right
,
...
...
@@ -49,34 +49,34 @@ class AutoLayoutParentData extends ContainerBoxParentDataMixin<RenderBox> {
final
RenderBox
_renderBox
;
AutoLayout
Params
get
params
=>
_params
;
AutoLayout
Params
_params
;
void
set
params
(
AutoLayoutParams
value
)
{
if
(
_
params
==
value
)
AutoLayout
Rect
get
rect
=>
_rect
;
AutoLayout
Rect
_rect
;
void
set
rect
(
AutoLayoutRect
value
)
{
if
(
_
rect
==
value
)
return
;
if
(
_
params
!=
null
)
if
(
_
rect
!=
null
)
_removeImplicitConstraints
();
_
params
=
value
;
if
(
_
params
!=
null
)
_
rect
=
value
;
if
(
_
rect
!=
null
)
_addImplicitConstraints
();
}
BoxConstraints
get
_constraintsFromSolver
{
return
new
BoxConstraints
.
tightFor
(
width:
_
params
.
_right
.
value
-
_params
.
_left
.
value
,
height:
_
params
.
_bottom
.
value
-
_params
.
_top
.
value
width:
_
rect
.
_right
.
value
-
_rect
.
_left
.
value
,
height:
_
rect
.
_bottom
.
value
-
_rect
.
_top
.
value
);
}
Offset
get
_offsetFromSolver
{
return
new
Offset
(
_
params
.
_left
.
value
,
_params
.
_top
.
value
);
return
new
Offset
(
_
rect
.
_left
.
value
,
_rect
.
_top
.
value
);
}
List
<
al
.
Constraint
>
_implicitConstraints
;
void
_addImplicitConstraints
()
{
assert
(
_renderBox
!=
null
);
if
(
_renderBox
.
parent
==
null
||
_
params
==
null
)
if
(
_renderBox
.
parent
==
null
||
_
rect
==
null
)
return
;
final
List
<
al
.
Constraint
>
implicit
=
_constructImplicitConstraints
();
assert
(
implicit
!=
null
&&
implicit
.
isNotEmpty
);
...
...
@@ -106,8 +106,9 @@ class AutoLayoutParentData extends ContainerBoxParentDataMixin<RenderBox> {
/// may return null.
List
<
al
.
Constraint
>
_constructImplicitConstraints
()
{
return
<
al
.
Constraint
>[
_params
.
_left
>=
al
.
cm
(
0.0
),
// The left edge must be positive.
_params
.
_right
>=
_params
.
_left
,
// Width must be positive.
_rect
.
_left
>=
al
.
cm
(
0.0
),
// The left edge must be positive.
_rect
.
_right
>=
_rect
.
_left
,
// Width must be positive.
// Why don't we need something similar for the top and the bottom?
];
}
}
...
...
@@ -115,7 +116,7 @@ class AutoLayoutParentData extends ContainerBoxParentDataMixin<RenderBox> {
abstract
class
AutoLayoutDelegate
{
const
AutoLayoutDelegate
();
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Params
parent
);
List
<
al
.
Constraint
>
getConstraints
(
AutoLayout
Rect
parent
);
bool
shouldUpdateConstraints
(
AutoLayoutDelegate
oldDelegate
);
}
...
...
@@ -128,10 +129,10 @@ class RenderAutoLayout extends RenderBox
List
<
RenderBox
>
children
})
:
_delegate
=
delegate
,
_needToUpdateConstraints
=
(
delegate
!=
null
)
{
_solver
.
addEditVariables
(<
al
.
Variable
>[
_
params
.
_left
.
variable
,
_
params
.
_right
.
variable
,
_
params
.
_top
.
variable
,
_
params
.
_bottom
.
variable
_
rect
.
_left
.
variable
,
_
rect
.
_right
.
variable
,
_
rect
.
_top
.
variable
,
_
rect
.
_bottom
.
variable
],
al
.
Priority
.
required
-
1
);
addAll
(
children
);
...
...
@@ -158,7 +159,7 @@ class RenderAutoLayout extends RenderBox
bool
_needToUpdateConstraints
;
final
AutoLayout
Params
_params
=
new
AutoLayoutParams
();
final
AutoLayout
Rect
_rect
=
new
AutoLayoutRect
();
final
al
.
Solver
_solver
=
new
al
.
Solver
();
final
List
<
al
.
Constraint
>
_explicitConstraints
=
new
List
<
al
.
Constraint
>();
...
...
@@ -212,17 +213,17 @@ class RenderAutoLayout extends RenderBox
if
(
_needToUpdateConstraints
)
{
_clearExplicitConstraints
();
if
(
_delegate
!=
null
)
_setExplicitConstraints
(
_delegate
.
getConstraints
(
_
params
));
_setExplicitConstraints
(
_delegate
.
getConstraints
(
_
rect
));
_needToUpdateConstraints
=
false
;
needToFlushUpdates
=
true
;
}
if
(
size
!=
_previousSize
)
{
_solver
..
suggestValueForVariable
(
_
params
.
_left
.
variable
,
0.0
)
..
suggestValueForVariable
(
_
params
.
_top
.
variable
,
0.0
)
..
suggestValueForVariable
(
_
params
.
_bottom
.
variable
,
size
.
height
)
..
suggestValueForVariable
(
_
params
.
_right
.
variable
,
size
.
width
);
..
suggestValueForVariable
(
_
rect
.
_left
.
variable
,
0.0
)
..
suggestValueForVariable
(
_
rect
.
_top
.
variable
,
0.0
)
..
suggestValueForVariable
(
_
rect
.
_bottom
.
variable
,
size
.
height
)
..
suggestValueForVariable
(
_
rect
.
_right
.
variable
,
size
.
width
);
_previousSize
=
size
;
needToFlushUpdates
=
true
;
}
...
...
packages/flutter/lib/src/widgets/auto_layout.dart
View file @
4408c820
...
...
@@ -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
({
AutoLayout
Params
params
,
Widget
child
})
:
params
=
params
,
super
(
key:
new
ObjectKey
(
params
),
child:
child
);
AutoLayoutChild
({
AutoLayout
Rect
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