Skip to content

Commit

Permalink
Snap CB position to pixel boundary (#8095)
Browse files Browse the repository at this point in the history
* Snap CB position to pixel boundary

* Apply review comments
  • Loading branch information
vitvakatu authored Oct 18, 2023
1 parent 9e9860d commit cec115d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/gui2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"hash-sum": "^2.0.0",
"isomorphic-ws": "^5.0.0",
"lib0": "^0.2.85",
"lorem-ipsum": "^2.0.8",
"magic-string": "^0.30.3",
"murmurhash": "^2.0.1",
"pinia": "^2.1.6",
Expand Down
15 changes: 10 additions & 5 deletions app/gui2/src/components/ComponentBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useApproach } from '@/util/animation'
import { useResizeObserver } from '@/util/events'
import type { useNavigator } from '@/util/navigator'
import { Vec2 } from '@/util/vec2'
import { LoremIpsum } from 'lorem-ipsum'
import { computed, nextTick, onMounted, ref, watch } from 'vue'
const ITEM_SIZE = 32
Expand All @@ -34,10 +35,10 @@ onMounted(() => {
const transform = computed(() => {
const nav = props.navigator
const pos = props.position
return `${nav.transform} translate(${pos.x}px, ${pos.y}px) scale(${
1 / nav.scale
}) translateY(-100%)`
const translate = nav.translate
const position = translate.add(props.position).scale(nav.scale)
return `translate(${position.x}px, ${position.y}px) translateY(-100%)`
})
// === Input and Filtering ===
Expand Down Expand Up @@ -223,6 +224,7 @@ function updateScroll() {
// === Documentation Panel ===
const docsVisible = ref(true)
const docs = new LoremIpsum().generateParagraphs(6)
// === Key Events Handler ===
Expand Down Expand Up @@ -308,7 +310,9 @@ function handleKeydown(e: KeyboardEvent) {
</div>
</div>
</div>
<div class="panel docs" :class="{ hidden: !docsVisible }">DOCS</div>
<div class="panel docs scrollable" :class="{ hidden: !docsVisible }" @wheel.stop.passive>
{{ docs }}
</div>
</div>
<div class="CBInput">
<input ref="inputField" v-model="input.code.value" @keyup="readInputFieldSelection" />
Expand Down Expand Up @@ -357,6 +361,7 @@ function handleKeydown(e: KeyboardEvent) {
width: 406px;
clip-path: inset(0 0 0 0 round 20px);
transition: clip-path 0.2s;
overflow-y: auto;
}
.docs.hidden {
clip-path: inset(0 100% 0 0 round 20px);
Expand Down
13 changes: 5 additions & 8 deletions app/gui2/src/util/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,21 @@ export function useNavigator(viewportNode: Ref<Element | undefined>) {
return `${v.pos.x} ${v.pos.y} ${v.size.x} ${v.size.y}`
})

const transformValue = computed(() => {
const translate = computed<Vec2>(() => {
const nodeSize = size.value
const { x, y } = center.value
const s = scale.value
const w = nodeSize.x / s
const h = nodeSize.y / s
return { x: -x + w / 2, y: -y + h / 2 }
return new Vec2(-x + w / 2, -y + h / 2)
})

const transform = computed(
() =>
`scale(${scale.value}) translate(${transformValue.value.x}px, ${transformValue.value.y}px)`,
() => `scale(${scale.value}) translate(${translate.value.x}px, ${translate.value.y}px)`,
)

const prescaledTransform = computed(
() =>
`translate(${transformValue.value.x * scale.value}px, ${
transformValue.value.y * scale.value
}px)`,
() => `translate(${translate.value.x * scale.value}px, ${translate.value.y * scale.value}px)`,
)

useEvent(
Expand Down Expand Up @@ -126,6 +122,7 @@ export function useNavigator(viewportNode: Ref<Element | undefined>) {
}
},
},
translate,
scale,
viewBox,
transform,
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cec115d

Please sign in to comment.