-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWidget.mpp
More file actions
57 lines (47 loc) · 1.44 KB
/
Copy pathWidget.mpp
File metadata and controls
57 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export module CppUtils.Terminal.Area:Widget;
import std;
import :WidgetManager;
import :WritableAreaView;
import CppUtils.Chrono.Concept;
import CppUtils.Thread.Scheduler;
export namespace CppUtils::Terminal
{
class Widget
{
public:
virtual ~Widget() = default;
[[nodiscard]] virtual auto getSize() const noexcept -> Container::Size2 = 0;
virtual auto draw(WritableAreaView& view) noexcept -> void = 0;
inline auto drawFinished() noexcept -> void
{
m_needUpdate = false;
}
virtual inline auto setWidgetManager(WidgetManager& widgetManager) noexcept -> void
{
m_widgetManagerRef = widgetManager;
}
[[nodiscard]] inline auto getWidgetManager() -> WidgetManager&
{
return m_widgetManagerRef.value().get();
}
[[nodiscard]] inline auto hasWidgetManager() const noexcept -> bool
{
return m_widgetManagerRef.has_value();
}
inline auto requestUpdate(Chrono::Duration auto delay = std::chrono::milliseconds{10}) -> void
{
requestUpdateImpl(std::chrono::duration_cast<Thread::Scheduler::Clock::duration>(delay));
}
private:
inline auto requestUpdateImpl(Thread::Scheduler::Clock::duration delay) -> void
{
getWidgetManager().scheduler.schedule([this]() -> void {
m_needUpdate = true;
getWidgetManager().eventDispatcher.emit<"RequestUpdate">();
}, delay);
}
private:
std::atomic_bool m_needUpdate = true;
std::optional<std::reference_wrapper<WidgetManager>> m_widgetManagerRef = std::nullopt;
};
}