How does MV know when to use "narrow text"?

I'm having a small problem with my game.

I have an "evidence browser" screen which, in practice, is a screen that just acts as a special viewer for key items. But I've noticed an issue/

If I open the screen, it looks like this:

1622287033463.png


However, if I scroll down to the bottom of the list, then scroll 1 element down (which, obviously, causes the list to all shift up 1 element), it looks like this:

1622287190502.png


As you can see, the items with longer names are correctly shortened to fit onscreen.

I've seen this before; MV seems to have some mechanism by which it uses "narrow text" in some contexts to try and make sure all text fits in menu windows, but in this case, presumably it's not working correctly.

Can someone explain to me by what mechanism this works? So I have some idea where to look in order to fix it?
Short answer: it depends how the window is coded to draw the text.

RMMV's core scripts ultimately pass all text rendering to the CanvasRenderingContext2D.fillText method (cf rpg_core.js). This method accepts an optional maxWidth argument: the output will be adjusted as needed to keep it at or below the specified width.

For game windows (e.g. selectable lists), text is drawn via the drawText method of Window_Base. However, the maxWidth value is often passed in further up the chain, e.g.
Spoiler: Window_Base > drawActorName (rpg_windows.js)
JavaScript:
Window_Base.prototype.drawActorName = function(actor, x, y, width) {
    width = width || 168;
    this.changeTextColor(this.hpColor(actor));
    this.drawText(actor.name(), x, y, width);
};

Original thread: https://forums.rpgmakerweb.com/threads/how-does-mv-know-when-to-use-narrow-text.136946/