TermOx
notify_light.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_NOTIFY_LIGHT_HPP
2 #define TERMOX_WIDGET_WIDGETS_NOTIFY_LIGHT_HPP
3 #include <chrono>
4 #include <memory>
5 
6 #include <termox/painter/color.hpp>
7 #include <termox/painter/glyph.hpp>
8 #include <termox/widget/widget.hpp>
9 
10 namespace ox {
11 
13 class Notify_light : public Widget {
14  public:
15  struct Display {
16  Color on;
17  Color off;
18  };
19 
20  using Duration_t = std::chrono::milliseconds;
21 
22  enum class Fade : bool { On, Off };
23 
24  struct Parameters {
25  Display display = {Color::Foreground, Color::Background};
26  Duration_t duration = default_duration;
27  Fade fade = Fade::On;
28  };
29 
30  static auto constexpr default_duration = Duration_t{450};
31 
32  public:
33  explicit Notify_light(Display display = Display{Color::Foreground,
34  Color::Background},
35  Duration_t duration = default_duration,
36  Fade fade = Fade::On);
37 
38  explicit Notify_light(Parameters p);
39 
40  public:
42  void emit();
43 
45  void set_display(Display d);
46 
48  [[nodiscard]] auto get_display() const -> Display;
49 
51  void set_duration(Duration_t d);
52 
54  [[nodiscard]] auto get_duration() const -> Duration_t;
55 
57  void set_fade(Fade f);
58 
60  [[nodiscard]] auto get_fade() const -> Fade;
61 
62  protected:
63  auto timer_event() -> bool override;
64 
65  private:
66  Display display_;
67  Duration_t duration_;
68  Fade fade_;
69 
70  Glyph on_block_;
71  Glyph off_block_;
72 
73  static auto constexpr initial_block = U'█';
74  static auto constexpr block_count = 4;
75 };
76 
78 [[nodiscard]] auto notify_light(
79  Notify_light::Display display = Notify_light::Display{Color::Foreground,
80  Color::Background},
81  Notify_light::Duration_t duration = Notify_light::default_duration,
82  Notify_light::Fade fade = Notify_light::Fade::On)
83  -> std::unique_ptr<Notify_light>;
84 
86 [[nodiscard]] auto notify_light(Notify_light::Parameters p)
87  -> std::unique_ptr<Notify_light>;
88 
89 } // namespace ox
90 #endif // TERMOX_WIDGET_WIDGETS_NOTIFY_LIGHT_HPP
Color numbers [0 - 180] are valid.
Definition: color.hpp:16
A 'light' that can be emitted for a given duration to visually notify.
Definition: notify_light.hpp:13
auto get_fade() const -> Fade
Return the currently set Fade type.
Definition: notify_light.cpp:50
auto get_display() const -> Display
Return the on and off Colors currently used.
Definition: notify_light.cpp:42
auto timer_event() -> bool override
Handles Timer_event objects.
Definition: notify_light.cpp:52
void set_fade(Fade f)
Set the light to Fade or not.
Definition: notify_light.cpp:48
void emit()
Start emitting the on color for the set duration.
Definition: notify_light.cpp:26
auto get_duration() const -> Duration_t
Return the currently set duration.
Definition: notify_light.cpp:46
void set_display(Display d)
Set the on and off Colors of the light.
Definition: notify_light.cpp:33
void set_duration(Duration_t d)
Set the duration from the time emit is called to when the light is off.
Definition: notify_light.cpp:44
Definition: widget.hpp:31
Definition: notify_light.hpp:15
Definition: notify_light.hpp:24