Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_dynamic_text_label.hpp
1#pragma once
2
3#include "structure/system/time/spk_timer.hpp"
4#include "structure/widget/spk_text_label.hpp"
5
6#include <functional>
7#include <string>
8
9namespace spk
10{
22 {
23 public:
27 using TextProducer = std::function<std::wstring()>;
31 static inline const spk::Duration DefaultDuration = 1000_ms;
32
33 private:
34 TextProducer _textProducer;
35 spk::Timer _refreshTimer;
36 bool _needsImmediateRefresh = true;
37
38 void _refreshText();
39 void _restartTimer();
40
41 protected:
46 void _onUpdateEvent(spk::UpdateEvent &p_event) override;
47
48 public:
55 const std::wstring &p_name,
56 spk::Widget *p_parent);
57
62 void setTextProducer(const TextProducer &p_textProducer);
67 void setRefreshDuration(const spk::Duration &p_refreshDuration);
68
72 void refresh();
73 };
74}
Strongly-typed time span with cached conversions between ns/ms/s.
Definition spk_duration.hpp:15
void setTextProducer(const TextProducer &p_textProducer)
Sets the text producer callback.
Definition spk_dynamic_text_label.cpp:53
void refresh()
Immediately refreshes the label text.
Definition spk_dynamic_text_label.cpp:70
std::function< std::wstring()> TextProducer
Function type used to generate label text.
Definition spk_dynamic_text_label.hpp:27
void setRefreshDuration(const spk::Duration &p_refreshDuration)
Sets the refresh duration.
Definition spk_dynamic_text_label.cpp:64
void _onUpdateEvent(spk::UpdateEvent &p_event) override
Updates the label when the refresh timer ticks.
Definition spk_dynamic_text_label.cpp:24
static const spk::Duration DefaultDuration
Default refresh duration.
Definition spk_dynamic_text_label.hpp:31
DynamicTextLabel(const std::wstring &p_name, spk::Widget *p_parent)
Builds a dynamic text label.
Definition spk_dynamic_text_label.cpp:44
Widget that renders a text region over a nine-slice background.
Definition spk_text_label.hpp:20
Countdown helper tracking elapsed ratio and timeout state.
Definition spk_timer.hpp:24
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52
Carries per-frame update timing and input state snapshot.
Definition spk_update_event.hpp:15