1 #ifndef TERMOX_WIDGET_WIDGETS_BANNER_HPP
2 #define TERMOX_WIDGET_WIDGETS_BANNER_HPP
10 #include <signals_light/signal.hpp>
12 #include <termox/painter/glyph_string.hpp>
13 #include <termox/painter/painter.hpp>
14 #include <termox/widget/pipe.hpp>
15 #include <termox/widget/widget.hpp>
28 using Iter_t = std::vector<Index_and_position>::const_iterator;
34 [[nodiscard]]
auto begin()
const -> Iter_t;
36 [[nodiscard]]
auto end()
const -> Iter_t;
44 template <
typename Animator>
47 using Duration_t = std::chrono::milliseconds;
51 Duration_t interval = Duration_t{50};
52 Animator animator = Animator{};
57 Duration_t interval = std::chrono::milliseconds{50},
58 Animator animator = Animator{})
59 : text_{text}, interval_{interval}, animator_{animator}
61 *
this | pipe::fixed_height(1);
62 animator_.start.connect([
this] { this->start(); });
63 animator_.stop.connect([
this] { this->stop(); });
66 explicit Banner(Parameters p)
67 : Banner{std::move(p.text), std::move(p.interval),
68 std::move(p.animator)}
72 void set_text(Glyph_string text)
75 text_ = std::move(text);
77 animator_.set_text_length(text_.
size());
81 [[nodiscard]]
auto text() const noexcept -> Glyph_string const&
86 void set_interval(Duration_t interval)
95 [[nodiscard]]
auto interval() const noexcept -> Duration_t
100 [[nodiscard]]
auto animator() const noexcept -> Animator const&
105 [[nodiscard]]
auto animator() noexcept -> Animator& {
return animator_; }
111 for (
auto const& x : *range_)
112 p.put(text_[x.index], {x.position, 0});
115 p.put(text_, {0, 0});
121 range_ = animator_();
128 animator_.set_max_length(new_size.width);
134 Duration_t interval_;
136 std::optional<IP_range> range_;
141 if (text_.
size() == 0)
154 template <
typename Animator>
155 [[nodiscard]]
auto banner(Glyph_string text = U
"",
156 typename Banner<Animator>::Duration_t interval =
157 std::chrono::milliseconds{50},
158 Animator animator = Animator{})
159 -> std::unique_ptr<Banner<Animator>>
161 return std::make_unique<Banner<Animator>>(std::move(text), interval,
162 std::move(animator));
166 template <
typename Animator>
167 [[nodiscard]]
auto banner(
typename Banner<Animator>::Parameters p)
168 -> std::unique_ptr<Banner<Animator>>
170 return std::make_unique<Banner<Animator>>(std::move(p));
175 namespace ox::animator {
179 sl::Signal<void()> start;
180 sl::Signal<void()> stop;
186 void set_max_length(std::size_t x);
188 void set_text_length(std::size_t x);
191 [[nodiscard]]
auto data()
const -> std::vector<Index_and_position>
const&;
193 [[nodiscard]]
auto data() -> std::vector<Index_and_position>&;
198 [[nodiscard]]
auto max_length()
const -> std::size_t;
200 [[nodiscard]]
auto text_length()
const -> std::size_t;
202 [[nodiscard]]
auto is_started()
const -> bool;
204 [[nodiscard]]
auto begin() -> std::vector<Index_and_position>::iterator;
206 [[nodiscard]]
auto begin()
const
207 -> std::vector<Index_and_position>::const_iterator;
209 [[nodiscard]]
auto end() -> std::vector<Index_and_position>::iterator;
211 [[nodiscard]]
auto end()
const
212 -> std::vector<Index_and_position>::const_iterator;
215 std::vector<Index_and_position> data_;
216 std::size_t max_length_;
217 std::size_t text_length_;
218 bool started_ =
false;
226 [[nodiscard]]
auto operator()() ->
IP_range;
228 void set_text_length(std::size_t x);
239 [[nodiscard]]
auto operator()() ->
IP_range;
241 void set_text_length(std::size_t x);
250 [[nodiscard]]
auto operator()() ->
IP_range;
252 void set_text_length(std::size_t x);
260 [[nodiscard]]
auto operator()() ->
IP_range;
262 void set_text_length(std::size_t x);
264 void set_max_length(std::size_t x);
267 std::size_t begin_ = 0;
268 std::size_t hold_ = 0;
271 void reset_hold_length();
274 std::size_t hold_length_;
280 void set_text_length(std::size_t x);
286 void set_text_length(std::size_t x);
288 void set_max_length(std::size_t x);
291 [[nodiscard]]
auto start_condition()
const -> bool;
293 [[nodiscard]]
auto stop_condition()
const -> bool;
295 void stop_and_reset();
301 [[nodiscard]]
auto operator()() ->
IP_range;
303 void set_text_length(std::size_t x);
309 void initialize_data();
319 [[nodiscard]]
auto scan_banner(
321 Scan_banner::Duration_t interval = std::chrono::milliseconds{50},
322 animator::Scan animator = animator::Scan{}) -> std::unique_ptr<Scan_banner>;
325 [[nodiscard]]
auto scan_banner(Scan_banner::Parameters p)
326 -> std::unique_ptr<Scan_banner>;
328 using Persistent_scan_banner = Banner<animator::Persistent_scan>;
331 [[nodiscard]]
auto persistent_scan_banner(
332 Glyph_string text = U
"",
333 Persistent_scan_banner::Duration_t interval = std::chrono::milliseconds{50},
334 animator::Persistent_scan animator = animator::Persistent_scan{})
335 -> std::unique_ptr<Persistent_scan_banner>;
338 [[nodiscard]]
auto persistent_scan_banner(Persistent_scan_banner::Parameters p)
339 -> std::unique_ptr<Persistent_scan_banner>;
341 using Random_banner = Banner<animator::Random>;
344 [[nodiscard]]
auto random_banner(
345 Glyph_string text = U
"",
346 Random_banner::Duration_t interval = std::chrono::milliseconds{50},
347 animator::Random animator = animator::Random{})
348 -> std::unique_ptr<Random_banner>;
351 [[nodiscard]]
auto random_banner(Random_banner::Parameters p)
352 -> std::unique_ptr<Random_banner>;
354 using Scroll_banner = Banner<animator::Scroll>;
357 [[nodiscard]]
auto scroll_banner(
358 Glyph_string text = U
"",
359 Scroll_banner::Duration_t interval = std::chrono::milliseconds{50},
360 animator::Scroll animator = animator::Scroll{})
361 -> std::unique_ptr<Scroll_banner>;
364 [[nodiscard]]
auto scroll_banner(Scroll_banner::Parameters p)
365 -> std::unique_ptr<Scroll_banner>;
367 using Conditional_scroll_banner = Banner<animator::Conditional_scroll>;
370 [[nodiscard]]
auto conditional_scroll_banner(
371 Glyph_string text = U
"",
372 Conditional_scroll_banner::Duration_t interval =
373 std::chrono::milliseconds{50},
374 animator::Conditional_scroll animator = animator::Conditional_scroll{})
375 -> std::unique_ptr<Conditional_scroll_banner>;
378 [[nodiscard]]
auto conditional_scroll_banner(
379 Conditional_scroll_banner::Parameters p)
380 -> std::unique_ptr<Conditional_scroll_banner>;
382 using Unscramble_banner = Banner<animator::Unscramble>;
385 [[nodiscard]]
auto unscramble_banner(
386 Glyph_string text = U
"",
387 Unscramble_banner::Duration_t interval = std::chrono::milliseconds{50},
388 animator::Unscramble animator = animator::Unscramble{})
389 -> std::unique_ptr<Unscramble_banner>;
392 [[nodiscard]]
auto unscramble_banner(Unscramble_banner::Parameters p)
393 -> std::unique_ptr<Unscramble_banner>;
Animated Text Line/Label.
Definition: banner.hpp:45
auto paint_event(Painter &p) -> bool override
Handles Paint_event objects.
Definition: banner.hpp:108
auto resize_event(Area new_size, Area old_size) -> bool override
Handles Resize_event objects.
Definition: banner.hpp:126
auto timer_event() -> bool override
Handles Timer_event objects.
Definition: banner.hpp:119
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
auto size() const -> int
Return the number of Glyphs in *this Glyph_string.
Definition: glyph_string.cpp:36
Definition: banner.hpp:26
Contains functions to paint Glyphs to a Widget's screen area.
Definition: painter.hpp:21
Definition: banner.hpp:177
void initialize_data()
Incremented values, length of text.
Definition: banner.cpp:73
Left to right reveal of text, then hold.
Definition: banner.hpp:237
Random indices are chosed and displayed one at a time.
Definition: banner.hpp:248
Left to right reveal of text, hold, left to right clearing of text.
Definition: banner.hpp:224
Starts with scrambled text and sorts itself one Glyph at a time.
Definition: banner.hpp:299
Definition: banner.hpp:49
Definition: banner.hpp:19