Scale box button brackets to the content height - #584
Open
LuciusChen wants to merge 2 commits into
Open
Conversation
Owner
|
This looks very promissing! let me first check this locally before merging it in |
LuciusChen
force-pushed
the
fix/scale-svg-button-brackets
branch
3 times, most recently
from
July 28, 2026 03:05
75bb8be to
485e65e
Compare
Content rendered with fonts taller than the default one (color emoji, CJK) or with embedded images makes the screen line taller than 1 char. This can happen inside a button or earlier on the same line, while bracket images remain exactly 1 char high, so reactions, UI and keyboard buttons look broken. Introduce the `content' value for the `:height' bracket property. Measure height and baseline from the real rendering of the current line prefix and button body with `buffer-text-pixel-size'. An anchor char in the default face preserves the max-ascent plus max-descent metrics used by redisplay. Recover the baseline by appending an `:ascent 100' probe of the measured line height. Use `ceiling' for the resulting percentage because image ascent is truncated during display. Keep the SVG viewport 1 char high and scale it proportionally to the displayed height. Compensate the outline width for that scale and align the mask hole with the body outline. Enable content sizing for `reaction', `telega-ui' (including comments and file actions), `iv' and `keyboard-*' styles. Emacs versions without `buffer-text-pixel-size' keep the previous fixed-height behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
LuciusChen
force-pushed
the
fix/scale-svg-button-brackets
branch
from
July 28, 2026 07:01
485e65e to
96fa46a
Compare
Contributor
Author
|
I've tested all the scenarios shown in the screenshots above, and they now work as expected. |
Contributor
Author
|
Added an explicit :background nil to SVG bracket images so their transparent area can follow cursor-face highlighting instead of retaining the passive background. The full test suite still passes (26/26). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Box button brackets are SVG images of exactly 1 char height. When the
button body or another glyph earlier on the same line renders taller than
one default-font line — color emoji glyphs (e.g. Apple Color Emoji has
noticeably larger ascent/descent than monospace fonts), CJK fonts, custom
emoji / avatar images — the screen line grows, but the brackets stay 1
char high. Reactions and inline keyboard buttons end up with content
sticking out above and below the button "pill". The same issue affects
ordinary UI buttons such as
Downloadwhen a taller media icon precedesthe button on its line.
Before
Approach
This PR introduces a
contentvalue for the:heightbracket property:With
:height content, bracket height and baseline are measured fromthe real rendering of the current line prefix and button body
(
telega-box-button--content-metrics):Line height is measured with
buffer-text-pixel-sizein a workbuffer. Measuring the actual redisplay result (instead of guessing via
per-character
font-at, which bypasses emoji compositions such asVS16/ZWJ sequences) makes emoji compositions, embedded images (custom
emoji, sender avatars) and
(raise ...)-displayed text all "justwork". An anchor char in the default face is appended, since screen
line metrics are
max(ascents) + max(descents)over all glyphs on theline.
Baseline position is recovered with a probe: appending an
:ascent 100space of the measured line height grows the line byexactly the line's descent, so
ascent = 2*H1 - H2. The resulting:ascentpercentage isceiling'ed — image ascent is truncated asfloor(percent * height / 100)on display, so rounding down herewould place the bracket 1px lower, with content peeking out above the
button.
Geometry. The SVG viewport stays 1 char high and is
proportionally scaled up to the displayed
:height, so bracket capskeep their shape, growing wider for taller content (Telegram-like pill
look). Two pixel-alignment details:
the outline is exactly
:outline-widthpixels on display;was inset by ~1.5x due to half-pixel offsets plus the hole's own
stroke).
Both make the bracket's visible background and outline pixel-aligned
with the button body, where the horizontal outline lines are drawn by
the
:boxoftelega-box-button--body-face.Since the left bracket is inserted before the body is known,
telega-ins--with-stylere-generates the left bracket image after thebody has been inserted and replaces its
displayproperty. Generatedimages are cached with the computed height/ascent as part of the cache
key.
:height contentis enabled for thereaction(and, via inheritance,reaction-chosen/reaction-paid),telega-ui(including commentsand file actions such as
Download),ivandkeyboard-*styles.After
Compatibility
buffer-text-pixel-size(< 29.1) metrics returnniland brackets fall back to the previous fixed 1 char height — no
behavior change.
:height content(e.g.default) areunaffected: for
height = 1all geometry reduces to the previousformulas.
ordinary labels look the same as before.
Testing
telega-box-button-content-metrics,telega-box-button-content-height-inserter,telega-box-button-bracket-metrics) cover the metrics math (includingthe
ceilingascent regression), same-line prefix preservation, leftbracket re-generation,
telega-uiinheritance and generated imagespecs. Full suite passes: 26/26.
10/14/16/20 + Apple Color Emoji + CJK font): bracket background
extents are pixel-identical to the button body, measured from actual
window captures.
🤖 Generated with Claude Code