Double-click a chat divider to switch the split layout
Double-clicking the divider between two chat panes flips that split between side by side and stacked, keeping its proportion, instead of resetting it to 50/50. Screen readers get the same action.
This commit is contained in:
@@ -138,6 +138,28 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
_changed();
|
||||
}
|
||||
|
||||
/// Flips one split between side by side and stacked, keeping its ratio.
|
||||
void toggleAxis(String splitId) {
|
||||
if (_root == null) return;
|
||||
_root = _toggle(_root!, splitId);
|
||||
_changed();
|
||||
}
|
||||
|
||||
ChatWorkspaceNode _toggle(ChatWorkspaceNode node, String id) {
|
||||
if (node is! ChatWorkspaceSplit) return node;
|
||||
return ChatWorkspaceSplit(
|
||||
node.id,
|
||||
node.id == id
|
||||
? (node.axis == ChatSplitAxis.horizontal
|
||||
? ChatSplitAxis.vertical
|
||||
: ChatSplitAxis.horizontal)
|
||||
: node.axis,
|
||||
_toggle(node.first, id),
|
||||
_toggle(node.second, id),
|
||||
ratio: node.ratio,
|
||||
);
|
||||
}
|
||||
|
||||
void close(String paneId) {
|
||||
final before = panes;
|
||||
final index = before.indexWhere((p) => p.id == paneId);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
@@ -13,10 +14,15 @@ class ChatWorkspaceDivider extends StatefulWidget {
|
||||
super.key,
|
||||
required this.geometry,
|
||||
required this.onChanged,
|
||||
this.onToggleAxis,
|
||||
});
|
||||
final ChatWorkspaceDividerGeometry geometry;
|
||||
final ValueChanged<double> onChanged;
|
||||
|
||||
/// Double-clicking the divider flips the split between side by side and
|
||||
/// stacked.
|
||||
final VoidCallback? onToggleAxis;
|
||||
|
||||
@override
|
||||
State<ChatWorkspaceDivider> createState() => _ChatWorkspaceDividerState();
|
||||
}
|
||||
@@ -56,6 +62,13 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
||||
decreasedValue:
|
||||
'${((_actual - 16 / _available).clamp(widget.geometry.minimum, widget.geometry.maximum) * 100).round()} percent',
|
||||
onIncrease: () => _step(16),
|
||||
customSemanticsActions: widget.onToggleAxis == null
|
||||
? null
|
||||
: {
|
||||
CustomSemanticsAction(
|
||||
label: _horizontal ? 'Stack panes' : 'Place panes side by side',
|
||||
): widget.onToggleAxis!,
|
||||
},
|
||||
onDecrease: () => _step(-16),
|
||||
child: Focus(
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
@@ -83,7 +96,7 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onDoubleTap: () => _change(.5),
|
||||
onDoubleTap: widget.onToggleAxis,
|
||||
onPanStart: (_) => setState(() => _drag = _actual),
|
||||
onPanUpdate: (details) {
|
||||
_drag =
|
||||
@@ -96,7 +109,9 @@ class _ChatWorkspaceDividerState extends State<ChatWorkspaceDivider> {
|
||||
onPanCancel: () => setState(() => _drag = null),
|
||||
child: Tooltip(
|
||||
excludeFromSemantics: true,
|
||||
message: 'Drag to resize chat panes',
|
||||
message: widget.onToggleAxis == null
|
||||
? 'Drag to resize chat panes'
|
||||
: 'Drag to resize · double-click to switch layout',
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
|
||||
@@ -144,6 +144,7 @@ Widget chatWorkspaceSurface({
|
||||
geometry: divider,
|
||||
onChanged: (ratio) =>
|
||||
controller.resize(divider.split.id, ratio),
|
||||
onToggleAxis: () => controller.toggleAxis(divider.split.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user