Skip to content

Marquee

marquee · Containers · interactive

A strip whose contents slide past and come round again.

Import

cpp
#include "gbui/widgets/marquee.hpp"

Example

Nothing is downloaded until you press it.

cpp
bool marquee(Ui& ui, const Interaction& input, std::string_view id, MarqueeState& state, float delta, const std::function<void(Ui&)>& content, const MarqueeOptions& options = {});

Draws content twice, side by side, sliding. Twice is the whole trick. One copy leaves a hole behind it while it travels; a second, exactly a content's width behind, fills that hole — and because the offset wraps at that same width, the seam between them never arrives at a moment the reader could see it. Anything narrower than the strip would show the gap on its own, which is what gap is measured from rather than added to. delta is the frame's own, and zero stops it. That is the one interaction a ticker has: held still while the pointer is over it, a reader can read a name instead of chasing it. Stopping is the caller's to decide because only the caller knows what should stop it. The content is built twice per frame, so it should be cheap — a row of labels, not a table. It is laid out in one line: this is a strip, and a strip that wrapped would be a paragraph that moves. Returns true on the frame it came round, which is the one moment a caller may change the content without the reader seeing it happen: the strip is showing the beginning of a pass, so a different pass beginning there reads as the next lap rather than as a jump. Changing it at any other time slides everything already on screen sideways by whatever was added or removed.

API

MarqueeOptions

OptionTypeDefaultWhat it does
speedfloat42.0fPixels a second. Negative runs the other way, which is what a right-to -left reader expects of the same strip.
gapfloat0.0fBetween the end of one pass and the start of the next. Set it for content with no spacing of its own — a sentence, which would otherwise read as one long word repeated. Leave it at zero for content that already spaces itself, a row of chips or cards: this gap applies at the seam and nowhere else, so anything wider than what the items already put between them is a hole that comes round once a lap and is the one part of a marquee a reader will notice.
heightfloatkAutoThe strip's own height. Auto takes the content's.
growfloat1.0fTakes the space left in the row it is in, and does so by default. It has to be told. Both passes are out of the flow — that is how they slide — so the strip has no content to be measured from and would otherwise collapse to nothing and draw an empty band, which is exactly what it did.
paddingEdges
namestd::string_viewWhat the strip is showing — "Now playing", "Market". The content itself reaches a reader through the tree; this says what the band is.

Released under the LGPL-3.0-or-later licence.