abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2025-05-29 23:41:21 +0200
committerJules Aguillon2025-05-30 20:07:26 +0200
commit9ab099175d8b0548eeeb77cc963dd1c13b9cbaf7 (patch)
treec4ac259ed8d571e6c428ac67932f999951458ca0 /srcs
parent0445c310ad231bb468126a9f94152e41e6bac9e8 (diff)
downloadunexpected-keyboard-9ab099175d8b0548eeeb77cc963dd1c13b9cbaf7.tar.gz
unexpected-keyboard-9ab099175d8b0548eeeb77cc963dd1c13b9cbaf7.zip
Fix label size when the keyboard is unusually high
The label size is computed relatively to the width of the keyboard when the height is larger than 3/2 of the width. This ensures that the labels have a reasonable size when the keyboard height increases.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 0e1b258..684e42a 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -42,6 +42,8 @@ public class Keyboard2View extends View
private Config _config;
private float _keyWidth;
+ private float _mainLabelSize;
+ private float _subLabelSize;
private float _marginRight;
private float _marginLeft;
private float _marginBottom;
@@ -308,6 +310,16 @@ public class Keyboard2View extends View
_marginBottom = _config.margin_bottom + insets_bottom;
_keyWidth = (width - _marginLeft - _marginRight) / _keyboard.keysWidth;
_tc = new Theme.Computed(_theme, _config, _keyWidth);
+ // Compute the size of labels based on the width or the height of keys. The
+ // margin around keys is taken into account. Keys normal aspect ratio is
+ // assumed to be 3/2. It's generally more, the width computation is useful
+ // when the keyboard is unusually high.
+ float labelBaseSize = Math.min(
+ _config.keyHeight - _tc.vertical_margin,
+ _keyWidth * 3/2 - _tc.horizontal_margin
+ ) * _config.characterSize;
+ _mainLabelSize = labelBaseSize * _config.labelTextSize;
+ _subLabelSize = labelBaseSize * _config.sublabelTextSize;
int height =
(int)(_config.keyHeight * _keyboard.keysHeight
+ _config.marginTop + _marginBottom);
@@ -440,7 +452,7 @@ public class Keyboard2View extends View
kv = modifyKey(kv, _mods);
if (kv == null)
return;
- float textSize = scaleTextSize(kv, _config.labelTextSize, keyH);
+ float textSize = scaleTextSize(kv, true);
Paint p = tc.label_paint(kv.hasFlagsAny(KeyValue.FLAG_KEY_FONT), labelColor(kv, isKeyDown, false), textSize);
canvas.drawText(kv.getString(), x, (keyH - p.ascent() - p.descent()) / 2f + y, p);
}
@@ -454,7 +466,7 @@ public class Keyboard2View extends View
kv = modifyKey(kv, _mods);
if (kv == null)
return;
- float textSize = scaleTextSize(kv, _config.sublabelTextSize, keyH);
+ float textSize = scaleTextSize(kv, false);
Paint p = tc.sublabel_paint(kv.hasFlagsAny(KeyValue.FLAG_KEY_FONT), labelColor(kv, isKeyDown, true), textSize, a);
float subPadding = _config.keyPadding;
if (v == Vertical.CENTER)
@@ -479,14 +491,15 @@ public class Keyboard2View extends View
if (k.indication == null || k.indication.equals(""))
return;
Paint p = tc.indication_paint;
- p.setTextSize(keyH * _config.sublabelTextSize * _config.characterSize);
+ p.setTextSize(_subLabelSize);
canvas.drawText(k.indication, 0, k.indication.length(),
x + keyW / 2f, (keyH - p.ascent() - p.descent()) * 4/5 + y, p);
}
- private float scaleTextSize(KeyValue k, float rel_size, float keyH)
+ private float scaleTextSize(KeyValue k, boolean main_label)
{
float smaller_font = k.hasFlagsAny(KeyValue.FLAG_SMALLER_FONT) ? 0.75f : 1.f;
- return keyH * rel_size * smaller_font * _config.characterSize;
+ float label_size = main_label ? _mainLabelSize : _subLabelSize;
+ return label_size * smaller_font;
}
}