155 m_window->handleEvents(
156 [
this, &handlers...](
auto&& event)
158 using EventType = decltype(event);
162 static_assert(!std::disjunction_v<std::is_invocable_r<bool, Ts, EventType, bool>...>,
163 "Handler for handleWindowEvents can't have both an extra bool argument and a bool return type");
169 auto callIfMatchesAndReturnsBool = [&event](auto&& handler)
172 using FuncType = decltype(handler);
173 if constexpr (std::is_invocable_v<FuncType, EventType>)
175 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType>, bool>)
176 return std::invoke(std::forward<FuncType>(handler), std::forward<EventType>(event));
179 static_assert(std::is_same_v<std::invoke_result_t<FuncType, EventType>, void>,
180 "Handler for handleWindowEvents must have either 'void' or 'bool' return type");
187 const bool passEventToGui = (callIfMatchesAndReturnsBool(std::forward<Ts>(handlers)) && ...);
190 bool eventHandledByGui =
false;
192 eventHandledByGui =
handleEvent(std::forward<EventType>(event));
196 auto callIfMatchesAndReturnsVoid = [&event](
auto&& handler,
auto&&... extraArgs)
198 using FuncType =
decltype(handler);
199 if constexpr (std::is_invocable_v<FuncType, EventType,
decltype(extraArgs)...>)
201 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType,
decltype(extraArgs)...>,
void>)
202 std::invoke(std::forward<FuncType>(handler),
203 std::forward<EventType>(event),
204 std::forward<
decltype(extraArgs)>(extraArgs)...);
207 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers)), ...);
208 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers), eventHandledByGui), ...);