Support update callback in ui::event_interceptor
This commit is contained in:
parent
c1699fe882
commit
cf13025cc6
2 changed files with 15 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ namespace psemek::ui
|
|||
void on_mouse_click(std::function<bool(mouse_click const &)> callback);
|
||||
void on_mouse_wheel(std::function<bool(mouse_wheel const &)> callback);
|
||||
void on_key_press(std::function<bool(key_press const &)> callback);
|
||||
void on_update(std::function<void(float)> callback);
|
||||
|
||||
bool on_event(mouse_move const & event) override;
|
||||
bool on_event(mouse_click const & event) override;
|
||||
|
|
@ -29,6 +30,8 @@ namespace psemek::ui
|
|||
|
||||
bool transparent() const override { return true; }
|
||||
|
||||
void update(float dt) override;
|
||||
|
||||
void draw(painter &) const override {}
|
||||
|
||||
private:
|
||||
|
|
@ -38,6 +41,7 @@ namespace psemek::ui
|
|||
std::function<bool(mouse_click const &)> mouse_click_callback_;
|
||||
std::function<bool(mouse_wheel const &)> mouse_wheel_callback_;
|
||||
std::function<bool(key_press const &)> key_press_callback_;
|
||||
std::function<void(float)> update_callback_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ namespace psemek::ui
|
|||
key_press_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void event_interceptor::on_update(std::function<void(float)> callback)
|
||||
{
|
||||
update_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
bool event_interceptor::on_event(mouse_move const & event)
|
||||
{
|
||||
if (child_)
|
||||
|
|
@ -92,4 +97,10 @@ namespace psemek::ui
|
|||
return false;
|
||||
}
|
||||
|
||||
void event_interceptor::update(float dt)
|
||||
{
|
||||
if (update_callback_)
|
||||
update_callback_(dt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue