147 m_window->handleEvents([
this,&handlers...](
auto&& event) {
148 using EventType = decltype(event);
152 static_assert(!std::disjunction_v<std::is_invocable_r<bool, Ts, EventType, bool>...>,
"Handler for handleWindowEvents can't have both an extra bool argument and a bool return type");
158 auto callIfMatchesAndReturnsBool = [&event](auto&& handler)
161 using FuncType = decltype(handler);
162 if constexpr (std::is_invocable_v<FuncType, EventType>)
164 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType>, bool>)
165 return std::invoke(std::forward<FuncType>(handler), std::forward<EventType>(event));
168 static_assert(std::is_same_v<std::invoke_result_t<FuncType, EventType>, void>,
"Handler for handleWindowEvents must have either 'void' or 'bool' return type");
175 const bool passEventToGui = (callIfMatchesAndReturnsBool(std::forward<Ts>(handlers)) && ...);
178 bool eventHandledByGui =
false;
180 eventHandledByGui = this->
handleEvent(std::forward<EventType>(event));
184 auto callIfMatchesAndReturnsVoid = [&event](
auto&& handler,
auto&&... extraArgs)
186 using FuncType =
decltype(handler);
187 if constexpr (std::is_invocable_v<FuncType, EventType,
decltype(extraArgs)...>)
189 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType,
decltype(extraArgs)...>,
void>)
190 std::invoke(std::forward<FuncType>(handler), std::forward<EventType>(event), std::forward<
decltype(extraArgs)>(extraArgs)...);
193 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers)), ...);
194 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers), eventHandledByGui), ...);