Feature: relative position helpers#2051
Feature: relative position helpers#2051DigiDuncan wants to merge 6 commits intopythonarcade:developmentfrom
Conversation
* Normalized -> fractional since we aren't clamping * Variable name and style tweaks (redundant parens can go)
Relative positions cleanup
| def absolute(self, fractional_pos: tuple[float, float]) -> tuple[float, float]: | ||
| """Convert a relative fractional pair to absolute screen pixels. | ||
|
|
||
| As in the rest of arcade and OpenGL, the default coordinate system | ||
| places the origin at the bottom left. | ||
|
|
||
| :param fractional_pos: A position where the x and y are fractional | ||
| values of the window size. | ||
| :returns: A tuple of absolute pixel X and Y relative to bottom left. | ||
| """ |
There was a problem hiding this comment.
This docstring just seems to academic and lacks contex/example. It's unclear what "fractional pair" is. Also unsure is the method name itself is clear.
| def relative(self, pixel_pos: tuple[float, float]) -> tuple[float, float]: | ||
| """Convert absolute screen pixels to a relative fractional pair. | ||
|
|
||
| :param pixel_pos: a tuple of X and Y pixel positions within the window. | ||
| :returns: A tuple of fractional X and Y relative to the bottom left. |
There was a problem hiding this comment.
This docstring just seems to academic and lacks contex/example. It's unclear what "fractional pair" is. Also unsure is the method name itself is clear.
|
If the idea here just being able to express/convert 0.0 -> 1.0 screen coordinates into pixel coordiantes regardless of aspect ratio? Is this really a common use case in arcade? I think this change lacks contex and more explanation. |
Yes. This is mainly for UI positioning or thing meant to be "pinned" to the sides of the windows. For example, if you have a 1280x720 window, and you want something in the dead center, It's based slightly off how Ren'Py handles positioning; it makes these calculations screen dimension-agnostic. |
TL;DR: Not just 0.0 to 1.0 since it's useful for OOB events When I asked Duncan about whether this is intentionally unclamped, he pointed out that it's intentional. I can see the value of this since values may fall outside window and other bboxes, especially during mouse drag events. This means "normalized" not quite right in my eyes. "Relative" is also too vague and misleading since it's not actually encoding the relative position to anything but the origin.
TL;DR: I think it would be if we built it out, especially for the UI Percent-like layout would be useful for general UI layout imo. I'm not sure of how to handle it from an API standpoint yet, but I see its consistent usefulness in CSS percent units. |
|
Definitely not againts it, but method names and docstrings are very vague. I had to actually read the code to even start understanding what the methods are about. A little more text and an
|
|
Let's close this for now and evaluate if we want something like this in 3.x |
Really basic relative position helpers for a Window.
Adds two functions,
relative()andabsolute(), which allow to convert to and from screenspace coordinates.Inspired by my adventures in Ren'Py.
If there's any issue with this, I apologize, my blood sugar is off today 😅