1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #ifndef IMPLEMENTATION_H
- #define IMPLEMENTATION_H
- #include <functional>
- #include <vector>
- #include "interface.hpp"
- #include "simple.hpp"
- class movable_bounds : public i_movable_bounds<int2>
- {
- public:
- movable_bounds(range2D bounds);
- int2 lower() const override;
- int2 upper() const override;
- movable_bounds& operator+=(const int2& offset) override;
- virtual ~movable_bounds() = default;
- protected:
- movable_bounds(const movable_bounds&) = default;
- movable_bounds& operator=(const movable_bounds&) = default;
- range2D bounds;
- };
- class ui_element : public i_interactive, public i_focusable
- {
- public:
- enum class state
- {
- idle,
- pressed,
- hover,
- disabled
- };
- ui_element(const ui_element&) = delete; // TODO: remove, when bounds_proxy is replaced with CRTP, meanwhile, copy is dangerous, it should still be explicit though
- virtual ~ui_element() = default;
- void update(const interactive::event&) noexcept override;
- state current_state() const noexcept;
- void disable(bool = true) noexcept;
- void enable(bool = true) noexcept;
- using callback = std::function<void(ui_element&)>;
- std::vector<callback> on_click;
- std::vector<callback> on_press;
- std::vector<callback> on_release;
- void drop_focus() noexcept override;
- virtual void gain_focus() noexcept;
- bool focus() const noexcept override;
- bool focus_on(const i_focusable&) noexcept override;
- bool focus(direction) noexcept override;
- protected:
- explicit ui_element(const i_bounds<int2>&);
- state current;
- private:
- // TODO: polymorphic bounds are clearly useless here, can just CRTP this
- const i_bounds<int2>& bounds_proxy;
- bool _focus;
- };
- template <typename Range>
- class focus_group final : public i_focusable
- {
- public:
- bool focus() const noexcept override;
- void drop_focus() noexcept override;
- bool focus_on(const i_focusable&) noexcept override;
- bool focus(direction) override;
- focus_group();
- focus_group(Range);
- private:
- bool focused_in_range() const noexcept;
- Range elements;
- typename Range::iterator focused_element;
- };
- template <typename R> focus_group(R) -> focus_group<R>;
- using focus_vector = focus_group<std::vector<std::reference_wrapper<i_focusable>>>;
- #endif /* end of include guard */
|