85 lines
3.0 KiB
Dart
85 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 its own tabs, floating at its bottom, still fit).
|
|
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, {
|
|
double minimum = kListPaneMinWidth,
|
|
}) {
|
|
final bodyMinimum = math.max(
|
|
window * _bodyWindowMinimum,
|
|
kDetailPaneMinWidth,
|
|
);
|
|
final maximum = math.min(
|
|
available - 1 - bodyMinimum,
|
|
window * _listWindowMaximum,
|
|
);
|
|
if (maximum < minimum) return null;
|
|
return (min: minimum, 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),
|
|
);
|