[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functi
From: |
Eli Zaretskii |
Subject: |
Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C |
Date: |
Thu, 24 Oct 2024 12:55:03 +0300 |
> From: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
> Date: Wed, 23 Oct 2024 21:03:55 +0100
> Cc: emacs-devel@gnu.org
>
> Each completion in a list of completion candidates is a triple of (candidate
> string, prefix, annotation), all in
> varying widths. Aligning these 3 columns requires calculating paddings. Since
> there are paddings, the
> padding between the candidate string and the annotation can also be
> arbitrarily large. Naive truncation that
> truncates the entire concatenated line against the width of the pop up box,
> which is actually the window width
> in a child frame, may leave some arbitrarily long empty space in the end. In
> addition, naive truncation does
> not replace extra characters in the relevant columns with ellipses to
> indicate truncation happened. Please look
> at the link in my first email for further details.
>
> So the issue is not "pixel-wise truncation", the issue is to take
> variable-width display elements into account when truncating, is that
> right?
>
> To be precise, by " truncate strings correctly and preferably in pixel
> precision", I mean truncation that respects
> pixel width constraints (and grapheme clusters, as clarified by you).
> Truncating variable-width display
> elements on GUIs necessitate the ability to calculate the widths of the
> individual elements, I call this the
> hypothetical `glyph-pixel-width`. Whether it is exposed to Elisp is less
> important to a hypothetical
> `truncate-string-to-pixel-width` for my use case.
OK, thanks.
So let me see if I understand the issue. You want to create in a
child frame a display such as below:
<icon1><candidate1> <Type1>
<icon2><longer-name-candidate> <AnotherType>
...
And you want to do it in a way that all the "Type"s are aligned to the
right (i.e. end at the right edge of the frame), no matter what is
shown in the <icon>s and in the <candidate>s, which could be of
different width and could include characters of different fonts and
even images/emoji. Is that correct, or is there something else?
If the above is what you want, and since the popup is actually a
frame, my first suggestion would be to use :align-to display property
on the whitespace between the <candidate>s and the <Type>s. Did you
try that?
The advantage of :align-to is that you don't have to measure the
pixel-width of the candidate names, only the pixel-width of each
<Type> string (to correctly set up the offset from the right edge of
the text area) -- the rest will be done by the display engine. And
the display engine always does everything in pixel resolution.
- Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/23
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/23
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/23
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/23
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/23
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C,
Eli Zaretskii <=
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/24
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/25
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Jimmy Yuen Ho Wong, 2024/10/25
- Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C, Eli Zaretskii, 2024/10/25