hold the header's width against a changing status caption

The panel is sized to its card, so anything that changes the card's width drags
the panel with it. The status caption changes as a building works -- "producing"
is shorter than "missing input", which is shorter than "output full" -- and the
panel twitched every time it did. On a Smelter it also changed height, because a
narrower card wraps its item chips differently.

The pill now reserves room for the widest caption it can ever show, so the
header keeps one width whatever the state is. The captions were spelled out in
the switch that chose them, which left no way to ask for the set; they come from
one function now, and the set is what the reservation is built from.

Ship cards do the same with the behaviour names (REQ-UI-SHIP-BEHAVIOR), which
change just as often while a ship fights.

Miner card, sampled every tick for 900 ticks across two different-length
captions: one distinct width, one distinct height. The reservation is what does
it -- the same run without it sits at 138px, with it at 155px, the width of the
longest caption.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K
This commit is contained in:
2026-08-07 22:07:49 +02:00
parent 7d0f3e6daf
commit a6152b9998
7 changed files with 105 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
#include <QColor>
#include <QString>
#include <QStringList>
#include <QWidget>
class QLabel;
@@ -23,7 +24,16 @@ public:
void setStatus(const QColor& dotColor, const QColor& outlineColor,
const QString& caption);
// Reserves room for the widest of the captions this pill can show, so the header --
// and with it the panel, which is sized to its content (REQ-UI-SELECTION-PANEL) --
// keeps its width as the caption changes. Without it the whole panel jumps every
// time a building's status does, and a card whose chips wrap changes height with it.
void reserveFor(const QStringList& captions);
private:
QLabel* m_dotLabel;
QLabel* m_captionLabel;
// What the width is currently reserved for, so re-reserving the same set on every
// refresh costs nothing.
QStringList m_reservedFor;
};