Support arbitrary post-draw effect in ui::controller

This commit is contained in:
Nikita Lisitsa 2022-05-29 19:27:28 +03:00
parent 14d7dda788
commit 6e289b3b90
2 changed files with 12 additions and 0 deletions

View file

@ -22,6 +22,8 @@ namespace psemek::ui
void set_hint_delay(float seconds); void set_hint_delay(float seconds);
void on_hint(util::function<void(element *)> callback); void on_hint(util::function<void(element *)> callback);
void set_post_draw_effect(util::function<void(element *, painter &)> effect);
void reshape(geom::box<float, 2> const & shape); void reshape(geom::box<float, 2> const & shape);
bool event(mouse_move const & e); bool event(mouse_move const & e);

View file

@ -68,6 +68,7 @@ namespace psemek::ui
util::function<void(element *)> on_hint; util::function<void(element *)> on_hint;
std::optional<std::weak_ptr<element>> hinted_element = std::nullopt; std::optional<std::weak_ptr<element>> hinted_element = std::nullopt;
std::optional<std::string> hint_called = std::nullopt; std::optional<std::string> hint_called = std::nullopt;
util::function<void(element *, struct painter &)> post_draw_effect;
impl(async::event_loop * loop); impl(async::event_loop * loop);
@ -212,6 +213,11 @@ namespace psemek::ui
impl().on_hint = std::move(callback); impl().on_hint = std::move(callback);
} }
void controller::set_post_draw_effect(util::function<void(element *, painter &)> effect)
{
impl().post_draw_effect = std::move(effect);
}
void controller::reshape(geom::box<float, 2> const & shape) void controller::reshape(geom::box<float, 2> const & shape)
{ {
impl().root->reshape(shape); impl().root->reshape(shape);
@ -321,7 +327,11 @@ namespace psemek::ui
for (auto c : elem->children()) for (auto c : elem->children())
if (c) self(c); if (c) self(c);
if (visible) if (visible)
{
elem->post_draw(impl().painter); elem->post_draw(impl().painter);
if (impl().post_draw_effect)
impl().post_draw_effect(elem, impl().painter);
}
}); });
visitor(impl().root.get()); visitor(impl().root.get());