Skip to content

Commit

Permalink
widget-manager: Fix main-menu closing when hovering
Browse files Browse the repository at this point in the history
With previous implementation, while outside the 100x100 area, the menu closes, even if the user is hovering it.
  • Loading branch information
rafaellehmkuhl committed Nov 8, 2022
1 parent 8186656 commit b165320
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/views/WidgetsView.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<v-menu v-if="showMainMenuButton || activateMainMenuButton" location="bottom">
<v-menu v-if="showMainMenuButton" location="bottom">
<template #activator="{ props: menuProps }">
<v-btn
v-bind="menuProps"
class="edit-mode-btn"
icon="mdi-menu"
:disabled="!activateMainMenuButton"
:disabled="disableMainMenuButton"
/>
</template>
<v-card class="pa-2 ma-2">
<v-card ref="mainMenu" class="pa-2 ma-2">
<v-switch
:model-value="editingMode"
inset
Expand All @@ -17,7 +17,7 @@
@click="editingMode = !editingMode"
/>
<v-checkbox
v-model="showMainMenuButton"
v-model="alwaysShowMainMenuButton"
label="Always show menu button"
hide-details
/>
Expand Down Expand Up @@ -84,14 +84,13 @@
</template>

<script setup lang="ts">
import { useMouse } from '@vueuse/core'
import { useMouse, useMouseInElement } from '@vueuse/core'
import {
// type AsyncComponentLoader,
computed,
reactive,
// defineAsyncComponent,
ref,
watch,
} from 'vue'
import { useWidgetManagerStore } from '@/stores/widgetManager'
Expand All @@ -112,19 +111,26 @@ import VideoPlayer from '../components/widgets/VideoPlayer.vue'
const store = useWidgetManagerStore()
const mouse = reactive(useMouse())
const showMainMenuButton = ref(false)
const activateMainMenuButton = ref(false)
const alwaysShowMainMenuButton = ref(false)
const editingMode = ref(false)
const showGrid = ref(true)
const gridInterval = ref(0.01)
const mainMenu = ref()
const widgetsPresent = computed(() =>
store.currentProfile.layers.some((layer) => layer.widgets.length != 0)
)
watch(mouse, () => {
activateMainMenuButton.value =
(mouse.x < 100 && mouse.y < 100) || !widgetsPresent.value
const { isOutside: notHoveringMainMenu } = useMouseInElement(mainMenu)
const mouseNearMainButton = computed(() => mouse.x < 100 && mouse.y < 100)
const disableMainMenuButton = computed(() => !mouseNearMainButton.value)
const showMainMenuButton = computed(() => {
return (
alwaysShowMainMenuButton.value ||
mouseNearMainButton.value ||
!notHoveringMainMenu.value ||
!widgetsPresent.value
)
})
// TODO: Make this work
Expand Down

0 comments on commit b165320

Please sign in to comment.