-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpinner.mpp
More file actions
48 lines (41 loc) · 1.42 KB
/
Spinner.mpp
File metadata and controls
48 lines (41 loc) · 1.42 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
export module CppUtils.Terminal.Spinner;
import std;
import CppUtils.Terminal.Area;
import CppUtils.Container.Size;
import CppUtils.Chrono.Concept;
export import CppUtils.Terminal.FixedAreaBuffer;
export namespace CppUtils::Terminal
{
template<std::size_t Width, std::size_t Height, std::size_t NbFrames, Chrono::Duration Duration = std::chrono::milliseconds>
class Spinner final: public Widget
{
public:
using Frame = FixedAreaBuffer<Width, Height>;
using Frames = std::array<Frame, NbFrames>;
static constexpr auto size = Frame::size;
inline Spinner(const Frames& frames, const Duration& duration = std::chrono::milliseconds{50}):
m_frames{frames},
m_duration{duration}
{}
[[nodiscard]] inline auto getSize() const noexcept -> Container::Size2 final
{
return size;
}
inline auto draw(WritableAreaView& view) noexcept -> void
{
if (std::empty(m_frames))
return;
view.applyArea(m_frames[m_frame]);
if (++m_frame == std::size(m_frames))
m_frame = 0;
drawFinished();
requestUpdate(m_duration);
}
private:
std::size_t m_frame = 0;
const Frames& m_frames;
Duration m_duration;
};
template<std::size_t Width, std::size_t Height, std::size_t NbFrames, Chrono::Duration Duration = std::chrono::milliseconds>
Spinner(std::array<FixedAreaBuffer<Width, Height>, NbFrames>&& frames, const Duration& duration = std::chrono::milliseconds{50}) -> Spinner<Width, Height, NbFrames, Duration>;
}