Encapsulate relative position logic in UITextInput.on_event#2327
Encapsulate relative position logic in UITextInput.on_event#2327pushfoo wants to merge 5 commits intodevelopmentfrom
Conversation
pushfoo
commented
Jul 29, 2024
- Add relative position helpers
- Use position helpers to clean up UITextInput.on_event
- Some light refactoring for readability
- Improve related docstrings and comments
* Add UIWidget._event_pos_relative_to_self * Add UITextInput._event_pos_relative_to_self * Use new method to clean up UITextInput.on_event
* Use self._event_pos_relative_to_self * Restructure it to put the type check * Add comments explaining when / why things are handled
* Use inside_xy in the lower block as well * Improve UITextInput.on_event docstring + comments
|
@DigiDuncan Let me know if the relative position helper seems to belong in |
| def _event_pos_relative_to_self(self, mouse_event: UIMouseEvent) -> Vec2 | None: | ||
| """Gets coords relative to bottom left if inside the widget. | ||
|
|
||
| Args: | ||
| mouse_event: Any :py:class:`UIMouseEvent`. | ||
| Returns: | ||
| ``None`` if outside the widget or coords relative to | ||
| the widget's bottom left. | ||
| """ | ||
| pos = mouse_event.pos | ||
| if not self.rect.point_in_rect(pos): | ||
| return None | ||
| return Vec2(pos[0] - self.left, pos[1] - self.bottom) | ||
|
|
There was a problem hiding this comment.
Update to use the new Rect method.
There was a problem hiding this comment.
I didn't update it yet because I want to give it more thought after rereading the UI code and considering the following:
- 3.9 features will be our new minimum
- The new rect method seems to perform more ops
- It may add even more call overhead
|
Hi, I am unsure about the state of the changes, due to the conflicts and the lag of an open issue, I would maybe close this PR? |
This thing was an exploratory kludge. I want to review your recent UI event proposals for controllers before attempting this + thoroughly review
|