Support ui component-specific cursors specified by a string id
This commit is contained in:
parent
61fd45d40c
commit
d5b755bde0
3 changed files with 36 additions and 0 deletions
|
|
@ -9,6 +9,8 @@
|
|||
#include <psemek/util/span.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
|
@ -33,6 +35,8 @@ namespace psemek::ui::impl
|
|||
virtual void draw(renderer &) {}
|
||||
virtual void post_draw(renderer &) {}
|
||||
|
||||
virtual std::optional<std::string> cursor() const { return std::nullopt; }
|
||||
|
||||
virtual ~component() {}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <psemek/ui/impl/component_factory.hpp>
|
||||
#include <psemek/ui/impl/renderer.hpp>
|
||||
#include <psemek/ui/impl/event_state.hpp>
|
||||
#include <psemek/react/value.hpp>
|
||||
#include <psemek/util/pimpl.hpp>
|
||||
|
||||
|
|
@ -25,9 +26,13 @@ namespace psemek::ui::impl
|
|||
bool on_event(mouse_button_event const & event);
|
||||
bool on_event(key_event const & event);
|
||||
|
||||
event_state const & state();
|
||||
|
||||
void update(float dt);
|
||||
void draw(renderer & renderer);
|
||||
|
||||
std::optional<std::string> cursor();
|
||||
|
||||
private:
|
||||
psemek_declare_pimpl
|
||||
};
|
||||
|
|
|
|||
|
|
@ -90,6 +90,23 @@ namespace psemek::ui::impl
|
|||
|
||||
element->post_draw(renderer);
|
||||
}
|
||||
|
||||
std::optional<std::string> cursor()
|
||||
{
|
||||
return cursor_impl(root.get());
|
||||
}
|
||||
|
||||
std::optional<std::string> cursor_impl(component * element)
|
||||
{
|
||||
if (!element)
|
||||
return std::nullopt;
|
||||
|
||||
for (auto const & child : util::reversed(element->children()))
|
||||
if (auto cursor = cursor_impl(child.get()))
|
||||
return cursor;
|
||||
|
||||
return element->cursor();
|
||||
}
|
||||
};
|
||||
|
||||
controller::controller(component_factory & factory)
|
||||
|
|
@ -133,6 +150,11 @@ namespace psemek::ui::impl
|
|||
return impl().on_event(event);
|
||||
}
|
||||
|
||||
event_state const & controller::state()
|
||||
{
|
||||
return impl().state;
|
||||
}
|
||||
|
||||
void controller::update(float dt)
|
||||
{
|
||||
impl().update(dt);
|
||||
|
|
@ -143,4 +165,9 @@ namespace psemek::ui::impl
|
|||
impl().draw(renderer);
|
||||
}
|
||||
|
||||
std::optional<std::string> controller::cursor()
|
||||
{
|
||||
return impl().cursor();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue