Skip to content

Add explicit HiDPI window metrics support#17

Open
planetis-m wants to merge 1 commit into
nim-lang:masterfrom
planetis-m:highdpi
Open

Add explicit HiDPI window metrics support#17
planetis-m wants to merge 1 commit into
nim-lang:masterfrom
planetis-m:highdpi

Conversation

@planetis-m
Copy link
Copy Markdown
Contributor

This updates the windowing API to expose HiDPI metrics explicitly while keeping the existing logical-coordinate rendering model.

Main changes:

  • change ScreenLayout.scaleX/scaleY from int to float32
  • add getWindowLayout() so callers can query current logical size and scale
  • add WindowMetricsEvent carrying logical width/height plus scaleX/scaleY
  • update SDL3 to handle HiDPI internally by rendering in device pixels while keeping logical coordinates above the driver boundary
  • update GTK4 to use a HiDPI backing surface while preserving existing logical text/layout behavior
  • wire getWindowLayout() through Cocoa, GTK4, SDL2, X11, and WinAPI
  • update examples and driver docs to use the new event model

Design

The intent is to keep scaling driver-owned rather than pushing pixel/logical conversions into the upper layer.

That means:

  • app code continues to work in logical coordinates
  • drivers decide how to map logical units to device pixels
  • apps can now react explicitly to runtime window metric changes, including monitor scale changes

Verification

Built successfully with:

  • nim c -d:gtk4 examples/todo.nim
  • nim c -d:gtk4 examples/hello.nim
  • nim c -d:sdl3 examples/hello.nim
  • nim c examples/hello.nim

Notes

WindowResizeEvent is still accepted in the examples for compatibility, but WindowMetricsEvent is now the preferred event for window size/scale updates.

Comment thread doc/drivers.md
- **Window**: Emit `WindowResizeEvent` with the new size in `e.x`, `e.y`.
- **Window**: Emit `WindowMetricsEvent` with the new logical size in `e.x`, `e.y`
and the current scale in `e.scaleX`, `e.scaleY`. `WindowResizeEvent` remains
available for older drivers but should be treated as legacy.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come on, just let WindowResizeEvent do a little more and remove the new WindowMetricsEvent again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants