|
| 1 | +/*============================================================================= |
| 2 | + Copyright (c) 2024 Flole |
| 3 | +
|
| 4 | + Distributed under the MIT License [ https://opensource.org/licenses/MIT ] |
| 5 | +=============================================================================*/ |
| 6 | +#if !defined(ELEMENTS_BUSY_BAR_JUNE_13_2024) |
| 7 | +#define ELEMENTS_BUSY_BAR_JUNE_13_2024 |
| 8 | + |
| 9 | +#include "elements/element/progress_bar.hpp" |
| 10 | + |
| 11 | +namespace cycfi::elements |
| 12 | +{ |
| 13 | + class busy_bar_base : public progress_bar_base |
| 14 | + { |
| 15 | + public: |
| 16 | + busy_bar_base(double init_value = 0.0, double start_value = 0.0) |
| 17 | + : progress_bar_base(init_value), _start(start_value), _status(-0.2) |
| 18 | + {} |
| 19 | + |
| 20 | + void start(double val); |
| 21 | + double start() const { return _start; } |
| 22 | + void animate(view& view_, duration time); |
| 23 | + |
| 24 | + rect foreground_bounds(context const& ctx) const override; |
| 25 | + |
| 26 | + private: |
| 27 | + void animate(view& view_); |
| 28 | + |
| 29 | + double _start; // Start position |
| 30 | + double _status; |
| 31 | + duration _time; |
| 32 | + }; |
| 33 | + |
| 34 | + class basic_busy_bar_base : public busy_bar_base |
| 35 | + { |
| 36 | + public: |
| 37 | + basic_busy_bar_base(double init_value, double start_value) |
| 38 | + : busy_bar_base(init_value, start_value) |
| 39 | + {} |
| 40 | + }; |
| 41 | + |
| 42 | + namespace concepts |
| 43 | + { |
| 44 | + template <typename T> |
| 45 | + concept BusyBar = std::is_base_of_v<busy_bar_base, std::decay_t<T>>; |
| 46 | + } |
| 47 | + |
| 48 | + template < |
| 49 | + concepts::Element Background |
| 50 | + , concepts::Element Foreground |
| 51 | + , concepts::BusyBar Base = basic_busy_bar_base |
| 52 | + > |
| 53 | + class basic_busy_bar : public Base |
| 54 | + { |
| 55 | + public: |
| 56 | + |
| 57 | + using background_type = std::decay_t<Background>; |
| 58 | + using foreground_type = std::decay_t<Foreground>; |
| 59 | + |
| 60 | + basic_busy_bar( |
| 61 | + Background&& bg |
| 62 | + , Foreground&& fg |
| 63 | + , double init_value |
| 64 | + , double start_value |
| 65 | + ) |
| 66 | + : Base(init_value, start_value) |
| 67 | + , _background(std::forward<Foreground>(bg)) |
| 68 | + , _foreground(std::forward<Background>(fg)) |
| 69 | + {} |
| 70 | + |
| 71 | + basic_busy_bar(Background const& bg, Foreground const& fg, double init_value, double start_value) |
| 72 | + : Base(init_value, start_value) |
| 73 | + , _foreground(fg) |
| 74 | + , _background(bg) |
| 75 | + {} |
| 76 | + |
| 77 | + element const& background() const override { return _background; } |
| 78 | + element& background() override { return _background; } |
| 79 | + element const& foreground() const override { return _foreground; } |
| 80 | + element& foreground() override { return _foreground; } |
| 81 | + |
| 82 | + private: |
| 83 | + |
| 84 | + background_type _background; |
| 85 | + foreground_type _foreground; |
| 86 | + }; |
| 87 | + |
| 88 | + template <concepts::Element Background, concepts::Element Foreground> |
| 89 | + basic_busy_bar<Background, Foreground, basic_busy_bar_base> |
| 90 | + busy_bar(Background&& bg, Foreground&& fg, double init_value = 0.0, double start_value = 0.0) |
| 91 | + { |
| 92 | + return { |
| 93 | + std::forward<Background>(bg), |
| 94 | + std::forward<Foreground>(fg), |
| 95 | + init_value, |
| 96 | + start_value |
| 97 | + }; |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +#endif |
0 commit comments