Commit graph

2 commits

Author SHA1 Message Date
andrewmd5 2b46565a2e fix: text measurement/rendering width mismatch in sokol_clay
The text bounding box width was incorrect because the measurement function
was using logical pixels while the rendering function was using physical
pixels (scaled by DPI). This caused a mismatch where:

- sclay_measure_text() set font size and letter spacing without DPI scaling
- sclay_render() applied DPI scaling to both font size and letter spacing
- fontstash's fonsTextBounds() returned physical pixel measurements even
  when given logical pixel sizes, leading to incorrect width calculations

The fix ensures consistent DPI scaling by:
1. Scaling font size and letter spacing by dpi_scale during measurement
2. Dividing the returned bounds by dpi_scale to convert back to logical pixels
3. This ensures Clay receives measurements in logical pixels that match what
   will actually be rendered

This was particularly noticeable with long continuous text where the
discrepancy accumulated across many characters. The issue was font-size
dependent because different font sizes have different rounding behaviors
in the underlying font rendering system.

Also adds text alignment support to properly measure and render centered/right-aligned text.
2025-08-08 17:55:32 +09:00
Nathan Korth eb46688b82
[Renderers/Sokol] Sokol renderer & examples (#373) 2025-04-09 13:40:22 +12:00