Open a choice menu over its anchor when the anchor is a whole pane
The add-pane picker is opened from a pane, not a button; with no room above or below the anchor the panel was laid out with no height (found by run 303's UI review).
This commit is contained in:
@@ -20,6 +20,8 @@ bool usesDesktopPopups(BuildContext context) {
|
||||
///
|
||||
/// On a wide app it is a menu panel anchored to [anchor] (the button that
|
||||
/// opened it): below it, or above when there is no room, kept inside the app.
|
||||
/// When [anchor] is a region rather than a button (a pane), the panel opens
|
||||
/// over its top left.
|
||||
/// On a phone it is a bottom sheet. Either way it is on the root navigator,
|
||||
/// so it is above every floating window. Escape, Back or a press outside
|
||||
/// closes it; the content closes it with `Navigator.of(context).pop(value)`.
|
||||
@@ -169,38 +171,59 @@ class _AnchoredMenuLayout extends SingleChildLayoutDelegate {
|
||||
static const double margin = 8;
|
||||
static const double gap = 4;
|
||||
|
||||
/// Less room than this on both sides means the anchor is not a button but
|
||||
/// a region (a pane's bar, a whole pane): the panel then opens over it,
|
||||
/// from its top.
|
||||
static const double minRoom = 200;
|
||||
|
||||
double _below(Size size) => size.height - anchor.bottom - gap - margin;
|
||||
double _above() => anchor.top - gap - margin;
|
||||
bool _over(Size size) => _below(size) < minRoom && _above() < minRoom;
|
||||
|
||||
@override
|
||||
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
|
||||
final available = constraints.biggest;
|
||||
final below = available.height - anchor.bottom - gap - margin;
|
||||
final above = anchor.top - gap - margin;
|
||||
final height = (below >= 240 || below >= above ? below : above).clamp(
|
||||
0.0,
|
||||
available.height - 2 * margin,
|
||||
);
|
||||
final below = _below(available);
|
||||
final above = _above();
|
||||
final double room;
|
||||
if (_over(available)) {
|
||||
room =
|
||||
available.height -
|
||||
anchor.top.clamp(margin, available.height) -
|
||||
margin;
|
||||
} else {
|
||||
room = below >= minRoom || below >= above ? below : above;
|
||||
}
|
||||
final maxWidth = (available.width - 2 * margin).clamp(0.0, double.infinity);
|
||||
return BoxConstraints(
|
||||
minWidth: width.clamp(0.0, maxWidth),
|
||||
maxWidth: width.clamp(0.0, maxWidth),
|
||||
maxHeight: height,
|
||||
maxHeight: room.clamp(0.0, available.height - 2 * margin),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Offset getPositionForChild(Size size, Size childSize) {
|
||||
final below = size.height - anchor.bottom - gap - margin;
|
||||
final fitsBelow = childSize.height <= below;
|
||||
final top = fitsBelow
|
||||
? anchor.bottom + gap
|
||||
: (anchor.top - gap - childSize.height).clamp(
|
||||
margin,
|
||||
size.height - margin - childSize.height,
|
||||
);
|
||||
final left = anchor.left.clamp(
|
||||
final double top;
|
||||
if (_over(size)) {
|
||||
top = anchor.top + gap;
|
||||
} else if (childSize.height <= _below(size)) {
|
||||
top = anchor.bottom + gap;
|
||||
} else {
|
||||
top = anchor.top - gap - childSize.height;
|
||||
}
|
||||
final maxTop = (size.height - margin - childSize.height).clamp(
|
||||
margin,
|
||||
(size.width - margin - childSize.width).clamp(margin, double.infinity),
|
||||
double.infinity,
|
||||
);
|
||||
final maxLeft = (size.width - margin - childSize.width).clamp(
|
||||
margin,
|
||||
double.infinity,
|
||||
);
|
||||
return Offset(
|
||||
anchor.left.clamp(margin, maxLeft),
|
||||
top.clamp(margin, maxTop),
|
||||
);
|
||||
return Offset(left, top);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user