diff options
| author | 3gg <3gg@shellblade.net> | 2026-03-13 20:19:47 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-03-13 20:19:47 -0700 |
| commit | dad6f6cf87a94f5a1e804b2f68afa4ef680540e0 (patch) | |
| tree | 807612cfaa6de4fa95d7f790d518f4fe873b11cb /src | |
| parent | d3c4d4dfb28a518bff924764e74ca4ededf1bd41 (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/xplorer.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/xplorer.c b/src/xplorer.c index 6dd1bbf..da66f0d 100644 --- a/src/xplorer.c +++ b/src/xplorer.c | |||
| @@ -270,11 +270,13 @@ int main( | |||
| 270 | State state = {0}; | 270 | State state = {0}; |
| 271 | 271 | ||
| 272 | if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { | 272 | if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { |
| 273 | return false; | 273 | success = false; |
| 274 | goto cleanup; | ||
| 274 | } | 275 | } |
| 275 | 276 | ||
| 276 | if (!uiInit()) { | 277 | if (!uiInit()) { |
| 277 | return false; | 278 | success = false; |
| 279 | goto cleanup; | ||
| 278 | } | 280 | } |
| 279 | 281 | ||
| 280 | if (!Initialize(&state)) { | 282 | if (!Initialize(&state)) { |
| @@ -297,6 +299,12 @@ int main( | |||
| 297 | // Initially true to perform an initial draw before the window is displayed. | 299 | // Initially true to perform an initial draw before the window is displayed. |
| 298 | bool redraw = true; | 300 | bool redraw = true; |
| 299 | 301 | ||
| 302 | // Scrolling on a trackpad often results in scroll values in [0,1], but the UI | ||
| 303 | // library handles integer scroll deltas only. | ||
| 304 | // Accumulate floating-point deltas and issue them to the UI library when | ||
| 305 | // the integer part becomes non-zero. | ||
| 306 | float scroll = 0.f; | ||
| 307 | |||
| 300 | while (running) { | 308 | while (running) { |
| 301 | EVENT_LOOP_PRINT("loop\n"); | 309 | EVENT_LOOP_PRINT("loop\n"); |
| 302 | 310 | ||
| @@ -366,21 +374,21 @@ int main( | |||
| 366 | }; | 374 | }; |
| 367 | redraw = uiSendEvent(state.frame, &ev); | 375 | redraw = uiSendEvent(state.frame, &ev); |
| 368 | } else if (event.type == SDL_EVENT_MOUSE_WHEEL) { | 376 | } else if (event.type == SDL_EVENT_MOUSE_WHEEL) { |
| 369 | int x, y; | 377 | scroll += event.wheel.y; |
| 370 | MouseCoordsToUiCoords( | 378 | const int scroll_int = (int)scroll; |
| 371 | state.window, event.wheel.mouse_x, event.wheel.mouse_y, &x, &y); | 379 | scroll = scroll - (float)scroll_int; |
| 372 | // TODO: Scrolling on a trackpad results in 0<event.wheel.y<1 values, | 380 | if (scroll_int != 0) { |
| 373 | // which become 0 with integer truncation. Have the UI library handle | 381 | int x, y; |
| 374 | // float values for smooth scrolling. Though that means a lot of the UI | 382 | MouseCoordsToUiCoords( |
| 375 | // input will have to be float-based. Should we handle it here in the | 383 | state.window, event.wheel.mouse_x, event.wheel.mouse_y, &x, &y); |
| 376 | // client instead? That seems inconvenient. | 384 | const uiInputEvent ev = { |
| 377 | const uiInputEvent ev = { | ||
| 378 | .type = uiEventMouseScroll, | 385 | .type = uiEventMouseScroll, |
| 379 | .mouse_scroll = | 386 | .mouse_scroll = |
| 380 | (uiMouseScrollEvent){.scroll_offset = (int)event.wheel.y, | 387 | (uiMouseScrollEvent){.scroll_offset = scroll_int, |
| 381 | .mouse_position = (uiPoint){x, y}} | 388 | .mouse_position = (uiPoint){x, y}} |
| 382 | }; | 389 | }; |
| 383 | redraw = uiSendEvent(state.frame, &ev); | 390 | redraw = uiSendEvent(state.frame, &ev); |
| 391 | } | ||
| 384 | } else if (event.type == SDL_EVENT_MOUSE_MOTION) { | 392 | } else if (event.type == SDL_EVENT_MOUSE_MOTION) { |
| 385 | int x, y; | 393 | int x, y; |
| 386 | MouseCoordsToUiCoords( | 394 | MouseCoordsToUiCoords( |
| @@ -415,7 +423,7 @@ cleanup: | |||
| 415 | } | 423 | } |
| 416 | if (state.window) { | 424 | if (state.window) { |
| 417 | SDL_DestroyWindow(state.window); | 425 | SDL_DestroyWindow(state.window); |
| 418 | state.window = 0; | 426 | state.window = nullptr; |
| 419 | } | 427 | } |
| 420 | 428 | ||
| 421 | uiShutdown(); | 429 | uiShutdown(); |
