147 m_window->handleEvents(
148 [
this, &handlers...](
auto&& event)
150 using EventType = decltype(event);
154 static_assert(!std::disjunction_v<std::is_invocable_r<bool, Ts, EventType, bool>...>,
155 "Handler for handleWindowEvents can't have both an extra bool argument and a bool return type");
161 auto callIfMatchesAndReturnsBool = [&event](auto&& handler)
164 using FuncType = decltype(handler);
165 if constexpr (std::is_invocable_v<FuncType, EventType>)
167 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType>, bool>)
168 return std::invoke(std::forward<FuncType>(handler), std::forward<EventType>(event));
171 static_assert(std::is_same_v<std::invoke_result_t<FuncType, EventType>, void>,
172 "Handler for handleWindowEvents must have either 'void' or 'bool' return type");
179 const bool passEventToGui = (callIfMatchesAndReturnsBool(std::forward<Ts>(handlers)) && ...);
182 bool eventHandledByGui =
false;
184 eventHandledByGui =
handleEvent(std::forward<EventType>(event));
188 auto callIfMatchesAndReturnsVoid = [&event](
auto&& handler,
auto&&... extraArgs)
190 using FuncType =
decltype(handler);
191 if constexpr (std::is_invocable_v<FuncType, EventType,
decltype(extraArgs)...>)
193 if constexpr (std::is_same_v<std::invoke_result_t<FuncType, EventType,
decltype(extraArgs)...>,
void>)
194 std::invoke(std::forward<FuncType>(handler),
195 std::forward<EventType>(event),
196 std::forward<
decltype(extraArgs)>(extraArgs)...);
199 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers)), ...);
200 (callIfMatchesAndReturnsVoid(std::forward<Ts>(handlers), eventHandledByGui), ...);