Skip to content

Add ComputedNode.logical_size() method #17462

Open
@viridia

Description

What problem does this solve or what need does it fill?

When dragging, we often need to compute the relative position of the mouse pointer based on the width and height of the widget. However, node.size() returns the physical size, not the logical size of the entity. This means that the node size and the mouse position are in different units if the window scale factor is not 1.

Fortunately, the node contains an inverse_scale_factor property, so getting the logical size is trivial: multiply the physical size by inverse_scale_factor. However, new users may not realize that they need to do this multiplication, especially if they are developing on a window system with a scale factor of 1.

What solution would you like?

Add a logical_size() method to ComputedNode which simply returns the size * inverse_scale_factor.

Additional context

This is a super-trivial addition, and would be a great starter task for a novice user who is looking for a way to get started hacking on Bevy.

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-FeatureA new feature, making something new possibleD-TrivialNice and easy! A great choice to get started with BevyS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions