Skip to content

Commit

Permalink
make FunctionalEventListener default constructible
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Feb 29, 2024
1 parent ef1b5c1 commit 3188b82
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/threepp/core/EventDispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ namespace threepp {

struct FunctionalEventListener: EventListener {

FunctionalEventListener(): FunctionalEventListener([](Event){}){}

FunctionalEventListener(std::function<void(Event)> listener)
: f_(std::move(listener)) {}
: callback_(std::move(listener)) {}

void setListener(std::function<void(Event)> f) {
callback_ = std::move(f);
}

void onEvent(Event& event) override {
return f_(event);
return callback_(event);
}

private:
std::function<void(Event)> f_;
std::function<void(Event)> callback_;
};

class EventDispatcher {
Expand Down

0 comments on commit 3188b82

Please sign in to comment.