Skip to content

Commit f42f0d3

Browse files
authored
Merge pull request #226 from Geode-solutions/fix_hybrid_rendering_view
fix(HybridRenderingView): Edit the component to make it more reusable
2 parents 0ce28d3 + 2a607d2 commit f42f0d3

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

components/HybridRenderingView.vue

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,67 @@
11
<template>
22
<ClientOnly>
3-
<div style="position: relative; width: 100%; height: calc(100vh - 75px)">
3+
<div class="fill-height" style="position: relative">
44
<VeaseViewToolbar />
55
<slot name="ui"></slot>
66
<v-col
77
ref="viewer"
8-
style="
9-
overflow: hidden;
10-
position: relative;
11-
z-index: 0;
12-
height: 100%;
13-
width: 100%;
14-
"
15-
class="pa-0"
8+
style="overflow: hidden; position: relative; z-index: 0"
9+
:style="{ height: viewerHeight }"
1610
@click="get_x_y"
17-
@keydown.esc="viewer_store.toggle_picking_mode(false)"
11+
@keydown.esc="viewerStore.toggle_picking_mode(false)"
1812
/>
1913
</div>
2014
</ClientOnly>
2115
</template>
2216

2317
<script setup>
18+
const props = defineProps({
19+
height: {
20+
type: String,
21+
default: "100%",
22+
},
23+
})
24+
2425
const container = useTemplateRef("viewer")
2526
const hybridViewerStore = useHybridViewerStore()
26-
27+
const viewerStore = useViewerStore()
2728
const { windowWidth, windowHeight } = useWindowSize()
2829
const { width, height } = useElementSize(container)
2930
30-
watch([windowWidth, windowHeight, height, width], () => {
31+
const viewerHeight = computed(() => props.height)
32+
33+
const debouncedResize = debounce(() => {
3134
hybridViewerStore.resize(width.value, height.value)
35+
}, 100)
36+
37+
watch([windowWidth, windowHeight, width, height], () => {
38+
debouncedResize()
3239
})
3340
3441
onMounted(async () => {
3542
if (import.meta.client) {
3643
await hybridViewerStore.initHybridViewer()
3744
await nextTick()
3845
hybridViewerStore.setContainer(container)
46+
debouncedResize()
3947
}
4048
})
49+
50+
function debounce(func, wait) {
51+
let timeout
52+
return function executedFunction(...args) {
53+
const later = () => {
54+
clearTimeout(timeout)
55+
func(...args)
56+
}
57+
clearTimeout(timeout)
58+
timeout = setTimeout(later, wait)
59+
}
60+
}
61+
62+
function get_x_y(event) {
63+
emit("click", event)
64+
}
65+
66+
defineEmits(["click"])
4167
</script>

0 commit comments

Comments
 (0)