Skip to content

MouseControl Component

The <MouseControl /> component is a tool to add complex mouse control to any custom component. It is used internally by several of the other components in this package.

Basic Usage

The main output of the <MouseControl /> is a change event, with a delta value representing the change in input. This change is derived from mouse movement, where positive X and negative Y (right and up) movement contributes to an increased delta.

vue
<script setup>
import { ref } from 'vue'
import { MouseControl } from 'acousti-kit'

const delta = ref(0)
</script>

<template>
  <MouseControl
    @change="delta = $event"
    @start="console.log('Started change')"
    @end="console.log('Finished change')"
  >
    <div>
      {{ delta }}
    </div>
  </MouseControl>
</template>

Example

Props

The following props are available for the <Knob /> component:

PropTypeDefaultOptionalNote
normalStrengthnumber0YesConfigures the normal strength of mouse movement effect on value
fineStrengthnumber0YesConfigures the fine adjustment strength of mouse movement effect on value
fineKeystringAltYesSets the key used for enabling fine adjustment
captureMousebooleantrueYesEnables mouse capture when adjusting
behaviour'Flat' | 'Velocity''Flat'YesConfigures the mode of value adjustments
frictionnumber0.5YesSets the friction used when using the Velocity mode

Events

The following events are available for the <Knob /> component:

PropTypeNote
@changenumberEmitted on any change in mouse input
@startvoidEmitted when the user starts adjusting
@endvoidEmitted when the user ends adjusting

Advanced Usage

The component comes with a couple of features that are all adjustable:

Mouse capture

Optionally, you can make the mouse control capture the mouse pointer to prevent it leaving the position while adjusting. This can be turned on using the capture-mouse prop:

vue
<template>
  <MouseControl :capture-mouse="true">
    <div />
  </MouseControl>
</template>

Example:

Fine Adjustment

To enable finer input control, the control will by default scale down the intensity of change when the Alt key is held down. The current state is exposed through slot scoped props, as fine. Both the key and the intensity can be configured:

vue
<template>
  <MouseControl
    v-slot="{ fine }"
    :normal-strength="10"
    :fine-strength="0.1"
    fine-key="Control"
  >
    <div :class="[fine ? 'fine' : '']" />
  </MouseControl>
</template>

Example:

Mouse mode

The control supports two different kinds of mouse adjustment modes:

  1. Flat: This is the default, and changes the value with as much as the mouse moves
  2. Velocity: An alternative move where instead the velocity of the mouse is being considered

This can be configured through the mode prop:

vue
<template>
  <MouseControl
    mode="Velocity"
  >
    <div />
  </MouseControl>
</template>

Example: