Skip to content
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

Add Options::input_options for click-delay etc #4942

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

girtsf
Copy link
Contributor

@girtsf girtsf commented Aug 9, 2024

This takes 3 hardcoded constants from input_state.rs and puts them in a InputOptions struct that then gets added to Options. This allows adjusting these values at runtime, for example, to increase MAX_CLICK_DIST for touchscreen usage.

  • I have followed the instructions in the PR template

@girtsf
Copy link
Contributor Author

girtsf commented Aug 9, 2024

Background on the PR: I'm working on a UI for a touchscreen device and I've found that the default MAX_CLICK_DIST of 6 pixels doesn't work well - most finger taps will "slide" on the screen more than 6 pixels and thus won't register as clicks. Setting the value to a higher number makes the interface less finicky.

Thoughts on this? I don't quite like that I had to stash InputOptions in PointerState and InputState so that functions such as wants_repaint_after and is_long_press can do their calculations. Better ideas? Or is this acceptable?

(Maybe outside the scope of this PR, but maybe we could consider separate config values for mouse vs touch? The latter is much less precise. From a quick glance, this would require changing some of the plumbing that translates touch events into PointerButton events.)

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach better than the alternative in #4986

Comment on lines 863 to 864
/// Input state management configuration.
input_options: InputOptions,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should note here that this is copied from egui::Options at the start of each frame, and is only here for convenience

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know if you think Arc would be a better solution here. Currently it's just a couple of floats, so performance wise it might be a wash between Arc and copying the floats.

This takes 3 hardcoded constants from `input_state.rs` and puts them in
a `InputOptions` struct that then gets added to `Options`. This allows
adjusting these values at runtime, for example, to increase
`MAX_CLICK_DIST` for touchscreen usage.
@girtsf girtsf marked this pull request as ready for review September 4, 2024 19:08
@emilk emilk added feature New feature or request egui labels Sep 5, 2024
@emilk emilk changed the title Break out input_state constants into settings Add Options::input_options for click-delay etc Sep 5, 2024
@emilk emilk merged commit f741529 into emilk:master Sep 5, 2024
21 of 22 checks passed
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
This takes 3 hardcoded constants from `input_state.rs` and puts them in
a `InputOptions` struct that then gets added to `Options`. This allows
adjusting these values at runtime, for example, to increase
`MAX_CLICK_DIST` for touchscreen usage.

* [x] I have followed the instructions in the PR template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants