GNU bug report logs -
#51995
29.0.50; `string-pixel-width' depends on the current window width
Previous Next
Reported by: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
Date: Sat, 20 Nov 2021 05:05:02 UTC
Severity: normal
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 51995 <at> debbugs.gnu.org (full text, mbox):
>What is the actual real-life situation where
>this is needed?
Mainly when a window with delicated alignment is resized.
Indeed, in most situations it likely won't be an issue,
but I can think of times when it most definitely will:
For example, in the package I'm working on,
I want certain text to always be centered,
even if the user resizes the window.
(By centered I mean having the same amount of space on both sides).
This is a mockup of the code I use:
(let* ((string "Hello World, Hello World, Hello world")
(width (string-pixel-width string)))
(insert
(propertize " "
'display
`(space :align-to (- center (,(/ width 2)))))
string))
If you evaluate this code in a window that is bigger or equal
to the size of the string, it will be properly aligned even if
you resize it later. But if you evaluate it in a small window,
it will be grossly misaligned when you increase the window size.
This bug report was last modified 3 years and 178 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.