Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position of drag image #595

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/default-theme/style/tabbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@
min-width: 125px;
border: none;
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
transform: translateX(-40%) translateY(-58%);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it's always overridden by

protected moveDragImage(clientX: number, clientY: number): void {
if (!this.dragImage) {
return;
}
let style = this.dragImage.style;
style.transform = `translate(${clientX}px, ${clientY}px)`;

}
6 changes: 5 additions & 1 deletion packages/widgets/src/dockpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ export class DockPanel extends Widget {
sender.releaseMouse();

// Extract the data from the args.
let { title, tab, clientX, clientY } = args;
let { title, tab, clientX, clientY, offset } = args;

// Setup the mime data for the drag operation.
let mimeData = new MimeData();
Expand All @@ -1033,6 +1033,10 @@ export class DockPanel extends Widget {

// Create the drag image for the drag operation.
let dragImage = tab.cloneNode(true) as HTMLElement;
if (offset) {
dragImage.style.top = `-${offset.y}px`;
dragImage.style.left = `-${offset.x}px`;
}

// Create the drag object to manage the drag-drop operation.
this._drag = new Drag({
Expand Down
25 changes: 24 additions & 1 deletion packages/widgets/src/tabbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ export class TabBar<T> extends Widget {
data.tabSize = tabRect.height;
data.tabPressPos = data.pressY - tabRect.top;
}
data.tabPressOffset = {
x: data.pressX - tabRect.left,
y: data.pressY - tabRect.top
};
data.tabLayout = Private.snapTabLayout(tabs, this._orientation);
data.contentRect = this.contentNode.getBoundingClientRect();
data.override = Drag.overrideCursor('default');
Expand All @@ -875,7 +879,14 @@ export class TabBar<T> extends Widget {
let title = this._titles[index];

// Emit the tab detach requested signal.
this._tabDetachRequested.emit({ index, title, tab, clientX, clientY });
this._tabDetachRequested.emit({
index,
title,
tab,
clientX,
clientY,
offset: data.tabPressOffset
});

// Bail if the signal handler aborted the drag.
if (data.dragAborted) {
Expand Down Expand Up @@ -1472,6 +1483,11 @@ export namespace TabBar {
* The current client Y position of the mouse.
*/
readonly clientY: number;

/**
* The mouse position in the tab coordinate.
*/
readonly offset?: { x: number; y: number };
}

/**
Expand Down Expand Up @@ -1764,6 +1780,13 @@ namespace Private {
*/
tabPressPos: number;

/**
* The original mouse position in tab coordinates.
*
* This is undefined if the drag is not active.
*/
tabPressOffset?: { x: number; y: number };

/**
* The tab target index upon mouse release.
*
Expand Down
4 changes: 4 additions & 0 deletions review/api/widgets.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,10 @@ export namespace TabBar {
readonly clientX: number;
readonly clientY: number;
readonly index: number;
readonly offset?: {
x: number;
y: number;
};
readonly tab: HTMLElement;
readonly title: Title<T>;
}
Expand Down