Chat stack: hold and drag to reorder the open chats, or onto x to remove
A 300 ms hold lifts a chat in the open column; dragging opens a gap and dropping commits through ChatWorkspaceController.movePane, the pane order the server syncs. An x comes in at the bottom while dragging; dropping on it removes the chat with Undo, which restores its place. Escape, a cancelled pointer or a drop away from the column put it back. Move up, Move down and Remove are semantic actions. Repaint-only motion; reduced motion swaps at once. Also keep floating-layout tracking out of initState, and let the capture kit hold a press before a drag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'chat_stack_drag.dart';
|
||||
|
||||
/// Paints [child] where [item] says while a chat of the open column is
|
||||
/// dragged: moved, and scaled about its centre when [scales]. A change only
|
||||
/// repaints (the matrix and the layer are reused); hit tests follow it. At
|
||||
/// rest it paints straight through, with no layer.
|
||||
class ChatStackDragShift extends SingleChildRenderObjectWidget {
|
||||
const ChatStackDragShift({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.scales = true,
|
||||
super.child,
|
||||
});
|
||||
|
||||
final ChatStackDragItem item;
|
||||
final bool scales;
|
||||
|
||||
@override
|
||||
RenderChatStackDragShift createRenderObject(BuildContext context) =>
|
||||
RenderChatStackDragShift(item: item, scales: scales);
|
||||
|
||||
@override
|
||||
void updateRenderObject(
|
||||
BuildContext context,
|
||||
RenderChatStackDragShift renderObject,
|
||||
) {
|
||||
renderObject
|
||||
..item = item
|
||||
..scales = scales;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderChatStackDragShift extends RenderProxyBox {
|
||||
RenderChatStackDragShift({
|
||||
required ChatStackDragItem item,
|
||||
required bool scales,
|
||||
}) {
|
||||
_item = item;
|
||||
_scales = scales;
|
||||
}
|
||||
|
||||
late ChatStackDragItem _item;
|
||||
set item(ChatStackDragItem value) {
|
||||
if (identical(value, _item)) return;
|
||||
if (attached) _item.removeListener(_changed);
|
||||
_item = value;
|
||||
if (attached) _item.addListener(_changed);
|
||||
_changed();
|
||||
}
|
||||
|
||||
late bool _scales;
|
||||
set scales(bool value) {
|
||||
if (value == _scales) return;
|
||||
_scales = value;
|
||||
_changed();
|
||||
}
|
||||
|
||||
final Matrix4 _matrix = Matrix4.identity();
|
||||
final LayerHandle<TransformLayer> _layer = LayerHandle<TransformLayer>();
|
||||
|
||||
bool get _moved =>
|
||||
_item.offset != Offset.zero || (_scales && _item.scale != 1);
|
||||
|
||||
bool _wasMoved = false;
|
||||
|
||||
void _changed() {
|
||||
// Entering or leaving rest adds or drops the transform layer.
|
||||
final moved = _moved;
|
||||
if (moved != _wasMoved) {
|
||||
_wasMoved = moved;
|
||||
markNeedsCompositingBitsUpdate();
|
||||
}
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(PipelineOwner owner) {
|
||||
super.attach(owner);
|
||||
_wasMoved = _moved;
|
||||
_item.addListener(_changed);
|
||||
}
|
||||
|
||||
@override
|
||||
void detach() {
|
||||
_item.removeListener(_changed);
|
||||
super.detach();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_layer.layer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
bool get alwaysNeedsCompositing => child != null && _moved;
|
||||
|
||||
Matrix4 _current() {
|
||||
final offset = _item.offset;
|
||||
final scale = _scales ? _item.scale : 1.0;
|
||||
final cx = size.width / 2;
|
||||
final cy = size.height / 2;
|
||||
return _matrix
|
||||
..setIdentity()
|
||||
..translateByDouble(offset.dx + cx, offset.dy + cy, 0, 1)
|
||||
..scaleByDouble(scale, scale, 1, 1)
|
||||
..translateByDouble(-cx, -cy, 0, 1);
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (child == null) return;
|
||||
if (!_moved) {
|
||||
_layer.layer = null;
|
||||
super.paint(context, offset);
|
||||
return;
|
||||
}
|
||||
_layer.layer = context.pushTransform(
|
||||
needsCompositing,
|
||||
offset,
|
||||
_current(),
|
||||
super.paint,
|
||||
oldLayer: _layer.layer,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
||||
if (!_moved) return super.hitTestChildren(result, position: position);
|
||||
return result.addWithPaintTransform(
|
||||
transform: _current(),
|
||||
position: position,
|
||||
hitTest: (result, position) =>
|
||||
super.hitTestChildren(result, position: position),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void applyPaintTransform(RenderBox child, Matrix4 transform) {
|
||||
if (_moved) transform.multiply(_current());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user