Merge: draggable list/detail divider, remembered per tab
This commit is contained in:
@@ -9,6 +9,7 @@ import '../ui/adaptive/floating_destination_bar.dart';
|
||||
import 'attention_badge.dart';
|
||||
import 'destination.dart';
|
||||
import 'list_detail.dart';
|
||||
import 'list_pane_widths.dart';
|
||||
import 'shell_bar.dart';
|
||||
|
||||
class AdaptiveShell extends StatefulWidget {
|
||||
@@ -20,8 +21,12 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.onDestinationSelected,
|
||||
this.onSearch,
|
||||
this.attentionCount = 0,
|
||||
this.listPaneWidthStore = const SharedPreferencesListPaneWidthStore(),
|
||||
});
|
||||
|
||||
/// Where each destination's dragged list-pane width is kept on this device.
|
||||
final ListPaneWidthStore listPaneWidthStore;
|
||||
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
final bool cupertino;
|
||||
|
||||
@@ -46,6 +51,9 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
late AppDestination _selected;
|
||||
final Set<AppDestination> _visited = {};
|
||||
final ShellBarRegistry _bar = ShellBarRegistry();
|
||||
late final ListPaneWidths _paneWidths = ListPaneWidths(
|
||||
store: widget.listPaneWidthStore,
|
||||
);
|
||||
// Keeps every destination's state if the stack's parent ever changes.
|
||||
final GlobalKey _destinationStackKey = GlobalKey();
|
||||
|
||||
@@ -53,6 +61,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_handleDestinationKeyEvent);
|
||||
_bar.dispose();
|
||||
_paneWidths.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -168,9 +177,10 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
SegmentedBar currentBar() =>
|
||||
_segmentedBar(_bar.specFor(_selected), details.label, page: page);
|
||||
final topBar = _ListPaneBar(
|
||||
listenable: _bar.bar,
|
||||
listenable: Listenable.merge([_bar.bar, _paneWidths]),
|
||||
initial: currentBar(),
|
||||
split: () => _bar.split(_selected),
|
||||
preferredWidth: () => _paneWidths.widthFor(_selected.name),
|
||||
bar: currentBar,
|
||||
);
|
||||
// The scaffolds below swap the system insets for their bars'
|
||||
@@ -313,10 +323,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _destinationStack(List<Widget> contents) => FadeThroughStack(
|
||||
key: _destinationStackKey,
|
||||
index: AppDestination.values.indexOf(_selected),
|
||||
children: contents,
|
||||
Widget _destinationStack(List<Widget> contents) => ListPaneWidthsScope(
|
||||
widths: _paneWidths,
|
||||
child: FadeThroughStack(
|
||||
key: _destinationStackKey,
|
||||
index: AppDestination.values.indexOf(_selected),
|
||||
children: contents,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -334,12 +347,14 @@ class _ListPaneBar extends StatelessWidget
|
||||
required this.listenable,
|
||||
required this.initial,
|
||||
required this.split,
|
||||
required this.preferredWidth,
|
||||
required this.bar,
|
||||
});
|
||||
|
||||
final Listenable listenable;
|
||||
final SegmentedBar initial;
|
||||
final bool Function() split;
|
||||
final double? Function() preferredWidth;
|
||||
final SegmentedBar Function() bar;
|
||||
|
||||
@override
|
||||
@@ -354,6 +369,7 @@ class _ListPaneBar extends StatelessWidget
|
||||
listenable: listenable,
|
||||
builder: (context, _) => ListPaneWidth(
|
||||
split: split(),
|
||||
preferredWidth: preferredWidth(),
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: bar(),
|
||||
),
|
||||
|
||||
+120
-109
@@ -1,47 +1,15 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../ui/adaptive/floating_bar_layout.dart';
|
||||
import '../ui/adaptive/host.dart';
|
||||
import 'detail_pane_navigator.dart';
|
||||
import 'list_detail_policy.dart';
|
||||
import 'list_pane_divider.dart';
|
||||
import 'list_pane_widths.dart';
|
||||
import 'shell_bar.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 open item's width beside a list, for a [window] this wide and
|
||||
/// [available] width for both panes and their divider.
|
||||
double listDetailBodyWidth(double window, double available) {
|
||||
// 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) =>
|
||||
math.max(0, available - 1 - listDetailBodyWidth(window, available));
|
||||
export 'list_detail_policy.dart';
|
||||
|
||||
/// The system's own insets (status bar, navigation bar) as the shell saw
|
||||
/// them, before its scaffold replaced them with its bars' heights.
|
||||
@@ -79,10 +47,15 @@ class ListPaneWidth extends StatelessWidget {
|
||||
super.key,
|
||||
required this.split,
|
||||
required this.alignment,
|
||||
this.preferredWidth,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool split;
|
||||
|
||||
/// The list width the operator dragged the divider to, null for the
|
||||
/// default policy; see [listDetailListWidth].
|
||||
final double? preferredWidth;
|
||||
final AlignmentGeometry alignment;
|
||||
final Widget child;
|
||||
|
||||
@@ -93,6 +66,7 @@ class ListPaneWidth extends StatelessWidget {
|
||||
? listDetailListWidth(
|
||||
MediaQuery.sizeOf(context).width,
|
||||
constraints.maxWidth,
|
||||
preferredWidth,
|
||||
)
|
||||
: constraints.maxWidth;
|
||||
return Align(
|
||||
@@ -115,7 +89,7 @@ class ListPaneWidth extends StatelessWidget {
|
||||
/// [kStackedBarGap] as its bottom padding: its own tabs (or the chat
|
||||
/// composer) float above the shell's bar, never on it, and its content clears
|
||||
/// both. Pages the item opens stay in its pane ([DetailPaneNavigator]).
|
||||
class ListDetailPanes extends StatelessWidget {
|
||||
class ListDetailPanes extends StatefulWidget {
|
||||
const ListDetailPanes({
|
||||
super.key,
|
||||
required this.list,
|
||||
@@ -130,88 +104,125 @@ class ListDetailPanes extends StatelessWidget {
|
||||
/// previous one opened in its pane.
|
||||
final Object? detailIdentity;
|
||||
|
||||
@override
|
||||
State<ListDetailPanes> createState() => _ListDetailPanesState();
|
||||
}
|
||||
|
||||
class _ListDetailPanesState extends State<ListDetailPanes> {
|
||||
// Outside a shell (no [ListPaneWidthsScope]) the divider still drags; the
|
||||
// width lasts as long as the panes.
|
||||
ListPaneWidths? _ownWidths;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ownWidths?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final divider = usesCupertinoHost(context)
|
||||
? Container(
|
||||
width: 1,
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
)
|
||||
: const VerticalDivider(width: 1);
|
||||
final widths =
|
||||
ListPaneWidthsScope.maybeOf(context) ??
|
||||
(_ownWidths ??= ListPaneWidths(store: MemoryListPaneWidthStore()));
|
||||
final key = ShellBarScope.maybeOf(context)?.destination.name ?? 'panes';
|
||||
final media = MediaQuery.of(context);
|
||||
final split = ShellBar.available(context);
|
||||
return ShellPaneSplit(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final bodyWidth = listDetailBodyWidth(
|
||||
media.size.width,
|
||||
constraints.maxWidth,
|
||||
);
|
||||
Widget body = detail;
|
||||
Widget listPane = list;
|
||||
if (split) {
|
||||
// Beside the list the item is not under the shell's top bar (it
|
||||
// stays over the list pane): it keeps the system's own top inset,
|
||||
// so its bar sits just below the status bar at the top edge. The
|
||||
// shell's tab bar floats at the bottom right, over this pane; its
|
||||
// height (the shell's bottom padding here) plus a gap lifts the
|
||||
// item's tabs or composer above it.
|
||||
final system = ShellSystemInsets.of(context);
|
||||
body = MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(
|
||||
top: system.top,
|
||||
bottom: media.padding.bottom + kStackedBarGap,
|
||||
),
|
||||
),
|
||||
child: PageTabsEdge(
|
||||
edge: FloatingBarEdge.bottom,
|
||||
child: DetailPaneNavigator(
|
||||
identity: detailIdentity,
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
);
|
||||
// The tab bar sits over the detail pane, never the list (the
|
||||
// detail is at least half the window, wider than the bar), so
|
||||
// the list clears only the system's bottom inset.
|
||||
listPane = MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(bottom: system.bottom),
|
||||
),
|
||||
child: list,
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox.expand(
|
||||
key: const ValueKey('list-detail-list'),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
identifier: 'list-detail-list',
|
||||
child: listPane,
|
||||
child: ListenableBuilder(
|
||||
listenable: widths,
|
||||
builder: (context, _) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final window = media.size.width;
|
||||
final available = constraints.maxWidth;
|
||||
final preferred = widths.widthFor(key);
|
||||
final listWidth = listDetailListWidth(window, available, preferred);
|
||||
final bodyWidth = math.max(0.0, available - 1 - listWidth);
|
||||
final bounds = listPaneWidthBounds(window, available);
|
||||
Widget body = widget.detail;
|
||||
Widget listPane = widget.list;
|
||||
if (split) {
|
||||
// Beside the list the item is not under the shell's top bar (it
|
||||
// stays over the list pane): it keeps the system's own top
|
||||
// inset, so its bar sits just below the status bar at the top
|
||||
// edge. The shell's tab bar floats at the bottom right, over
|
||||
// this pane; its height (the shell's bottom padding here) plus
|
||||
// a gap lifts the item's tabs or composer above it.
|
||||
final system = ShellSystemInsets.of(context);
|
||||
body = MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(
|
||||
top: system.top,
|
||||
bottom: media.padding.bottom + kStackedBarGap,
|
||||
),
|
||||
),
|
||||
),
|
||||
divider,
|
||||
SizedBox(
|
||||
width: bodyWidth,
|
||||
child: SizedBox.expand(
|
||||
key: const ValueKey('list-detail-body'),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
identifier: 'list-detail-body',
|
||||
child: PageTabsEdge(
|
||||
edge: FloatingBarEdge.bottom,
|
||||
child: DetailPaneNavigator(
|
||||
identity: widget.detailIdentity,
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
// The tab bar sits over the detail pane, never the list (the
|
||||
// detail is at least half the window, wider than the bar), so
|
||||
// the list clears only the system's bottom inset.
|
||||
listPane = MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(bottom: system.bottom),
|
||||
),
|
||||
child: widget.list,
|
||||
);
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox.expand(
|
||||
key: const ValueKey('list-detail-list'),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
identifier: 'list-detail-list',
|
||||
child: listPane,
|
||||
),
|
||||
),
|
||||
),
|
||||
const ListPaneDividerLine(),
|
||||
SizedBox(
|
||||
width: bodyWidth,
|
||||
child: SizedBox.expand(
|
||||
key: const ValueKey('list-detail-body'),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
identifier: 'list-detail-body',
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (bounds != null)
|
||||
PositionedDirectional(
|
||||
start: listWidth + 0.5 - kListPaneDividerGrabWidth / 2,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
width: kListPaneDividerGrabWidth,
|
||||
child: ListPaneDivider(
|
||||
width: listWidth,
|
||||
min: bounds.min,
|
||||
max: bounds.max,
|
||||
onChanged: (value) => widths.preview(key, value),
|
||||
onChangeEnd: () => widths.commit(key),
|
||||
onReset: () => widths.reset(key),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
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),
|
||||
);
|
||||
@@ -0,0 +1,187 @@
|
||||
import 'package:flutter/gestures.dart' show DragStartBehavior;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../ui/adaptive/host.dart';
|
||||
|
||||
/// How wide the divider's invisible grab area is, centred on its line.
|
||||
const double kListPaneDividerGrabWidth = 12;
|
||||
|
||||
/// How far one arrow key press moves the divider.
|
||||
const double kListPaneDividerKeyStep = 16;
|
||||
|
||||
/// The one-pixel line between a list and its open item.
|
||||
class ListPaneDividerLine extends StatelessWidget {
|
||||
const ListPaneDividerLine({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => usesCupertinoHost(context)
|
||||
? Container(
|
||||
width: 1,
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
)
|
||||
: const VerticalDivider(width: 1);
|
||||
}
|
||||
|
||||
/// The grab area over [ListPaneDividerLine]: dragging it (mouse or touch)
|
||||
/// resizes the list pane between [min] and [max], the arrow keys move it by
|
||||
/// [kListPaneDividerKeyStep], and a double tap or click returns it to the
|
||||
/// default policy. It shows a handle while hovered, focused or dragged.
|
||||
class ListPaneDivider extends StatefulWidget {
|
||||
const ListPaneDivider({
|
||||
super.key,
|
||||
required this.width,
|
||||
required this.min,
|
||||
required this.max,
|
||||
required this.onChanged,
|
||||
required this.onChangeEnd,
|
||||
required this.onReset,
|
||||
});
|
||||
|
||||
/// The list pane's current width.
|
||||
final double width;
|
||||
final double min;
|
||||
final double max;
|
||||
|
||||
/// A new list width, live while dragging.
|
||||
final ValueChanged<double> onChanged;
|
||||
|
||||
/// The drag or key press ended: the width is final.
|
||||
final VoidCallback onChangeEnd;
|
||||
final VoidCallback onReset;
|
||||
|
||||
@override
|
||||
State<ListPaneDivider> createState() => _ListPaneDividerState();
|
||||
}
|
||||
|
||||
class _ListPaneDividerState extends State<ListPaneDivider> {
|
||||
bool _hovered = false;
|
||||
bool _focused = false;
|
||||
// The unclamped width the pointer asks for since the drag began, so moving
|
||||
// back past a bound picks up where the pointer is, not where it stopped.
|
||||
double? _dragWidth;
|
||||
|
||||
double _clamp(double value) => value.clamp(widget.min, widget.max);
|
||||
|
||||
// The list is at the start: in a right-to-left layout a drag to the left
|
||||
// widens it.
|
||||
double _forward(double dx) =>
|
||||
Directionality.of(context) == TextDirection.rtl ? -dx : dx;
|
||||
|
||||
void _dragStart(DragStartDetails _) =>
|
||||
setState(() => _dragWidth = widget.width);
|
||||
|
||||
void _dragUpdate(DragUpdateDetails details) {
|
||||
final width = (_dragWidth ?? widget.width) + _forward(details.delta.dx);
|
||||
_dragWidth = width;
|
||||
widget.onChanged(_clamp(width));
|
||||
}
|
||||
|
||||
void _dragEnd() {
|
||||
if (_dragWidth == null) return;
|
||||
setState(() => _dragWidth = null);
|
||||
widget.onChangeEnd();
|
||||
}
|
||||
|
||||
// A width a key press sent that the panes have not rebuilt with yet, so
|
||||
// presses quicker than frames add up.
|
||||
double? _stepped;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ListPaneDivider oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_stepped = null;
|
||||
}
|
||||
|
||||
void _step(double delta) {
|
||||
final current = _stepped ?? widget.width;
|
||||
final width = _clamp(current + delta);
|
||||
if (width == current) return;
|
||||
_stepped = width;
|
||||
widget.onChanged(width);
|
||||
widget.onChangeEnd();
|
||||
}
|
||||
|
||||
KeyEventResult _key(FocusNode _, KeyEvent event) {
|
||||
if (event is! KeyDownEvent && event is! KeyRepeatEvent) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
final key = event.logicalKey;
|
||||
if (key == LogicalKeyboardKey.arrowRight ||
|
||||
key == LogicalKeyboardKey.arrowLeft) {
|
||||
final right = key == LogicalKeyboardKey.arrowRight ? 1.0 : -1.0;
|
||||
_step(_forward(right * kListPaneDividerKeyStep));
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
String _describe(double width) => '${width.round()} pixels';
|
||||
|
||||
Color _handleColor(BuildContext context) => usesCupertinoHost(context)
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dragging = _dragWidth != null;
|
||||
final active = _hovered || _focused || dragging;
|
||||
final increased = _clamp(widget.width + kListPaneDividerKeyStep);
|
||||
final decreased = _clamp(widget.width - kListPaneDividerKeyStep);
|
||||
return Semantics(
|
||||
identifier: 'list-detail-divider',
|
||||
label: 'List width',
|
||||
hint: 'Drag, or use the arrow keys, to resize the list',
|
||||
slider: true,
|
||||
value: _describe(widget.width),
|
||||
increasedValue: _describe(increased),
|
||||
decreasedValue: _describe(decreased),
|
||||
onIncrease: increased == widget.width
|
||||
? null
|
||||
: () => _step(kListPaneDividerKeyStep),
|
||||
onDecrease: decreased == widget.width
|
||||
? null
|
||||
: () => _step(-kListPaneDividerKeyStep),
|
||||
child: Focus(
|
||||
onKeyEvent: _key,
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.resizeColumn,
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
key: const ValueKey('list-detail-divider'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
// The slider semantics above stand for the drag.
|
||||
excludeFromSemantics: true,
|
||||
// The handle follows the pointer from where it went down.
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onHorizontalDragStart: _dragStart,
|
||||
onHorizontalDragUpdate: _dragUpdate,
|
||||
onHorizontalDragEnd: (_) => _dragEnd(),
|
||||
onHorizontalDragCancel: _dragEnd,
|
||||
onDoubleTap: widget.onReset,
|
||||
child: Center(
|
||||
child: AnimatedOpacity(
|
||||
opacity: active ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: Container(
|
||||
width: 4,
|
||||
decoration: BoxDecoration(
|
||||
// A hovered or focused handle is a hint; it firms up
|
||||
// while dragged.
|
||||
color: _handleColor(
|
||||
context,
|
||||
).withValues(alpha: dragging ? 1 : 0.5),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Prefix of the persisted list-pane widths, one key per destination.
|
||||
const listPaneWidthStoragePrefix = 'pipelines.next.listPaneWidth.v1.';
|
||||
|
||||
/// The persistence seam for list-pane widths the operator dragged, in logical
|
||||
/// pixels per destination. Both directions may fail: a null read means
|
||||
/// "nothing saved", a false write means "this session only".
|
||||
abstract interface class ListPaneWidthStore {
|
||||
Future<double?> read(String destination);
|
||||
|
||||
/// Saves [width], or forgets the destination's width when it is null.
|
||||
Future<bool> write(String destination, double? width);
|
||||
}
|
||||
|
||||
/// `shared_preferences` storage under [listPaneWidthStoragePrefix].
|
||||
class SharedPreferencesListPaneWidthStore implements ListPaneWidthStore {
|
||||
const SharedPreferencesListPaneWidthStore();
|
||||
|
||||
@override
|
||||
Future<double?> read(String destination) async {
|
||||
try {
|
||||
return (await SharedPreferences.getInstance()).getDouble(
|
||||
'$listPaneWidthStoragePrefix$destination',
|
||||
);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> write(String destination, double? width) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final key = '$listPaneWidthStoragePrefix$destination';
|
||||
return width == null
|
||||
? await prefs.remove(key)
|
||||
: await prefs.setDouble(key, width);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An in-memory store for tests, fixtures and panes outside a shell.
|
||||
class MemoryListPaneWidthStore implements ListPaneWidthStore {
|
||||
MemoryListPaneWidthStore([Map<String, double>? values])
|
||||
: values = values ?? {};
|
||||
|
||||
final Map<String, double> values;
|
||||
|
||||
@override
|
||||
Future<double?> read(String destination) async => values[destination];
|
||||
|
||||
@override
|
||||
Future<bool> write(String destination, double? width) async {
|
||||
if (width == null) {
|
||||
values.remove(destination);
|
||||
} else {
|
||||
values[destination] = width;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// The list-pane widths the operator chose, per destination; a destination
|
||||
/// without one uses the default policy (`listDetailListWidth`).
|
||||
///
|
||||
/// A drag [preview]s widths live and [commit]s once; a window too small for
|
||||
/// a saved width clamps it when laying out, never here, so the saved value
|
||||
/// survives a small window.
|
||||
class ListPaneWidths extends ChangeNotifier {
|
||||
ListPaneWidths({ListPaneWidthStore? store})
|
||||
: _store = store ?? const SharedPreferencesListPaneWidthStore();
|
||||
|
||||
final ListPaneWidthStore _store;
|
||||
final Map<String, double> _widths = {};
|
||||
final Set<String> _loaded = {};
|
||||
bool _disposed = false;
|
||||
|
||||
/// The chosen width for [destination], null for the default policy. The
|
||||
/// first ask loads the saved width and notifies when it arrives.
|
||||
double? widthFor(String destination) {
|
||||
if (_loaded.add(destination)) _load(destination);
|
||||
return _widths[destination];
|
||||
}
|
||||
|
||||
Future<void> _load(String destination) async {
|
||||
final saved = await _store.read(destination);
|
||||
// A drag before the read finished wins over the saved value.
|
||||
if (_disposed || saved == null || _widths.containsKey(destination)) {
|
||||
return;
|
||||
}
|
||||
_widths[destination] = saved;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Shows [width] for [destination] without saving it.
|
||||
void preview(String destination, double width) {
|
||||
_loaded.add(destination);
|
||||
if (_widths[destination] == width) return;
|
||||
_widths[destination] = width;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Saves the destination's current width.
|
||||
Future<void> commit(String destination) async {
|
||||
await _store.write(destination, _widths[destination]);
|
||||
}
|
||||
|
||||
/// Shows and saves [width] for [destination].
|
||||
Future<void> set(String destination, double width) {
|
||||
preview(destination, width);
|
||||
return commit(destination);
|
||||
}
|
||||
|
||||
/// Returns [destination] to the default policy and forgets its width.
|
||||
Future<void> reset(String destination) async {
|
||||
_loaded.add(destination);
|
||||
if (_widths.remove(destination) != null) notifyListeners();
|
||||
await _store.write(destination, null);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides the shell's [ListPaneWidths] to the list-detail panes below it.
|
||||
class ListPaneWidthsScope extends InheritedNotifier<ListPaneWidths> {
|
||||
const ListPaneWidthsScope({
|
||||
super.key,
|
||||
required ListPaneWidths widths,
|
||||
required super.child,
|
||||
}) : super(notifier: widths);
|
||||
|
||||
static ListPaneWidths? maybeOf(BuildContext context) => context
|
||||
.dependOnInheritedWidgetOfExactType<ListPaneWidthsScope>()
|
||||
?.notifier;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# Resizable list pane
|
||||
|
||||
The divider between a list and its open item (`ListDetailPanes`) drags to
|
||||
resize the list, on every destination that splits (Pipelines, Runs, Chat).
|
||||
|
||||
- `lib/shell/list_pane_divider.dart`: 12 px grab area over the 1 px line,
|
||||
`resizeColumn` cursor, handle on hover/focus/drag, mouse and touch drag,
|
||||
double tap resets, arrow keys step 16 px, slider semantics.
|
||||
- `lib/shell/list_pane_widths.dart`: per-destination widths, saved in
|
||||
SharedPreferences under `pipelines.next.listPaneWidth.v1.<destination>`
|
||||
on drag end; the shell owns one and the bar over the list follows it.
|
||||
- `lib/shell/list_detail_policy.dart`: `listPaneWidthBounds` (list >= 240,
|
||||
open item >= max(half the window, 320), list <= 60% of the window). A saved
|
||||
width is clamped when laid out, never overwritten by a small window.
|
||||
- Below `kListDetailMinWidth` nothing changes.
|
||||
- Capture kit: new `hover=` and `drag=` steps. Evidence: /tmp/split-drag/.
|
||||
@@ -0,0 +1,222 @@
|
||||
import 'dart:ui' show SemanticsAction;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/list_detail.dart';
|
||||
import 'package:pipelines_app/shell/list_pane_divider.dart';
|
||||
import 'package:pipelines_app/shell/list_pane_widths.dart';
|
||||
import 'package:pipelines_app/shell/shell_bar.dart';
|
||||
|
||||
/// Dragging the divider between a list and its open item resizes the list,
|
||||
/// within bounds, per destination, remembered on this device.
|
||||
void main() {
|
||||
Future<void> setSize(WidgetTester tester, Size size) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
Widget panes(String name) => ListDetailPanes(
|
||||
list: ShellBar(child: ListView(children: [Text('$name list')])),
|
||||
detail: Center(child: Text('$name detail')),
|
||||
);
|
||||
|
||||
Widget shell({
|
||||
required bool cupertino,
|
||||
required ListPaneWidthStore store,
|
||||
AppDestination destination = AppDestination.runs,
|
||||
}) {
|
||||
final app = AdaptiveShell(
|
||||
cupertino: cupertino,
|
||||
destination: destination,
|
||||
listPaneWidthStore: store,
|
||||
destinationBodies: {
|
||||
AppDestination.runs: (_) => panes('runs'),
|
||||
AppDestination.chat: (_) => panes('chat'),
|
||||
},
|
||||
);
|
||||
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
|
||||
}
|
||||
|
||||
Future<void> settle(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
}
|
||||
|
||||
double listWidth(WidgetTester tester) =>
|
||||
tester.getSize(find.byKey(const ValueKey('list-detail-list'))).width;
|
||||
double bodyWidth(WidgetTester tester) =>
|
||||
tester.getSize(find.byKey(const ValueKey('list-detail-body'))).width;
|
||||
// The shell's top bar, narrowed to the list pane.
|
||||
double shellBarWidth(WidgetTester tester) => tester
|
||||
.getSize(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ListPaneWidth),
|
||||
matching: find.byType(SizedBox),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.width;
|
||||
final divider = find.byKey(const ValueKey('list-detail-divider'));
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: dragging resizes the list live, the shell bar '
|
||||
'follows, and the width clamps', (tester) async {
|
||||
await setSize(tester, const Size(1200, 800));
|
||||
final store = MemoryListPaneWidthStore();
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth);
|
||||
expect(shellBarWidth(tester), kListPaneMaxWidth);
|
||||
|
||||
final gesture = await tester.startGesture(tester.getCenter(divider));
|
||||
await gesture.moveBy(const Offset(-50, 0));
|
||||
await gesture.moveBy(const Offset(-50, 0));
|
||||
await tester.pump();
|
||||
// Live, before the drag ends; nothing saved yet.
|
||||
expect(listWidth(tester), closeTo(340, 0.5));
|
||||
expect(shellBarWidth(tester), closeTo(340, 0.5));
|
||||
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5));
|
||||
expect(store.values, isEmpty);
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
expect(store.values['runs'], closeTo(340, 0.5));
|
||||
|
||||
// Never narrower than the minimum...
|
||||
await tester.drag(divider, const Offset(-400, 0));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMinWidth);
|
||||
// ...nor wider than leaves the open item half the window.
|
||||
await tester.drag(divider, const Offset(900, 0));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
|
||||
expect(shellBarWidth(tester), closeTo(599, 0.5));
|
||||
expect(store.values['runs'], closeTo(599, 0.5));
|
||||
});
|
||||
|
||||
testWidgets('$host: a double tap returns to the default policy', (
|
||||
tester,
|
||||
) async {
|
||||
await setSize(tester, const Size(1200, 800));
|
||||
final store = MemoryListPaneWidthStore({'runs': 300});
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), 300);
|
||||
|
||||
await tester.tap(divider);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.tap(divider);
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth);
|
||||
expect(shellBarWidth(tester), kListPaneMaxWidth);
|
||||
expect(store.values, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('$host: widths are kept per destination and restored', (
|
||||
tester,
|
||||
) async {
|
||||
await setSize(tester, const Size(1200, 800));
|
||||
final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500});
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), 300);
|
||||
expect(shellBarWidth(tester), 300);
|
||||
|
||||
await tester.pumpWidget(
|
||||
shell(
|
||||
cupertino: cupertino,
|
||||
store: store,
|
||||
destination: AppDestination.chat,
|
||||
),
|
||||
);
|
||||
await settle(tester);
|
||||
final chatList = find.byKey(const ValueKey('list-detail-list')).last;
|
||||
expect(tester.getSize(chatList).width, 500);
|
||||
expect(shellBarWidth(tester), 500);
|
||||
|
||||
// A destination nobody resized keeps the default policy.
|
||||
final fresh = MemoryListPaneWidthStore({'chat': 500});
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: fresh));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth);
|
||||
});
|
||||
|
||||
testWidgets('$host: a small window clamps the saved width without '
|
||||
'overwriting it', (tester) async {
|
||||
await setSize(tester, const Size(1000, 800));
|
||||
final store = MemoryListPaneWidthStore({'runs': 600});
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), closeTo(1000 - 1 - 500, 0.5));
|
||||
expect(shellBarWidth(tester), closeTo(499, 0.5));
|
||||
expect(store.values['runs'], 600);
|
||||
|
||||
await setSize(tester, const Size(1600, 800));
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), 600);
|
||||
expect(shellBarWidth(tester), 600);
|
||||
});
|
||||
|
||||
testWidgets('$host: arrow keys move the divider and it reads as a '
|
||||
'slider', (tester) async {
|
||||
await setSize(tester, const Size(1200, 800));
|
||||
final store = MemoryListPaneWidthStore();
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
||||
await settle(tester);
|
||||
Focus.of(tester.element(divider)).requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep);
|
||||
expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep);
|
||||
|
||||
expect(
|
||||
tester.getSemantics(divider),
|
||||
matchesSemantics(
|
||||
label: 'List width',
|
||||
hint: 'Drag, or use the arrow keys, to resize the list',
|
||||
value: '456 pixels',
|
||||
increasedValue: '472 pixels',
|
||||
decreasedValue: '440 pixels',
|
||||
isSlider: true,
|
||||
isFocusable: true,
|
||||
isFocused: true,
|
||||
hasIncreaseAction: true,
|
||||
hasDecreaseAction: true,
|
||||
hasFocusAction: true,
|
||||
),
|
||||
);
|
||||
tester.semantics.performAction(
|
||||
find.semantics.byLabel('List width'),
|
||||
SemanticsAction.decrease,
|
||||
);
|
||||
await settle(tester);
|
||||
expect(listWidth(tester), kListPaneMaxWidth);
|
||||
semantics.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
test('bounds: list at least 240, open item at least half the window', () {
|
||||
expect(listPaneWidthBounds(1200, 1200), (min: 240.0, max: 599.0));
|
||||
expect(listPaneWidthBounds(600, 600), (min: 240.0, max: 279.0));
|
||||
expect(listPaneWidthBounds(500, 500), isNull);
|
||||
expect(listDetailListWidth(1200, 1200, 100), 240);
|
||||
expect(listDetailListWidth(1200, 1200, 300), 300);
|
||||
expect(listDetailListWidth(500, 500, 300), listDetailListWidth(500, 500));
|
||||
});
|
||||
}
|
||||
@@ -47,6 +47,8 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`.
|
||||
| `type=text` | type into the focused field (or the first visible one) |
|
||||
| `press=Enter` | press a key: Enter, Escape, Tab, Backspace, ArrowUp or ArrowDown |
|
||||
| `scroll=600` | scroll with the mouse wheel at the centre (JSON `at` sets a target, `dx` a horizontal delta, `repeat` and `gap` a run of ticks) |
|
||||
| `hover=<target>` | move the mouse onto the target without pressing (hover states) |
|
||||
| `drag=<target>>dx,dy` | press on the target, move by dx,dy in `steps` (12) moves `gap` (16) ms apart, release (JSON `dx`, `dy`, `steps`, `gap`; `hold: true` keeps the button down to capture mid-drag) |
|
||||
| `size=WxH` | resize without reloading |
|
||||
| `labels=name` | write the visible semantics labels, keys and rects to JSON |
|
||||
| `film=<target>` | screencast a click for `--film-ms` (900) and write the frames plus a contact sheet |
|
||||
|
||||
@@ -22,7 +22,8 @@ options: --script <steps.json> --size WxH (880x1000) --platform material|cuperti
|
||||
--params <query, e.g. chats=2&rich=1, added to every open>
|
||||
steps: open=<route>[@WxH] wait=<ms> shot=<name> click=<target> waitfor=<target>
|
||||
type=<text> press=<Enter|Escape|Tab|...> scroll=<dy> size=WxH
|
||||
film=<target> labels=<name> eval=<js> expect=<js>
|
||||
film=<target> labels=<name> eval=<js> expect=<js> hover=<target>
|
||||
drag=<target>><dx>,<dy> (JSON: drag, dx, dy, steps, gap, hold)
|
||||
target: <label> | label:<label> | key:<semantics identifier> | x,y`;
|
||||
|
||||
const opts = { wait: '1000', 'film-ms': '900' };
|
||||
@@ -118,6 +119,24 @@ try {
|
||||
await delay(step.wait ?? settle);
|
||||
break;
|
||||
}
|
||||
case 'hover': {
|
||||
const at = await page.hover(value, step.timeout);
|
||||
log(` mouse at ${Math.round(at.x)},${Math.round(at.y)}`);
|
||||
await delay(step.wait ?? settle);
|
||||
break;
|
||||
}
|
||||
case 'drag': {
|
||||
// CLI form: drag=<target>><dx>,<dy>; JSON may set dx/dy instead.
|
||||
const [target, by] = String(value).split('>');
|
||||
const [bx, by2] = (by ?? '').split(',').map(Number);
|
||||
const moved = await page.drag(target, {
|
||||
dx: Number(step.dx ?? bx ?? 0) || 0, dy: Number(step.dy ?? by2 ?? 0) || 0,
|
||||
steps: Number(step.steps ?? 12), gap: Number(step.gap ?? 16), hold: Boolean(step.hold),
|
||||
});
|
||||
log(` dragged ${Math.round(moved.from.x)},${Math.round(moved.from.y)} -> ${Math.round(moved.to.x)},${Math.round(moved.to.y)}`);
|
||||
await delay(step.wait ?? settle);
|
||||
break;
|
||||
}
|
||||
case 'eval': {
|
||||
const result = await page.evaluate(String(value));
|
||||
log(` = ${JSON.stringify(result)}`);
|
||||
|
||||
@@ -143,6 +143,29 @@ export function flutterPage(browser, log) {
|
||||
}
|
||||
return at;
|
||||
},
|
||||
/** Moves the mouse onto [target] without pressing (hover states, cursors). */
|
||||
async hover(target, timeout) {
|
||||
const at = await locate(target, timeout);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: at.x, y: at.y });
|
||||
return at;
|
||||
},
|
||||
/**
|
||||
* Presses the mouse on [target], moves it by dx/dy in [steps] moves [gap] ms
|
||||
* apart, and releases it unless [hold] (to capture mid-drag; the next
|
||||
* mouse step or the end of the run releases it).
|
||||
*/
|
||||
async drag(target, { dx = 0, dy = 0, steps = 12, gap = 16, hold = false } = {}) {
|
||||
const at = await locate(target);
|
||||
const mouse = (type, x, y, extra = {}) => send('Input.dispatchMouseEvent', { type, x, y, button: 'left', ...extra });
|
||||
await mouse('mouseMoved', at.x, at.y, { button: 'none' });
|
||||
await mouse('mousePressed', at.x, at.y, { buttons: 1, clickCount: 1 });
|
||||
for (let i = 1; i <= steps; i++) {
|
||||
await delay(gap);
|
||||
await mouse('mouseMoved', at.x + (dx * i) / steps, at.y + (dy * i) / steps, { buttons: 1 });
|
||||
}
|
||||
if (!hold) await mouse('mouseReleased', at.x + dx, at.y + dy, { buttons: 0, clickCount: 1 });
|
||||
return { from: at, to: { x: at.x + dx, y: at.y + dy } };
|
||||
},
|
||||
evaluate,
|
||||
/** Screencasts [ms] after clicking [target]; frames are `{ data, ms }` relative to the click. */
|
||||
async film(target, ms) {
|
||||
|
||||
Reference in New Issue
Block a user