Skip to content

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

Merged
emilk merged 2 commits into
emilk:masterfrom
girtsf:girtsf/input-options
Sep 5, 2024
Merged

emilk merged 2 commits into
emilk:masterfrom
girtsf:girtsf/input-options

Conversation

@girtsf

@girtsf girtsf commented Aug 9, 2024

Copy link
Copy Markdown
Contributor

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

girtsf commented Aug 9, 2024

Copy link
Copy Markdown
Contributor Author

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.)

@emilk emilk left a comment

Copy link
Copy Markdown
Owner

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
Copy Markdown
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
Copy Markdown
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 force-pushed the girtsf/input-options branch from d2b52f6 to 0e36e62 Compare September 4, 2024 18:51
@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
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