expansionLength static method
How many characters expandPercent adds to a value of baseLength:
percent of the value's own ceiling, and the ceiling depends on how
short it is.
A short string has proportionally the most room to grow — localisation
guidance is unanimous that a 6-character button label can triple where a
70-character sentence grows by a third — and a flat ×2 ceiling was
answering "at least 22" for an 11-character label whose real limit sits
far higher. So the top rung (percent: 100) pads a value up to +300% at
≤10 characters, +200% at ≤20, +150% at ≤30, +120% at ≤50 and +100%
beyond, and every rung below scales its key's own ceiling — the same ten
passes probe every key as far as it plausibly goes.
Implementation
static int expansionLength(int baseLength, int percent) {
var factor = switch (baseLength) {
<= 10 => 3.0,
<= 20 => 2.0,
<= 30 => 1.5,
<= 50 => 1.2,
_ => 1.0,
};
return (baseLength * percent * factor / 100).ceil();
}