Grid: highlight hints on hover

This commit is contained in:
2026-02-08 18:18:07 +01:00
parent 4b2d98fe05
commit ad4ea9617c
3 changed files with 33 additions and 6 deletions

View File

@@ -76,7 +76,7 @@ const handlePointerCancel = (e) => {
@pointerup="handlePointerUp" @pointerup="handlePointerUp"
@pointercancel="handlePointerCancel" @pointercancel="handlePointerCancel"
@pointerleave="handlePointerCancel" @pointerleave="handlePointerCancel"
@mouseenter="emit('enter-cell', props.r, props.c)" @mouseenter="emit('enter-cell', props.r, props.c, $event)"
@contextmenu.prevent @contextmenu.prevent
> >
<span v-if="props.state === 2" class="cross-mark">×</span> <span v-if="props.state === 2" class="cross-mark">×</span>

View File

@@ -12,6 +12,9 @@ const { startDrag, onMouseEnter, stopDrag } = useNonogram();
const cellSize = ref(30); const cellSize = ref(30);
const rowHintsRef = ref(null); const rowHintsRef = ref(null);
const activeRow = ref(null);
const activeCol = ref(null);
const isFinePointer = ref(false);
const getRowHintsWidth = () => { const getRowHintsWidth = () => {
const el = rowHintsRef.value?.$el; const el = rowHintsRef.value?.$el;
@@ -52,10 +55,24 @@ const handlePointerMove = (e) => {
} }
}; };
const handleCellEnter = (r, c) => {
onMouseEnter(r, c);
if (!isFinePointer.value) return;
activeRow.value = r;
activeCol.value = c;
};
const handleGridLeave = () => {
stopDrag();
activeRow.value = null;
activeCol.value = null;
};
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
computeCellSize(); computeCellSize();
}); });
isFinePointer.value = window.matchMedia('(pointer: fine)').matches;
window.addEventListener('resize', computeCellSize); window.addEventListener('resize', computeCellSize);
window.addEventListener('mouseup', handleGlobalMouseUp); window.addEventListener('mouseup', handleGlobalMouseUp);
window.addEventListener('pointerup', handleGlobalPointerUp); window.addEventListener('pointerup', handleGlobalPointerUp);
@@ -81,10 +98,10 @@ watch(() => store.size, async () => {
<div class="corner-spacer"></div> <div class="corner-spacer"></div>
<!-- Column Hints --> <!-- Column Hints -->
<Hints :hints="colHints" orientation="col" :size="store.size" /> <Hints :hints="colHints" orientation="col" :size="store.size" :activeIndex="activeCol" />
<!-- Row Hints --> <!-- Row Hints -->
<Hints ref="rowHintsRef" :hints="rowHints" orientation="row" :size="store.size" /> <Hints ref="rowHintsRef" :hints="rowHints" orientation="row" :size="store.size" :activeIndex="activeRow" />
<!-- Grid --> <!-- Grid -->
<div <div
@@ -94,7 +111,7 @@ watch(() => store.size, async () => {
gridTemplateRows: `repeat(${store.size}, var(--cell-size))` gridTemplateRows: `repeat(${store.size}, var(--cell-size))`
}" }"
@pointermove.prevent="handlePointerMove" @pointermove.prevent="handlePointerMove"
@mouseleave="stopDrag" @mouseleave="handleGridLeave"
> >
<template v-for="(row, r) in store.playerGrid" :key="r"> <template v-for="(row, r) in store.playerGrid" :key="r">
<Cell <Cell
@@ -108,7 +125,7 @@ watch(() => store.size, async () => {
'guide-bottom': (r + 1) % 5 === 0 && r !== store.size - 1 'guide-bottom': (r + 1) % 5 === 0 && r !== store.size - 1
}" }"
@start-drag="startDrag" @start-drag="startDrag"
@enter-cell="onMouseEnter" @enter-cell="handleCellEnter"
/> />
</template> </template>
</div> </div>

View File

@@ -12,6 +12,10 @@ defineProps({
size: { size: {
type: Number, type: Number,
required: true required: true
},
activeIndex: {
type: Number,
default: null
} }
}); });
</script> </script>
@@ -28,7 +32,7 @@ defineProps({
v-for="(group, index) in hints" v-for="(group, index) in hints"
:key="index" :key="index"
class="hint-group" class="hint-group"
:class="{ 'hint-alt': index % 2 !== 0 }" :class="{ 'hint-alt': index % 2 !== 0, 'is-active': index === activeIndex }"
> >
<span <span
v-for="(num, idx) in group" v-for="(num, idx) in group"
@@ -100,4 +104,10 @@ defineProps({
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
border-color: var(--accent-cyan); border-color: var(--accent-cyan);
} }
.hint-group.is-active {
background: rgba(79, 172, 254, 0.2);
border-color: rgba(79, 172, 254, 0.8);
box-shadow: 0 0 12px rgba(79, 172, 254, 0.35);
}
</style> </style>