Subject: bug#51995: 29.0.50; `string-pixel-width' depends on the current window width

From: Brahimi Saifullah <[email-masked]>
Date: Sat, 20 Nov 2021 18:36:46 -0300

>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.