If the scroll bar and the margin are generated programmatically, then
presumably the program which creates them knows their width, or can
calculate that?  If so, the :align-to value should take that into
consideration.

As I said, the problem is letting the window system do the truncation rather than in code. There's no way to tell Emacs to start truncating from the actual content rather than UI elements that Emacs thinks are content. Hence, the original ask. Correct and performant custom truncation that respects pixel width is much much harder than it should be in Emacs.