Merge pull request #1745 from HansMuller/stack_alignment
Use FractionalOffset alignment value in Stack and IndexedStack
This commit is contained in:
commit
7ea42642f1
@ -241,7 +241,7 @@ class DropdownButton<T> extends StatelessComponent {
|
|||||||
new IndexedStack(items,
|
new IndexedStack(items,
|
||||||
key: indexedStackKey,
|
key: indexedStackKey,
|
||||||
index: selectedIndex,
|
index: selectedIndex,
|
||||||
horizontalAlignment: 0.5
|
alignment: const FractionalOffset(0.5, 0.0)
|
||||||
),
|
),
|
||||||
new Container(
|
new Container(
|
||||||
child: new Icon(type: 'navigation/arrow_drop_down', size: 36),
|
child: new Icon(type: 'navigation/arrow_drop_down', size: 36),
|
||||||
|
@ -186,9 +186,8 @@ abstract class RenderStackBase extends RenderBox
|
|||||||
RenderBoxContainerDefaultsMixin<RenderBox, StackParentData> {
|
RenderBoxContainerDefaultsMixin<RenderBox, StackParentData> {
|
||||||
RenderStackBase({
|
RenderStackBase({
|
||||||
List<RenderBox> children,
|
List<RenderBox> children,
|
||||||
double horizontalAlignment: 0.0,
|
alignment: const FractionalOffset(0.0, 0.0)
|
||||||
double verticalAlignment: 0.0
|
}) : _alignment = alignment {
|
||||||
}) : _horizontalAlignment = horizontalAlignment, _verticalAlignment = verticalAlignment {
|
|
||||||
addAll(children);
|
addAll(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,20 +198,11 @@ abstract class RenderStackBase extends RenderBox
|
|||||||
child.parentData = new StackParentData();
|
child.parentData = new StackParentData();
|
||||||
}
|
}
|
||||||
|
|
||||||
double get horizontalAlignment => _horizontalAlignment;
|
FractionalOffset get alignment => _alignment;
|
||||||
double _horizontalAlignment;
|
FractionalOffset _alignment;
|
||||||
void set horizontalAlignment (double value) {
|
void set alignment (FractionalOffset value) {
|
||||||
if (_horizontalAlignment != value) {
|
if (_alignment != value) {
|
||||||
_horizontalAlignment = value;
|
_alignment = value;
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double get verticalAlignment => _verticalAlignment;
|
|
||||||
double _verticalAlignment;
|
|
||||||
void set verticalAlignment (double value) {
|
|
||||||
if (_verticalAlignment != value) {
|
|
||||||
_verticalAlignment = value;
|
|
||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,8 +317,8 @@ abstract class RenderStackBase extends RenderBox
|
|||||||
final StackParentData childParentData = child.parentData;
|
final StackParentData childParentData = child.parentData;
|
||||||
|
|
||||||
if (!childParentData.isPositioned) {
|
if (!childParentData.isPositioned) {
|
||||||
double x = (size.width - child.size.width) * horizontalAlignment;
|
double x = (size.width - child.size.width) * alignment.x;
|
||||||
double y = (size.height - child.size.height) * verticalAlignment;
|
double y = (size.height - child.size.height) * alignment.y;
|
||||||
childParentData.position = new Point(x, y);
|
childParentData.position = new Point(x, y);
|
||||||
} else {
|
} else {
|
||||||
BoxConstraints childConstraints = const BoxConstraints();
|
BoxConstraints childConstraints = const BoxConstraints();
|
||||||
@ -395,12 +385,12 @@ abstract class RenderStackBase extends RenderBox
|
|||||||
/// are no non-positioned children, the stack becomes as large as possible.
|
/// are no non-positioned children, the stack becomes as large as possible.
|
||||||
///
|
///
|
||||||
/// The final location of non-positioned children is determined by the alignment
|
/// The final location of non-positioned children is determined by the alignment
|
||||||
/// parameters. The left of each non-positioned child becomes the
|
/// parameter. The left of each non-positioned child becomes the
|
||||||
/// difference between the child's width and the stack's width scaled by
|
/// difference between the child's width and the stack's width scaled by
|
||||||
/// horizontalAlignment. The top of each non-positioned child is computed
|
/// alignment.x. The top of each non-positioned child is computed
|
||||||
/// similarly and scaled by verticalAlignement. So if the alignment parameters
|
/// similarly and scaled by alignement.y. So if the alignment x and y properties
|
||||||
/// are 0.0 (the default) then the non-positioned children remain in the
|
/// are 0.0 (the default) then the non-positioned children remain in the
|
||||||
/// upper-left corner. If the alignment parameters are 0.5 then the
|
/// upper-left corner. If the alignment x and y properties are 0.5 then the
|
||||||
/// non-positioned children are centered within the stack.
|
/// non-positioned children are centered within the stack.
|
||||||
///
|
///
|
||||||
/// Next, the positioned children are laid out. If a child has top and bottom
|
/// Next, the positioned children are laid out. If a child has top and bottom
|
||||||
@ -418,12 +408,10 @@ abstract class RenderStackBase extends RenderBox
|
|||||||
class RenderStack extends RenderStackBase {
|
class RenderStack extends RenderStackBase {
|
||||||
RenderStack({
|
RenderStack({
|
||||||
List<RenderBox> children,
|
List<RenderBox> children,
|
||||||
double horizontalAlignment: 0.0,
|
alignment: const FractionalOffset(0.0, 0.0)
|
||||||
double verticalAlignment: 0.0
|
|
||||||
}) : super(
|
}) : super(
|
||||||
children: children,
|
children: children,
|
||||||
horizontalAlignment: horizontalAlignment,
|
alignment: alignment
|
||||||
verticalAlignment: verticalAlignment
|
|
||||||
);
|
);
|
||||||
|
|
||||||
void paintStack(PaintingContext context, Offset offset) {
|
void paintStack(PaintingContext context, Offset offset) {
|
||||||
@ -438,13 +426,11 @@ class RenderStack extends RenderStackBase {
|
|||||||
class RenderIndexedStack extends RenderStackBase {
|
class RenderIndexedStack extends RenderStackBase {
|
||||||
RenderIndexedStack({
|
RenderIndexedStack({
|
||||||
List<RenderBox> children,
|
List<RenderBox> children,
|
||||||
double horizontalAlignment: 0.0,
|
alignment: const FractionalOffset(0.0, 0.0),
|
||||||
double verticalAlignment: 0.0,
|
|
||||||
int index: 0
|
int index: 0
|
||||||
}) : _index = index, super(
|
}) : _index = index, super(
|
||||||
children: children,
|
children: children,
|
||||||
horizontalAlignment: horizontalAlignment,
|
alignment: alignment
|
||||||
verticalAlignment: verticalAlignment
|
|
||||||
);
|
);
|
||||||
|
|
||||||
int get index => _index;
|
int get index => _index;
|
||||||
|
@ -592,54 +592,34 @@ class BlockBody extends MultiChildRenderObjectWidget {
|
|||||||
class Stack extends MultiChildRenderObjectWidget {
|
class Stack extends MultiChildRenderObjectWidget {
|
||||||
Stack(List<Widget> children, {
|
Stack(List<Widget> children, {
|
||||||
Key key,
|
Key key,
|
||||||
this.horizontalAlignment: 0.0,
|
this.alignment: const FractionalOffset(0.0, 0.0)
|
||||||
this.verticalAlignment: 0.0
|
}) : super(key: key, children: children);
|
||||||
}) : super(key: key, children: children) {
|
|
||||||
assert(horizontalAlignment != null);
|
|
||||||
assert(verticalAlignment != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final double horizontalAlignment;
|
final FractionalOffset alignment;
|
||||||
final double verticalAlignment;
|
|
||||||
|
|
||||||
RenderStack createRenderObject() {
|
RenderStack createRenderObject() => new RenderStack(alignment: alignment);
|
||||||
return new RenderStack(
|
|
||||||
horizontalAlignment: horizontalAlignment,
|
|
||||||
verticalAlignment: verticalAlignment
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateRenderObject(RenderStack renderObject, Stack oldWidget) {
|
void updateRenderObject(RenderStack renderObject, Stack oldWidget) {
|
||||||
renderObject.horizontalAlignment = horizontalAlignment;
|
renderObject.alignment = alignment;
|
||||||
renderObject.verticalAlignment = verticalAlignment;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IndexedStack extends MultiChildRenderObjectWidget {
|
class IndexedStack extends MultiChildRenderObjectWidget {
|
||||||
IndexedStack(List<Widget> children, {
|
IndexedStack(List<Widget> children, {
|
||||||
Key key,
|
Key key,
|
||||||
this.horizontalAlignment: 0.0,
|
this.alignment: const FractionalOffset(0.0, 0.0),
|
||||||
this.verticalAlignment: 0.0,
|
|
||||||
this.index: 0
|
this.index: 0
|
||||||
}) : super(key: key, children: children);
|
}) : super(key: key, children: children);
|
||||||
|
|
||||||
final int index;
|
final int index;
|
||||||
final double horizontalAlignment;
|
final FractionalOffset alignment;
|
||||||
final double verticalAlignment;
|
|
||||||
|
|
||||||
RenderIndexedStack createRenderObject() {
|
RenderIndexedStack createRenderObject() => new RenderIndexedStack(index: index, alignment: alignment);
|
||||||
return new RenderIndexedStack(
|
|
||||||
index: index,
|
|
||||||
verticalAlignment: verticalAlignment,
|
|
||||||
horizontalAlignment: horizontalAlignment
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateRenderObject(RenderIndexedStack renderObject, IndexedStack oldWidget) {
|
void updateRenderObject(RenderIndexedStack renderObject, IndexedStack oldWidget) {
|
||||||
super.updateRenderObject(renderObject, oldWidget);
|
super.updateRenderObject(renderObject, oldWidget);
|
||||||
renderObject.index = index;
|
renderObject.index = index;
|
||||||
renderObject.horizontalAlignment = horizontalAlignment;
|
renderObject.alignment = alignment;
|
||||||
renderObject.verticalAlignment = verticalAlignment;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +103,7 @@ void main() {
|
|||||||
new Container(key: child0Key, width: 20.0, height: 20.0),
|
new Container(key: child0Key, width: 20.0, height: 20.0),
|
||||||
new Container(key: child1Key, width: 10.0, height: 10.0)
|
new Container(key: child1Key, width: 10.0, height: 10.0)
|
||||||
],
|
],
|
||||||
horizontalAlignment: 0.5,
|
alignment: const FractionalOffset(0.5, 0.5)
|
||||||
verticalAlignment: 0.5
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user