-
Notifications
You must be signed in to change notification settings - Fork 397
Fix/selection toolbox reflow #5158
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ab32840
fix: layout perf issue
simula-r 5400033
feat: skip a whole host of transform issues created by the SelectionO…
simula-r de5b425
refactor: removed unused files/functionality
simula-r 6e17eb7
refactor: removed unused types
simula-r f09a4f8
fix: z index issue
simula-r e781b6a
fix: PR feedback
simula-r 71d6ebd
fix: PR feedback and more perf improvements
simula-r 166395e
Update test expectations [skip ci]
invalid-email-address File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { ref, watch } from 'vue' | ||
| import type { CSSProperties } from 'vue' | ||
|
|
||
| import { useCanvasTransformSync } from '@/composables/canvas/useCanvasTransformSync' | ||
| import { useSelectedLiteGraphItems } from '@/composables/canvas/useSelectedLiteGraphItems' | ||
| import { createBounds } from '@/lib/litegraph/src/litegraph' | ||
| import { useCanvasStore } from '@/stores/graphStore' | ||
|
|
||
| /** | ||
| * Manages the position of the selection toolbox independently. | ||
| * Uses transform for all positioning to avoid layout. | ||
| */ | ||
| export function useSelectionToolboxPosition() { | ||
| const canvasStore = useCanvasStore() | ||
| const lgCanvas = canvasStore.getCanvas() | ||
| const { getSelectableItems } = useSelectedLiteGraphItems() | ||
|
|
||
| // World position of selection center | ||
| const worldPosition = ref({ x: 0, y: 0, width: 0, height: 0 }) | ||
|
|
||
| // Visibility state | ||
| const visible = ref(false) | ||
|
|
||
| // Style for toolbox positioning | ||
| const style = ref<CSSProperties>({ | ||
| position: 'fixed', | ||
| left: '0', | ||
| top: '0', | ||
| visibility: 'hidden' | ||
| }) | ||
|
|
||
| /** | ||
| * Update position based on selection | ||
| */ | ||
| const updateSelectionBounds = () => { | ||
| const selectableItems = getSelectableItems() | ||
|
|
||
| if (!selectableItems.size) { | ||
| visible.value = false | ||
| style.value = { | ||
| ...style.value, | ||
| visibility: 'hidden' | ||
| } | ||
| return | ||
| } | ||
|
|
||
| visible.value = true | ||
| const bounds = createBounds(selectableItems) | ||
|
|
||
| if (bounds) { | ||
| // Store world coordinates | ||
| // bounds = [x, y, width, height] | ||
| worldPosition.value = { | ||
| x: bounds[0] + bounds[2] / 2, // Center X of bounds | ||
| y: bounds[1], // Top Y of bounds | ||
| width: bounds[2], | ||
| height: bounds[3] | ||
| } | ||
|
|
||
| updateTransform() | ||
| } | ||
simula-r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Update transform based on canvas state | ||
| */ | ||
| const updateTransform = () => { | ||
| if (!visible.value) return | ||
|
|
||
| const { scale, offset } = lgCanvas.ds | ||
| const canvasRect = lgCanvas.canvas.getBoundingClientRect() | ||
|
|
||
| // Transform world to screen coordinates | ||
| // Position toolbox at top-center of selection | ||
| const screenX = | ||
| (worldPosition.value.x + offset[0]) * scale + canvasRect.left | ||
| const screenY = (worldPosition.value.y + offset[1]) * scale + canvasRect.top | ||
|
|
||
| // Position the toolbox above the selection bounds | ||
| // The -50% centers it horizontally, and we subtract pixels to position above | ||
| const toolboxOffset = 45 // Pixels above the selection | ||
|
|
||
| style.value = { | ||
| position: 'fixed', | ||
| left: '0', | ||
| top: '0', | ||
| transform: `translate(${screenX}px, ${screenY - toolboxOffset}px) translateX(-50%)`, | ||
| visibility: 'visible', | ||
| willChange: 'transform' | ||
| } | ||
| } | ||
|
|
||
| // Sync with canvas transform | ||
| const { startSync, stopSync } = useCanvasTransformSync(updateTransform, { | ||
| autoStart: false | ||
| }) | ||
|
|
||
| // Watch for selection changes | ||
| watch( | ||
| () => canvasStore.getCanvas().state.selectionChanged, | ||
| (changed) => { | ||
| if (changed) { | ||
| updateSelectionBounds() | ||
| canvasStore.getCanvas().state.selectionChanged = false | ||
|
|
||
| // Start transform sync if we have selection | ||
| if (visible.value) { | ||
| startSync() | ||
| } else { | ||
| stopSync() | ||
| } | ||
| } | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
|
|
||
| // Watch for dragging state | ||
| watch( | ||
| () => canvasStore.canvas?.state?.draggingItems, | ||
| (dragging) => { | ||
| if (dragging) { | ||
| // Hide during node dragging | ||
| style.value = { | ||
| ...style.value, | ||
| visibility: 'hidden' | ||
| } | ||
| } else if (visible.value) { | ||
| // Show after dragging ends | ||
| requestAnimationFrame(() => { | ||
| updateSelectionBounds() | ||
| }) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| return { | ||
| style, | ||
| visible, | ||
| updateSelectionBounds | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.