Commit graph

181 commits

Author SHA1 Message Date
Andrew Sampson e5a478cdd8
undo: textAlignment 2025-08-15 20:58:30 +09:00
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
Nic Barker 4aa3d75bef [Core] Split base ID hash from index ID hash 2025-07-16 09:30:54 +10:00
Tomás Ralph 0022d12c0c
[DebugTools] Fix aspect ratio display, closes #449 (#451) 2025-07-02 09:46:12 +10:00
Nic Barker d9d0b6c37b [Core] Fix incorrect percentage sizing of floating elements 2025-07-02 09:37:38 +10:00
Nic Barker 3433a53a8e [Core] Fix an alignment bug for scrolling container contents 2025-06-24 13:55:20 +10:00
Nic Barker ff7917798c [Core] Avoid calling measure text function with length zero 2025-06-23 10:10:13 +10:00
Nic Barker a5e212b8de [Renderers/HTML] Fix a mouse overlap bug with external scroll handling 2025-06-20 10:59:44 +10:00
Nic Barker c524485c46 [Core] Fix case where there could be 64 extra bytes of padding between arrays in clays internal arena 2025-06-17 13:07:56 +10:00
Nic Barker b9e27178c0 [Core] Align base arena memory to 64 byte cache line 2025-06-17 10:32:30 +10:00
Nic Barker 6f10bf4b3d [Core] Remove erroneous break statement when using external scroll handling 2025-06-13 10:35:31 +10:00
Nic Barker dca9f60a6c [Core] Add objective-c support 2025-06-12 12:16:29 +10:00
Nic Barker 3ccfa0f8fa [Core] Fix a bug where extra child gap was added to the dimensions of clipped containers 2025-06-11 10:41:01 +10:00
Nic Barker 6b03a215b7 [Core] Fix an out of bounds access for single newline characters 2025-06-10 11:38:56 +10:00
Nic Barker 8bbe14fbcc [Documentation] Fix README typo, bump version number to 0.14 2025-06-06 10:20:37 +10:00
Nic Barker 87575cb7c3 [Core] Fix handling of letter spacing 2025-06-05 10:38:53 +10:00
Michael Tanner 149833bdc0
[Core] Fix dimension calculation that would always result in 0 (#428) 2025-06-02 12:27:28 +10:00
Nic Barker 0431f862f4 [Core] Improve handling of aspect ratio scaling 2025-06-02 12:14:09 +10:00
Nic Barker d6f3957a60
[Core] Split aspect ratio scaling into its own config (#426) 2025-06-02 10:36:58 +10:00
Boreal 89ce22e894
[Core] Fix sign comparison warning (#427) 2025-05-29 13:10:05 +10:00
Nic Barker ce2475ba73 [Compilers] Add missing struct name for image element config 2025-05-26 10:10:24 +10:00
Johann Muszynski 34ff7e1bea
[Compilers] Add struct names to public structs (#336) 2025-05-26 10:03:07 +10:00
Simon Oelerich efbd680685
[Core] restore compatibility with C99 (#412) 2025-05-14 13:29:12 +12:00
Patrick Doane b656dc5253
[Core] Add Clay_FloatingClipToElement (#413) 2025-05-14 13:24:42 +12:00
João Matos b78fd66da8
[Core] Add Clay_GetPointerOverIds function to the public API. (#389) 2025-05-14 12:39:56 +12:00
João Matos 52759cd028
[Debug] Update Clay__RenderDebugLayoutSizing to handle more sizing types. (#392) 2025-05-05 12:27:55 +12:00
Nic Barker 90b45f059c [Core] Fix a bug with the implementation of clip .childOffset 2025-05-01 17:21:09 +12:00
Nic Barker 970919e1fb
[Core] Replace .scroll config with .clip (#376) 2025-05-01 14:11:31 +12:00
Nic Barker a21b0665fe [Core] Correctly throw an error when using attach to element id with an invalid id 2025-04-29 12:31:54 +12:00
Nic Barker b33ba4ff62
[Core] Fix a string hash bug with single characters (#384) 2025-04-16 20:16:05 +12:00
Nic Barker 06167b4f4b [Core] Fix a potential null pointer deref in scroll GetScrollContainerData 2025-04-12 11:27:10 +12:00
Nic Barker a9e94e3be0 [Core] Fix onHover reference not being reset for identical IDs between frames 2025-04-04 13:05:31 +13:00
Nic Barker 50aad568fa [Core] Remove unused variable in arm simd and inline rotate function' 2025-04-01 10:43:11 +13:00
Nic Barker b4dc02c73a [Core] Fix a bug with how element string ids were stored when using Clay_Hovered 2025-04-01 10:40:04 +13:00
Nic Barker 1204ac400b [Compilers] Fix implicit typecast in simd hash function 2025-03-28 11:52:20 +13:00
Nic Barker 6a7ce77024 [Core] Fix implicit simd typecast on arm architectures 2025-03-28 11:47:57 +13:00
Piggybank Studios 7c9506bc31
[Core] Fix CLAY__ELEMENT_DEFINITION_LATCH overflow in CLAY macro if 256 loops end at the same time 2025-03-27 10:14:17 +13:00
Nic Barker 08e4c5b198 [Core] Fix a bug where ID aliases werent copied on hash collision 2025-03-26 09:35:15 +13:00
Igor Karatayev aee4baee1c
[Core] Guard against hashmap item null dereference (#338) 2025-03-26 09:19:50 +13:00
Nic Barker 47d1d84bc8
[Core] Switch text content hashing to default behaviour (#335) 2025-03-25 10:13:04 +13:00
Nic Barker ad49977f1b [Core] Apply minimum width for single words and fix some minimum sizing bugs 2025-03-21 11:22:48 +13:00
Nic Barker 982ade4cf9 [Compilers] Add a dummy function to suppress unused variable warning in GCC 2025-03-18 11:21:23 +13:00
Nic Barker 1f8cab8d72 [Core] Fix a bug where floating elements could be clipped incorrectly 2025-03-18 11:05:06 +13:00
Nic Barker 39fdd0e906
[Compilers] Fix integer truncation warnings with explicit casts 2025-03-13 09:40:31 +13:00
Nic Barker c06e01c1af
Merge pull request #319 from emoon/pass-declaration-by-pointer
Support passing declaration by pointer as well
2025-03-11 09:39:40 +13:00
Nic Barker fabdad43f6 [Documentation] Update internal version number to 0.13 in clay.h 2025-03-10 14:39:18 +13:00
Daniel Collin 19a27b39f2
[Compilers] Fixed SIMD related compile error on some ARM compilers (#316) 2025-03-09 10:28:09 +13:00
Daniel Collin 33b8e76903 Support passing declaration by pointer as well 2025-03-08 15:17:36 +01:00
Johann Muszynski ad4d00be33 Fix integer truncation warnings with explicit casts 2025-03-08 14:53:30 +02:00
Michael Savage 8e6640f7a2
[Core] Add a userData pointer to Clay_TextElementConfig (#274) 2025-03-08 11:01:26 +13:00