implementaion.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef IMPLEMENTAION_HPP
  2. #define IMPLEMENTAION_HPP
  3. #include <functional>
  4. #include <vector>
  5. #include "interface.hpp"
  6. #include "simple.hpp"
  7. class movable_bounds : public i_movable_bounds<int2>
  8. {
  9. public:
  10. movable_bounds(range2D bounds);
  11. int2 lower() const override;
  12. int2 upper() const override;
  13. movable_bounds& operator+=(const int2& offset) override;
  14. virtual ~movable_bounds() = default;
  15. protected:
  16. movable_bounds(const movable_bounds&) = default;
  17. movable_bounds& operator=(const movable_bounds&) = default;
  18. range2D bounds;
  19. };
  20. class ui_element : public i_interactive_focusable
  21. {
  22. public:
  23. enum class state
  24. {
  25. idle,
  26. pressed,
  27. hover,
  28. disabled
  29. };
  30. virtual ~ui_element() = default;
  31. void update(const interactive::event&) noexcept override;
  32. state current_state() const noexcept;
  33. void disable(bool = true) noexcept;
  34. void enable(bool = true) noexcept;
  35. using callback = std::function<void(ui_element&)>;
  36. std::vector<callback> on_click;
  37. std::vector<callback> on_press;
  38. std::vector<callback> on_release;
  39. void focus(bool) noexcept override;
  40. bool focus() const noexcept override;
  41. protected:
  42. explicit ui_element(const i_bounds<int2>&);
  43. state current;
  44. private:
  45. const i_bounds<int2>& bounds_proxy;
  46. bool _focus;
  47. };
  48. class focus_group
  49. {
  50. public:
  51. using container = std::vector<i_focusable*>;
  52. void focus();
  53. void drop_focus();
  54. void focus(size_t index);
  55. void focus(i_focusable*);
  56. void pre_update(const interactive::event&);
  57. void post_update(const interactive::event&);
  58. container elements;
  59. private:
  60. i_focusable* focused_element = nullptr;
  61. bool expecting_focus = false;
  62. };
  63. #endif /* end of include guard */