From f4f36655c3dd07cf53e79148e803273c62de42d4 Mon Sep 17 00:00:00 2001 From: Yan-Fa Li Date: Thu, 30 Apr 2020 09:35:28 -0700 Subject: [PATCH] Alternative approach to font-sizing (#726) * Alternative approach to font-sizing This approach uses CSS Custom Properties. I recently discovered you can use this dynamically by injecting them as styles in the parent div overriding any defaults. - use a newer css technology to avoid adding a style per key - see https://developer.mozilla.org/en-US/docs/Web/CSS/--* Apply styles to all keymaps * change default keySize to 0.85 (#12) Thank you! Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> --- src/components/BaseKey.vue | 14 ++++++-------- src/components/BaseKeymap.vue | 16 ++++++++++++++++ src/components/PrintKeymap.vue | 9 +-------- src/components/VisualKeymap.vue | 7 ------- src/components/VisualTesterKeymap.vue | 7 ------- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/components/BaseKey.vue b/src/components/BaseKey.vue index 06b1f1b52f08..d5c8114b4ebd 100644 --- a/src/components/BaseKey.vue +++ b/src/components/BaseKey.vue @@ -109,6 +109,9 @@ export default { if (this.inSwap) { classes.push('swapme'); } + if (this.meta && this.meta.name.length >= 2) { + classes.push('smaller'); + } const { KEY_WIDTH, KEY_HEIGHT } = this.config; if (!isUndefined(this.meta) && !this.printable) { if (this.colorwayOverride && this.colorwayOverride[this.meta.code]) { @@ -150,13 +153,7 @@ export default { if (this.x > 0) { styles.push(`left: ${this.x}px;`); } - if (this.meta && this.meta.name.length >= 2) { - let keySize = 0.61; - if (this.config.SCALE < 1) { - keySize *= (1 + this.config.SCALE) / 2; - } - styles.push(`font-size: ${keySize}rem;`); - } + return styles.join(''); } }, @@ -262,11 +259,12 @@ export default { transform: scale(0.8); } .key.smaller { - font-size: 0.61rem; + font-size: var(--default-smaller-key-font-size); } .key { border-radius: 6px; font-family: 'Montserrat', sans-serif; + font-size: var(--default-key-font-size); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; line-height: 120%; diff --git a/src/components/BaseKeymap.vue b/src/components/BaseKeymap.vue index 64547d83ce45..ff5fd3bf5171 100644 --- a/src/components/BaseKeymap.vue +++ b/src/components/BaseKeymap.vue @@ -1,6 +1,22 @@