struct mola::gui::LiveString
Overview
A string value that can be written from any thread and read (polled) from the GUI thread without data races.
Usage (writer side, any thread): liveStr.set(mrpt::format(“ICP quality: %.1f%%”, q));
Usage (GUI thread, nanogui backend): std::string tmp; if (liveStr.poll(tmp)) label->setCaption(tmp);
Usage (GUI thread, ImGui backend - called every frame): ImGui::TextUnformatted(liveStr.display.c_str()); liveStr.pollIntoDisplay(); // updates display if dirty
#include <GuiWidgetDescription.h> struct LiveString { // typedefs typedef std::shared_ptr<LiveString> Ptr; // fields std::string display; // construction LiveString(); LiveString(std::string initial); LiveString(const LiveString&); LiveString(LiveString&&); // methods uint64_t id() const; LiveString& operator = (const LiveString&); LiveString& operator = (LiveString&&); void set(std::string s); bool poll(std::string& out); void pollIntoDisplay(); };
Fields
std::string display
The current display value. Written only by the GUI thread (via pollIntoDisplay), so safe to read from the GUI thread without locking.
Methods
uint64_t id() const
Globally unique ID for this instance (stable for its lifetime).
void set(std::string s)
Write from any thread.
bool poll(std::string& out)
Call from the GUI thread. Copies pending value into out and clears the dirty flag. Returns true if the value changed.
void pollIntoDisplay()
Convenience variant for the ImGui backend: updates the public display member in-place. Call this each frame; then read display directly.