Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is not yet complete, I wrote a lot of comments for personal reference/notes that requires removal, and documentation needs to be added for some of the new traits, structs and functions that I have added.
Objective
This PR addresses issue #18137 by implementing logical pixel rendering for gizmo line widths. Currently, gizmo lines are rendered in physical pixels, which results in inconsistent appearance across different displays with varying DPI settings. This change ensures that gizmo lines maintain consistent visual thickness regardless of the display's scale factor or resolution.
Fixes #18137
Solution
The solution implements logical pixel rendering for gizmo line widths using the
Val
enum frombevy_ui
, similar to how UI borders are handled. Key changes include:1. Logical Pixel Implementation
GizmoLineConfig.width
fromf32
toVal
enumVal::Px(f32)
,Val::Vw(f32)
,Val::Vh(f32)
,Val::Auto
2. Backwards Compatibility
IntoVal
trait for automatic conversion fromf32
toVal::Px(f32)
ValExt
trait providing arithmetic operations (add_assign
,sub_assign
,mul_assign
,div_assign
,clamp
)f32
values continues to work without modificationGizmoLineConfig::new()
andwith_width()
accept bothf32
andVal
types3. Enhanced Configuration
4. Multi-Window Support
Testing
Manual Testing
2d_gizmos
example - compiles and runs correctly with new arithmetic methods3d_gizmos
example - compiles and runs correctly with constructor methodslight_gizmos
example - updated to useValExt
trait methodsf32
values work without changesPlatform Testing
Val
enum usageAreas for Additional Testing
How Reviewers Can Test
cargo run --example 2d_gizmos
f32
values in existing codeVal
-based features with different unitsShowcase
Click to view showcase
Before (Physical Pixels)
After (Logical Pixels)
Visual Impact
Migration Guide
Automatic Migration
Most existing code will continue to work without changes due to backwards compatibility:
Recommended Migration
For new code or when updating existing code, consider using the new
Val
-based approach:Breaking Changes