Various fixes/features

This commit is contained in:
space-nuko
2023-05-17 20:17:00 -05:00
parent fe3efe1154
commit ab54f771b1
22 changed files with 186 additions and 66 deletions

View File

@@ -30,6 +30,51 @@
// TODO
}
function moveTo(delta: number | ((cur: number, total: number) => number)) {
const dragItemID = $selectionState.currentSelection[0];
const entry = $layoutState.allItems[dragItemID];
if (!entry) {
return
}
const dragItem = entry.dragItem;
const containing = entry.parent
if (containing == null || containing.type !== "container") {
return
}
const containingEntry = $layoutState.allItems[containing.id];
const oldIndex = containingEntry.children.findIndex(c => c.id === dragItem.id)
if (oldIndex === -1) {
return;
}
let newIndex: number;
if (typeof delta === "number")
newIndex = oldIndex + delta;
else
newIndex = delta(oldIndex, containingEntry.children.length);
layoutState.moveItem(dragItem, containing as ContainerLayout, newIndex)
$layoutState = $layoutState
}
function moveUp() {
moveTo(-1)
}
function moveDown() {
moveTo(1)
}
function sendToTop() {
moveTo(() => 0)
}
function sendToBottom() {
moveTo((cur: number, total: number) => total - 1)
}
function groupWidgets(horizontal: boolean) {
const items = $selectionState.currentSelection
$selectionState.currentSelection = []
@@ -110,6 +155,23 @@
{#if showMenu}
<Menu {...menuPos} on:click={closeMenu} on:clickoutside={closeMenu}>
<MenuOption
isDisabled={$selectionState.currentSelection.length !== 1}
on:click={() => moveUp()}
text="Move Up" />
<MenuOption
isDisabled={$selectionState.currentSelection.length !== 1}
on:click={() => moveDown()}
text="Move Down" />
<MenuOption
isDisabled={$selectionState.currentSelection.length !== 1}
on:click={() => sendToTop()}
text="Send to Top" />
<MenuOption
isDisabled={$selectionState.currentSelection.length !== 1}
on:click={() => sendToBottom()}
text="Send to Bottom" />
<MenuDivider/>
<MenuOption
isDisabled={$selectionState.currentSelection.length === 0}
on:click={() => groupWidgets(false)}