-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Node::physical_rect
and add a physical_size
method
#8551
Conversation
* Added a method `physical_size` to `Node` that calculates the physical size of the `Node` based on the given scale factor. * Fixed the `Node::physical_rect` method, the logical size should be multiplied by the scale factor to get the physical size. * Removed the `scale_value` function from the `text` widget module and replaced its usage with `Node::physical_size`.
@@ -30,6 +30,15 @@ impl Node { | |||
self.calculated_size | |||
} | |||
|
|||
/// Returns the size of the node in physical pixels based on the given scale factor. | |||
#[inline] | |||
pub fn physical_size(&self, scale_factor: f64) -> Vec2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we need the double precision here when almost everything we're working with is single precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this is just a winit convention that we've stuck with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hasn't seemed like a priority so I've left it alone but I can't see anywhere that it makes any difference. We're not dealing with large numbers, Taffy and bevy_text both do rounding of coordinates and almost everything is recalculated with each update. There is nowhere for errors to accumulate.
If there are problems any with using f32
s everywhere, I think they would be very situational and we can identify and use double precision in those specific cases. It makes no sense to use double precision when calculating mouse over, for instance, and it's an extra little burden for contributors and users when the scale factor implementation is already fragile and confusing.
@ickshonpe can you resolve the merge conflicts and then I'll merge :) |
done |
Objective
Node::physical_rect
divides the logical size of the node by the scale factor, when it should multiply.physical_size
method toNode
that calculates the physical size of a node.Changelog
physical_size
toNode
that calculates the physical size of theNode
based on the given scale factor.Node::physical_rect
method, the logical size should be multiplied by the scale factor to get the physical size.scale_value
function from thetext
widget module and replaced its usage withNode::physical_size
.Copy
forNode
(since it's only a wrappedVec2
).Node::size
const.