OGLplus  (0.59.0) a C++ wrapper for rendering APIs

progress_bar.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_PROGRESS_BAR_HPP
10 #define EAGINE_PROGRESS_BAR_HPP
11 
12 #include "string_span.hpp"
13 #include <string>
14 
15 namespace eagine {
16 //------------------------------------------------------------------------------
17 template <typename Putter>
18 void format_progress_bar(
19  Putter& put,
20  int width,
21  float min,
22  float max,
23  float prev,
24  float curr);
25 //------------------------------------------------------------------------------
26 class progress_bar {
27 public:
28  progress_bar() noexcept = default;
29 
30  auto set_width(int w) noexcept -> auto& {
31  _width = w < 0 ? 0 : w;
32  return *this;
33  }
34 
35  auto set_min(float min) noexcept -> auto& {
36  _min = min;
37  return *this;
38  }
39 
40  auto set_max(float max) noexcept -> auto& {
41  _max = max;
42  return *this;
43  }
44 
45  auto reformat() noexcept -> progress_bar&;
46 
47  auto update(float value) noexcept -> progress_bar&;
48 
49  auto get() const noexcept -> string_view {
50  return {_buffer.c_str(), span_size_t(_idx)};
51  }
52 
53 private:
54  int _width{80};
55  float _min{-1.F};
56  float _max{+1.F};
57  float _prev{0.F};
58  float _curr{0.F};
59  std::size_t _idx{0};
60  std::string _buffer;
61 };
62 //------------------------------------------------------------------------------
63 } // namespace eagine
64 
65 #include <eagine/progress_bar.inl>
66 
67 #endif // EAGINE_PROGRESS_BAR_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
Common code is placed in this namespace.
Definition: eagine.hpp:21

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).