Add the Windows menu, window cycling, edge snapping and size per kind
Phase 4 of docs/plans/floating-windows.md. A bar button lists the app's windows on every tab (show one, Show all, Minimise all, Close all). Alt+` and Alt+Shift+` bring the next or previous window to the front. Dropping a title at the left or right edge fills that half, at the top it maximises. A new window of a kind opens at the size that kind was last given.
This commit is contained in:
@@ -99,3 +99,36 @@ Rect drawnWindowFrame(WindowEntry entry, Size bounds, Size minSize) =>
|
||||
windowMaximizedMargin.clamp(0.0, bounds.shortestSide / 2),
|
||||
)
|
||||
: fitWindowFrame(entry.frame, bounds, minSize);
|
||||
|
||||
/// Where a dragged window snaps when its title is dropped at an edge.
|
||||
enum WindowSnap { left, right, maximize }
|
||||
|
||||
/// How close to an edge of the window area the pointer must be to snap.
|
||||
const double windowSnapDistance = 6;
|
||||
|
||||
/// The snap for a title dropped with the pointer at [pointer] inside
|
||||
/// [bounds], or null away from the edges.
|
||||
WindowSnap? windowSnapFor(Offset pointer, Size bounds) {
|
||||
if (pointer.dy <= windowSnapDistance) return WindowSnap.maximize;
|
||||
if (pointer.dx <= windowSnapDistance) return WindowSnap.left;
|
||||
if (pointer.dx >= bounds.width - windowSnapDistance) return WindowSnap.right;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The frame of a window snapped to a half of [bounds].
|
||||
Rect windowSnapRect(WindowSnap snap, Size bounds) {
|
||||
final area = (Offset.zero & bounds).deflate(
|
||||
windowMaximizedMargin.clamp(0.0, bounds.shortestSide / 2),
|
||||
);
|
||||
final half = (area.width - windowMaximizedMargin) / 2;
|
||||
return switch (snap) {
|
||||
WindowSnap.left => Rect.fromLTWH(area.left, area.top, half, area.height),
|
||||
WindowSnap.right => Rect.fromLTWH(
|
||||
area.right - half,
|
||||
area.top,
|
||||
half,
|
||||
area.height,
|
||||
),
|
||||
WindowSnap.maximize => area,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user