Skip to content

Commit

Permalink
Make virtual keyboard text color dynamic based on background
Browse files Browse the repository at this point in the history
Use white text with dark backgrounds and black text with light background.

ref #661
  • Loading branch information
frostburn committed Apr 21, 2024
1 parent 435ceac commit 512fd47
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
57 changes: 55 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.21",
"sw-synth": "^0.1.0",
"temperaments": "^0.5.3",
"values.js": "^2.1.1",
"vue": "^3.3.4",
"vue-router": "^4.3.0",
"webmidi": "^3.1.8",
Expand Down
4 changes: 2 additions & 2 deletions src/components/VirtualKeyInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const props = defineProps<{
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
}
.black-key .key-info {
.dark .key-info {
color: white;
text-shadow: none;
}
.white-key .key-info {
.light .key-info {
color: black;
text-shadow: none;
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/VirtualKeyboardKey.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { LEFT_MOUSE_BTN } from '@/constants'
import { onMounted, onUnmounted, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import Values from 'values.js'
type NoteOff = () => void
type NoteOnCallback = () => NoteOff
Expand All @@ -14,6 +15,8 @@ const props = defineProps<{
const active = ref(false)
const light = computed(() => new Values(props.color).getBrightness() > 50)
const emit = defineEmits(['press', 'unpress'])
let noteOff: NoteOff | null = null
Expand Down Expand Up @@ -100,15 +103,15 @@ onUnmounted(() => {
<td
:data-key-number="index"
:style="'background-color:' + color"
:class="{ active, 'black-key': color === 'black', 'white-key': color === 'white' }"
:class="{ active, light, dark: !light }"
@touchstart="onTouchStart"
@touchend="onTouchEnd"
@touchcancel="onTouchEnd"
@mousedown="onMouseDown"
@mouseup="onMouseUp"
@mouseenter="onMouseEnter"
@mouseleave="onMouseLeave"
>
>
<slot></slot>
</td>
</template>
Expand Down

0 comments on commit 512fd47

Please sign in to comment.