"""Small shared helpers used across FarmHUD's widgets.""" from __future__ import annotations from PySide6.QtWidgets import QWidget def style_role(widget: QWidget, role: str) -> QWidget: widget.setProperty("role", role) return widget def clear_layout(layout) -> None: """Empties a layout so it can be rebuilt on the next poll tick. Removing a widget from a layout with takeAt() does NOT hide it - it keeps painting at its last geometry until deleteLater()'s deferred deletion actually runs on a later event-loop pass. Every dynamic list here (storage, missions, players, ...) gets rebuilt on every ~500ms poll tick, so that lag would show up as visible flicker/ghosting. Hiding immediately (synchronous, cheap) avoids that; deleteLater() still runs afterwards to actually free it. """ while layout.count(): item = layout.takeAt(0) w = item.widget() if w is not None: w.hide() w.deleteLater()