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
6e14bd2e
Commit
6e14bd2e
authored
Feb 15, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1896 from abarth/autolayout2
Add support for autolayout to widgets
parents
a85e7709
262dd7a6
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
319 additions
and
157 deletions
+319
-157
autolayout.dart
examples/layers/rendering/autolayout.dart
+53
-32
autolayout.dart
examples/layers/widgets/autolayout.dart
+87
-0
auto_layout.dart
packages/flutter/lib/src/rendering/auto_layout.dart
+136
-125
auto_layout.dart
packages/flutter/lib/src/widgets/auto_layout.dart
+42
-0
widgets.dart
packages/flutter/lib/widgets.dart
+1
-0
No files found.
examples/layers/rendering/autolayout.dart
View file @
6e14bd2e
// Copyright 201
5
The Chromium Authors. All rights reserved.
// Copyright 201
6
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
...
...
@@ -8,6 +8,45 @@
import
'package:cassowary/cassowary.dart'
as
al
;
import
'package:flutter/rendering.dart'
;
class
_MyAutoLayoutDelegate
extends
AutoLayoutDelegate
{
AutoLayoutParams
p1
=
new
AutoLayoutParams
();
AutoLayoutParams
p2
=
new
AutoLayoutParams
();
AutoLayoutParams
p3
=
new
AutoLayoutParams
();
AutoLayoutParams
p4
=
new
AutoLayoutParams
();
List
<
al
.
Constraint
>
getConstraints
(
AutoLayoutParams
parentParams
)
{
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
,
// The boxes must be stacked left to right
p1
.
rightEdge
<=
p2
.
leftEdge
,
p2
.
rightEdge
<=
p3
.
leftEdge
,
// The widths of the first and the third boxes should be equal
(
p1
.
width
==
p3
.
width
)
as
al
.
Constraint
,
// 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
,
// 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
,
// 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
,
];
}
bool
shouldUpdateConstraints
(
AutoLayoutDelegate
oldDelegate
)
=>
true
;
}
void
main
(
)
{
RenderDecoratedBox
c1
=
new
RenderDecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
))
...
...
@@ -25,40 +64,22 @@ void main() {
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFFFFFF
))
);
RenderAutoLayout
root
=
new
RenderAutoLayout
(
children:
<
RenderBox
>[
c1
,
c2
,
c3
,
c4
]);
AutoLayoutParentData
p1
=
c1
.
parentData
;
AutoLayoutParentData
p2
=
c2
.
parentData
;
AutoLayoutParentData
p3
=
c3
.
parentData
;
AutoLayoutParentData
p4
=
c4
.
parentData
;
root
.
addConstraints
(<
al
.
Constraint
>[
// Sum of widths of each box must be equal to that of the container
(
p1
.
width
+
p2
.
width
+
p3
.
width
==
root
.
width
)
as
al
.
Constraint
,
_MyAutoLayoutDelegate
delegate
=
new
_MyAutoLayoutDelegate
();
// The boxes must be stacked left to right
p1
.
rightEdge
<=
p2
.
leftEdge
,
p2
.
rightEdge
<=
p3
.
leftEdge
,
// The widths of the first and the third boxes should be equal
(
p1
.
width
==
p3
.
width
)
as
al
.
Constraint
,
// 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
,
RenderAutoLayout
root
=
new
RenderAutoLayout
(
delegate:
delegate
,
children:
<
RenderBox
>[
c1
,
c2
,
c3
,
c4
]
);
// 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
==
root
.
height
)
as
al
.
Constraint
,
AutoLayoutParentData
parentData1
=
c1
.
parentData
;
AutoLayoutParentData
parentData2
=
c2
.
parentData
;
AutoLayoutParentData
parentData3
=
c3
.
parentData
;
AutoLayoutParentData
parentData4
=
c4
.
parentData
;
// 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
,
]);
parentData1
.
params
=
delegate
.
p1
;
parentData2
.
params
=
delegate
.
p2
;
parentData3
.
params
=
delegate
.
p3
;
parentData4
.
params
=
delegate
.
p4
;
new
RenderingFlutterBinding
(
root:
root
);
}
examples/layers/widgets/autolayout.dart
0 → 100644
View file @
6e14bd2e
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This example shows how to use the Cassowary autolayout system with widgets.
import
'package:cassowary/cassowary.dart'
as
al
;
import
'package:flutter/widgets.dart'
;
class
_MyAutoLayoutDelegate
extends
AutoLayoutDelegate
{
AutoLayoutParams
p1
=
new
AutoLayoutParams
();
AutoLayoutParams
p2
=
new
AutoLayoutParams
();
AutoLayoutParams
p3
=
new
AutoLayoutParams
();
AutoLayoutParams
p4
=
new
AutoLayoutParams
();
List
<
al
.
Constraint
>
getConstraints
(
AutoLayoutParams
parentParams
)
{
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
,
// The boxes must be stacked left to right
p1
.
rightEdge
<=
p2
.
leftEdge
,
p2
.
rightEdge
<=
p3
.
leftEdge
,
// The widths of the first and the third boxes should be equal
(
p1
.
width
==
p3
.
width
)
as
al
.
Constraint
,
// 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
,
// 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
,
// 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
,
];
}
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
)
)
);
}
}
class
ColoredBoxes
extends
StatefulComponent
{
_ColoredBoxesState
createState
()
=>
new
_ColoredBoxesState
();
}
class
_ColoredBoxesState
extends
State
<
ColoredBoxes
>
{
final
_MyAutoLayoutDelegate
delegate
=
new
_MyAutoLayoutDelegate
();
Widget
build
(
BuildContext
context
)
{
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
)),
]
);
}
}
void
main
(
)
{
runApp
(
new
ColoredBoxes
());
}
packages/flutter/lib/src/rendering/auto_layout.dart
View file @
6e14bd2e
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/widgets/auto_layout.dart
0 → 100644
View file @
6e14bd2e
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/rendering.dart'
;
import
'framework.dart'
;
export
'package:flutter/rendering.dart'
show
AutoLayoutParams
,
AutoLayoutDelegate
;
class
AutoLayout
extends
MultiChildRenderObjectWidget
{
AutoLayout
({
Key
key
,
this
.
delegate
,
List
<
Widget
>
children:
const
<
Widget
>[]
})
:
super
(
key:
key
,
children:
children
);
final
AutoLayoutDelegate
delegate
;
RenderAutoLayout
createRenderObject
()
=>
new
RenderAutoLayout
(
delegate:
delegate
);
void
updateRenderObject
(
RenderAutoLayout
renderObject
,
AutoLayout
oldWidget
)
{
renderObject
.
delegate
=
delegate
;
}
}
class
AutoLayoutChild
extends
ParentDataWidget
<
AutoLayout
>
{
AutoLayoutChild
({
Key
key
,
this
.
params
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
final
AutoLayoutParams
params
;
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
;
}
}
packages/flutter/lib/widgets.dart
View file @
6e14bd2e
...
...
@@ -6,6 +6,7 @@
library
widgets
;
export
'src/widgets/asset_vendor.dart'
;
export
'src/widgets/auto_layout.dart'
;
export
'src/widgets/basic.dart'
;
export
'src/widgets/binding.dart'
;
export
'src/widgets/checked_mode_banner.dart'
;
...
...
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