better tab dragging off

This commit is contained in:
nakst 2021-09-10 15:36:25 +01:00
parent eb18fd7e21
commit 9ce99cde84
3 changed files with 15 additions and 28 deletions

View File

@ -254,7 +254,7 @@ bool ReorderItemDragged(ReorderItem *item, int mouseX) {
item->dragPosition = mouseX + item->GetWindowBounds().l - item->dragOffset; item->dragPosition = mouseX + item->GetWindowBounds().l - item->dragOffset;
int draggedIndex = (item->dragPosition + list->targetWidth / 2) / list->targetWidth; int draggedIndex = list->targetWidth ? ((item->dragPosition + list->targetWidth / 2) / list->targetWidth) : 0;
if (draggedIndex < 0) draggedIndex = 0; if (draggedIndex < 0) draggedIndex = 0;
if (draggedIndex >= (int) childCount) draggedIndex = childCount - 1; if (draggedIndex >= (int) childCount) draggedIndex = childCount - 1;
int currentIndex = -1; int currentIndex = -1;
@ -591,49 +591,36 @@ int WindowTabMessage(EsElement *element, EsMessage *message) {
EsPoint screenPosition = EsMouseGetPosition(); EsPoint screenPosition = EsMouseGetPosition();
WindowChangeBounds(RESIZE_MOVE, screenPosition.x, screenPosition.y, &gui.lastClickX, &gui.lastClickY, band->window); WindowChangeBounds(RESIZE_MOVE, screenPosition.x, screenPosition.y, &gui.lastClickX, &gui.lastClickY, band->window);
} else { } else {
EsRectangle tabBarBounds = tab->parent->GetWindowBounds(); EsPoint mousePosition = EsMouseGetPosition(tab->window);
EsRectangle tabBounds = tab->GetWindowBounds();
int32_t mouseX = message->mouseDragged.newPositionX + tabBounds.l;
int32_t mouseY = message->mouseDragged.newPositionY + tabBounds.t;
int32_t dragOffThreshold = GetConstantNumber("tabDragOffThreshold"); int32_t dragOffThreshold = GetConstantNumber("tabDragOffThreshold");
int32_t previousTabOffsetX = tab->offsetX;
if (EsRectangleContains(EsRectangleAdd(tabBarBounds, ES_RECT_1I(-dragOffThreshold)), mouseX, mouseY)) { if (EsRectangleContains(EsRectangleAdd(band->GetWindowBounds(), ES_RECT_1I(-dragOffThreshold)), mousePosition.x, mousePosition.y)) {
ReorderItemDragged(tab, message->mouseDragged.newPositionX); ReorderItemDragged(tab, message->mouseDragged.newPositionX);
} else { } else {
// Save information about the old container. // If we dragged the tab off the left or right side of the band, put it at the start of the new tab band.
int32_t oldTabDragX = mouseX - tab->dragOffset; bool putAtStart = tab->dragPosition < band->currentStyle->insets.l
int32_t oldTabDragY = mouseY - (gui.lastClickY - tab->offsetY); || tab->dragPosition + tab->width > band->width - band->currentStyle->insets.r;
EsRectangle oldContainerBounds = tab->window->GetScreenBounds(); int32_t putAtStartClickX = band->currentStyle->insets.l + tab->dragOffset;
EsRectangle oldTabBarScreenBounds = tab->parent->GetScreenBounds();
EsWindow *oldContainer = tab->window;
EsPoint mousePosition = EsMouseGetPosition(oldContainer);
// End the drag on this container. // End the drag on this container.
EsMessage m = { .type = ES_MSG_MOUSE_LEFT_UP }; EsMessage m = { .type = ES_MSG_MOUSE_LEFT_UP };
UIMouseUp(oldContainer, &m, false); UIMouseUp(band->window, &m, false);
// Move the tab to a new container. // Move the tab to a new container.
WindowTab *newTab = WindowTabMoveToNewContainer(tab); WindowTab *newTab = WindowTabMoveToNewContainer(tab);
if (newTab) { if (newTab) {
// Work out the position of the new container, so that the mouse position within the tab is preserved. // Transfer the drag to the new container.
newTab->window->width = Width(oldContainerBounds); EsSyscall(ES_SYSCALL_WINDOW_TRANSFER_PRESS, band->window->handle, newTab->window->handle, 0, 0);
newTab->window->height = Height(oldContainerBounds); ReorderItemDragged(newTab, 0);
UIWindowLayoutNow(newTab->window, nullptr); newTab->dragPosition = putAtStart ? band->currentStyle->insets.l : previousTabOffsetX;
EsRectangle newTabWindowBounds = newTab->GetWindowBounds();
EsRectangle bounds = ES_RECT_4PD(oldTabBarScreenBounds.l + oldTabDragX - newTabWindowBounds.l,
oldTabBarScreenBounds.t + oldTabDragY - newTabWindowBounds.t,
Width(oldContainerBounds), Height(oldContainerBounds));
EsSyscall(ES_SYSCALL_WINDOW_MOVE, newTab->window->handle, (uintptr_t) &bounds, 0, ES_WINDOW_MOVE_DYNAMIC);
// Start the drag on the new container.
EsSyscall(ES_SYSCALL_WINDOW_TRANSFER_PRESS, oldContainer->handle, newTab->window->handle, 0, 0);
newTab->window->pressed = newTab; newTab->window->pressed = newTab;
newTab->window->dragged = newTab; newTab->window->dragged = newTab;
gui.lastClickX = putAtStart ? putAtStartClickX : mousePosition.x;
gui.mouseButtonDown = true; gui.mouseButtonDown = true;
gui.draggingStarted = true; gui.draggingStarted = true;
gui.lastClickX = mousePosition.x + oldContainerBounds.l - bounds.l; WindowTabMessage(newTab, message);
gui.lastClickY = mousePosition.y + oldContainerBounds.t - bounds.t;
} }
} }
} }

Binary file not shown.

Binary file not shown.