bevyengine / bevyengine/bevy

Add ComputedNode.logical_size() method

Open
#17,462 2 comments 3 reactions 0 assignees View on GitHub
A-UI C-Feature D-Trivial S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.