Remove `Option` from any cursor position API
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
I'm trying to write a simple UI for some example. Nothing fancy. I keep hitting a wall against all the cursor position APIs returning an `Option`.
1. Why is `None` ever possible? This is documented nowhere. What does it ever mean to get an `Interaction::Clicked` with a `None` mouse cursor position?
2. It's extremely annoying to have to deal with `None`. This leaks into all code dealing with UI: button click, drag and drop, _etc._ and there's no good behavior to assign to it.
## What solution would you like?
Remove the `Option` from all those APIs, just use `Vec2` directly. If there's really a case where the mouse cursor position is not available, document why and possibly add an escape hatch for handling that, our try our best guess to find a position anyway.
## What alternative(s) have you considered?
User has to wrap all APIs into their own helper function(s) to safely unwrap that `Option` or find a default based on the (primary) window and other factors, which systematically adds several queries to all systems and is far from trivial (see Additional context).
## Additional context
- `Interaction` has no cursor information on click
- `RelativeCursorPosition` stores an `Option` but it's unused for cases where the cursor is outside the widget, which would be the only case where I find this would make sense.
- It's unclear how you get the current window where the interaction occurred (vs. the primary one) to be able to retrieve its position and cursor position.
Contributor guide
Research direction
Start by auditing the cursor position APIs, including Interaction and RelativeCursorPosition, and determine when a cursor position can be unavailable. Review the issue's examples of click and drag-and-drop handling. Done means the API consistently uses Vec2 or documents and provides a deliberate alternative for cases where no position exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100