Make auto row height calculations pixel perfect#67
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the UI layout system to perform calculations in pixel space rather than display point (DP) space, eliminating rounding accumulation that was causing row overlap bugs. The core change is in UI_initLayout() which now calculates optimal row count and pill height directly in pixels, then stores both pixel values (for exact positioning) and DP values (for proportional calculations) in the UI_Layout struct. This approach ensures that repeated layout arithmetic (e.g., y = edge_padding_px + row * pill_height_px) uses exact integer pixel values without intermediate DP conversions that round and accumulate error.
Key Changes:
- Introduced pixel-accurate row fitting algorithm that works entirely in pixel space to prevent rounding drift
- Added
*_pxfields toUI_Layoutstruct (pill_height_px,edge_padding_px,option_size_px) for exact layout positioning - Updated all UI rendering code to use pre-calculated
*_pxfields instead of repeatedly callingDP()on intermediate calculations
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
workspace/all/common/api.h |
Added comprehensive documentation explaining the distinction between DP values (for proportional calculations) and pixel values (for exact positioning), plus usage examples. Added new *_px fields to UI_Layout struct. |
workspace/all/common/api.c |
Rewrote UI_initLayout() to calculate row count and pill size entirely in pixel space. Updated initialization code to populate both DP and pixel fields. Modified asset scaling and text centering to use pre-calculated pixel values. |
workspace/all/utils/shui/ui_list.c |
Replaced DP(ui.edge_padding), DP(ui.pill_height), and DP(ui.option_size) calls with pre-calculated pixel values for exact positioning. |
workspace/all/utils/shui/ui_keyboard.c |
Updated layout calculations to use ui.pill_height_px and ui.edge_padding_px for pixel-perfect positioning. |
workspace/all/minui/minui.c |
Converted vertical positioning calculations to use ui.edge_padding_px + (j * ui.pill_height_px) pattern for pixel-accurate row placement. |
workspace/all/minarch/minarch_menu.c |
Updated pill positioning to use ui.edge_padding_px and ui.pill_height_px for consistent pixel-perfect layout. |
workspace/all/minarch/minarch.c |
Converted option row positioning to use ui.option_size_px and updated initialization to use pre-calculated pixel values throughout. |
tests/unit/all/common/test_ui_layout.c |
Removed deprecated ui.text_baseline field and associated test, reflecting its removal from the actual implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c607c71 to
4b7f3ac
Compare
No description provided.