Skip to content
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

Add compass north-up configuration #439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/WidgetHugger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ const optionsBtnTopStyle = computed(() => `${48 - constrain(widget.value.positio
color: white;
filter: drop-shadow(0.5px 0.5px 0.5px black);
display: v-bind('mouseOverWidgetStyle');
cursor: pointer;
}

.resize-handle {
Expand Down
63 changes: 59 additions & 4 deletions src/components/widgets/Compass.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
<template>
<div class="compass">
<img class="compass-ticks" src="@/assets/nautic-compass.svg" draggable="false" />
<img class="boat" src="@/assets/boat.svg" draggable="false" />
<img
:class="{ rotated: widget.options.headingStyle === HeadingStyle.HEAD_UP }"
class="compass-ticks"
src="@/assets/nautic-compass.svg"
draggable="false"
/>
<img
:class="{ rotated: widget.options.headingStyle === HeadingStyle.NORTH_UP }"
class="boat"
src="@/assets/boat.svg"
draggable="false"
/>
</div>
<Dialog v-model:show="showConfigurationMenu" class="w-72">
<div class="w-full h-full">
<div class="flex flex-col items-center justify-around">
<div class="flex items-center justify-between w-full my-1">
<span class="mr-1 text-slate-100">Heading style</span>
<div class="w-40"><Dropdown v-model="widget.options.headingStyle" :options="headingOptions" /></div>
</div>
</div>
</div>
</Dialog>
<span class="options-btn mdi mdi-dots-vertical" @click="showConfigurationMenu = !showConfigurationMenu" />
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { computed, onBeforeMount, ref, toRefs } from 'vue'

import Dialog from '@/components/Dialog.vue'
import Dropdown from '@/components/Dropdown.vue'
import { useMainVehicleStore } from '@/stores/mainVehicle'
import type { Widget } from '@/types/widgets'

const store = useMainVehicleStore()

const angleStyle = computed(() => `${store.attitude.yaw ?? 0}rad`)

/**
* Possible compass configurations.
* North-up keeps the cardinal points fixed, while the vehicle rotates.
* Head-up keeps the vehicle pointing up, while the cardinal points rotate.
*/
enum HeadingStyle {
NORTH_UP = 'North Up',
HEAD_UP = 'Head Up',
}
const headingOptions = Object.values(HeadingStyle)

const showConfigurationMenu = ref(false)
const props = defineProps<{
/**
* Widget reference
*/
widget: Widget
}>()
const widget = toRefs(props).widget

onBeforeMount(() => {
// Set initial widget options if they don't exist
if (Object.keys(widget.value.options).length === 0) {
widget.value.options = {
headingStyle: headingOptions[0],
}
}
})
</script>

<style scoped>
Expand All @@ -21,7 +74,6 @@ const angleStyle = computed(() => `${store.attitude.yaw ?? 0}rad`)
}
.compass-ticks {
transition: -webkit-transform 0.2s;
transform: rotate(v-bind('angleStyle'));
user-select: none;
height: 100%;
width: 100%;
Expand All @@ -37,4 +89,7 @@ const angleStyle = computed(() => `${store.attitude.yaw ?? 0}rad`)
user-select: none;
height: 55%;
}
.rotated {
transform: rotate(v-bind('angleStyle'));
}
</style>