-
Notifications
You must be signed in to change notification settings - Fork 324
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
Encapsulate relative position logic in UITextInput.on_event #2327
base: development
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to use the new Rect
method.
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.
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