Files
pipelines/app/lib/shell/list_detail_policy.dart
T
alan c0d68f7c47 Split view: drag the divider to resize the list pane, remembered per destination
A 12 px grab area over the divider line resizes the list live (mouse,
touch, arrow keys; double tap resets to the default policy). The shell bar
over the list follows. Widths persist per destination in SharedPreferences
and clamp to the window without overwriting the saved value. Capture kit
gains hover= and drag= steps.
2026-11-03 10:49:09 +00:00

84 lines
3.0 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/widgets.dart';
/// At least this wide, a destination keeps its list beside the open item
/// (with the destination rail) instead of pushing the item as its own page.
const double kListDetailMinWidth = 600;
const double _bodyWindowTarget = 0.6;
const double _bodyWindowMinimum = 0.5;
const double _bodyAvailableMaximum = 0.75;
/// The widest the list pane grows beside an open item: on a very wide window
/// (a 4K monitor) the extra width goes to the open item, not the list.
const double kListPaneMaxWidth = 440;
/// Whether the window at [context] shows list and detail side by side.
bool showsListBesideDetail(BuildContext context) =>
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
/// The narrowest list pane a drag leaves.
const double kListPaneMinWidth = 240;
/// The narrowest open item a drag leaves, beside the share of the window it
/// always keeps (so the shell's tab bar, floating over it, still fits).
const double kDetailPaneMinWidth = 320;
const double _listWindowMaximum = 0.6;
/// How far a drag may resize the list pane for a [window] this wide and
/// [available] width for both panes and their divider; null when the window
/// is too small for any width but the default policy's.
({double min, double max})? listPaneWidthBounds(
double window,
double available,
) {
final bodyMinimum = math.max(
window * _bodyWindowMinimum,
kDetailPaneMinWidth,
);
final maximum = math.min(
available - 1 - bodyMinimum,
window * _listWindowMaximum,
);
if (maximum < kListPaneMinWidth) return null;
return (min: kListPaneMinWidth, max: maximum);
}
/// The open item's width beside a list, for a [window] this wide and
/// [available] width for both panes and their divider. A [preferred] list
/// width (the operator's drag) replaces the default policy, clamped to
/// [listPaneWidthBounds].
double listDetailBodyWidth(
double window,
double available, [
double? preferred,
]) {
if (preferred != null) {
final bounds = listPaneWidthBounds(window, available);
if (bounds != null) {
return available - 1 - preferred.clamp(bounds.min, bounds.max);
}
}
// Target 60% of the full window. Keep at least half for the body while
// leaving a flexible share for native list controls on tighter windows.
final requestedMinimum = window * _bodyWindowMinimum;
final minimum = available > requestedMinimum
? requestedMinimum
: available * _bodyWindowMinimum;
final maximum = math.max(minimum, available * _bodyAvailableMaximum);
final body = (window * _bodyWindowTarget).clamp(minimum, maximum);
// Past the list's cap, the open item takes the rest.
return math.max(body, available - 1 - kListPaneMaxWidth);
}
/// The list pane's width beside an open item (see [listDetailBodyWidth]),
/// one divider excluded.
double listDetailListWidth(
double window,
double available, [
double? preferred,
]) => math.max(
0,
available - 1 - listDetailBodyWidth(window, available, preferred),
);