MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ mouse_scrolled()

MAYAFLUX_API Vruta::Event MayaFlux::Kriya::mouse_scrolled ( std::shared_ptr< Core::Window window,
std::function< void(double, double)>  callback 
)

Creates an Event coroutine that triggers on mouse scroll.

Parameters
windowWindow to listen to
callbackFunction to call on scroll with ScrollData
Returns
Event coroutine that can be added to EventManager

Example:

auto task = mouse_scrolled(window,
[](double xoffset, double yoffset) {
// Handle mouse scroll with offsets
});
Vruta::Event mouse_scrolled(std::shared_ptr< Core::Window > window, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on mouse scroll.

Definition at line 148 of file InputEvents.cpp.

151{
152 auto& promise = co_await GetEventPromise {};
153 auto& source = window->get_event_source();
154
155 Vruta::EventFilter filter;
156 filter.event_type = Core::WindowEventType::MOUSE_SCROLLED;
157
158 while (true) {
159 if (promise.should_terminate) {
160 break;
161 }
162
163 auto event = co_await EventAwaiter(source, filter);
164
165 if (auto* scroll_data = std::get_if<Core::WindowEvent::ScrollData>(&event.data)) {
166 callback(scroll_data->x_offset, scroll_data->y_offset);
167 }
168 }
169}
Templated awaitable for accessing a coroutine's promise object.
std::optional< Core::WindowEventType > event_type
Filter criteria for window events.

References MayaFlux::Vruta::EventFilter::event_type, and MayaFlux::Core::MOUSE_SCROLLED.

Referenced by MayaFlux::on_scroll().

+ Here is the caller graph for this function: