digit_display.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef TIME_DISPLAY_H
  2. #define TIME_DISPLAY_H
  3. #include <cassert>
  4. #include <utility>
  5. #include "implementation.h"
  6. #include "layout.h"
  7. #include "digits.h"
  8. template <size_t digit_count = 2>
  9. class digit_display :
  10. public i_movable_bounds<int2>,
  11. public i_graphic,
  12. public ui_element,
  13. public i_ui_object
  14. {
  15. public:
  16. digit_display(int2 digit_size, int2 digit_spacing, graphical::color color);
  17. virtual ~digit_display() = default;
  18. void set(int value) noexcept;
  19. digit_display& operator+=(const int2&) override;
  20. int2 lower() const override;
  21. int2 upper() const override;
  22. void draw(const graphical::surface&) override;
  23. void update(const interactive::event& event) noexcept override;
  24. void drop_focus() noexcept override;
  25. using callback = std::function<void(digit_display&, int old_value, int new_value)>;
  26. std::vector<callback> on_input;
  27. private:
  28. template <size_t... I>
  29. digit_display(int2 digit_size, int2 digit_spacing, graphical::color color, std::index_sequence<I...>);
  30. graphical::color color;
  31. std::array<digit_bitmap, digit_count> digits;
  32. bounds_layout_vector layout; // TODO: unnecessary self reference, wrecks the copy (along with similar thing in ui_element)
  33. int set_value;
  34. int input_value;
  35. bool input;
  36. };
  37. #endif /* end of include guard */