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

Toggle Button created using Slider #4310

Closed
wants to merge 36 commits into from
Closed

Conversation

rustbasic
Copy link
Contributor

@rustbasic rustbasic commented Apr 2, 2024

Toggle Button created using Slider.

20240404-1

@rustbasic rustbasic closed this Apr 2, 2024
@rustbasic rustbasic reopened this Apr 2, 2024
@DataTriny
Copy link
Contributor

Hi @rustbasic

What you are proposing here is not a toggle button but a switch. Semantically speaking, egui already has support for toggle buttons.

From an accessibility point of view, this new widget would be very confusing as is because:

  • right now it is exposed to assistive technologies as a slider even though it should be reported as a Switch and have its Checked state set accordingly. Typical properties that make sense for a slider such as numeric_value, min_numeric_value, max_numeric_value, numeric_value_step and numeric_value_jump would have to be disabled.
  • It should be possible to toggle the switch by pressing the space bar (maybe the slider already offers that?)
  • It should be possible to toggle the switch by just clicking (not dragging the mouse) (maybe the slider already offers that?)
  • The color of the widget would have to be different depending on the state otherwise it is hard to understand the meaning for people who rely less on their vision.
  • Key pressed that make sense for sliders (e.g. arrows, home/end...) would have to be disabled.

I'll let @emilk decide whether using the slider as a building block for a switch is a good idea or not, but there is more in a switch than just being able to slide something from left to right. A switch is semantically closer to a check box.

@rustbasic
Copy link
Contributor Author

rustbasic commented Apr 4, 2024

@DataTriny

Thank you for review.

It seems like it was written without use.
Please try it and let me know what specific changes need to be made.

For example,
you can change things with just a click rather than dragging.
Change the selected value like a checkbox.
The color is changeable ui.visuals_mut().slider_trailing_fill

@YgorSouza
Copy link
Contributor

There is already a toggle switch implementation in the demo app. It is provided as an example of how users can write their own widgets. If egui were to have a toggle switch widget, it would probably be implemented like this. But currently anyone who needs it can just copy those 20 lines of code, and then customize it if they want.

@rustbasic
Copy link
Contributor Author

There is already a toggle switch implementation in the demo app. It is provided as an example of how users can write their own widgets. If egui were to have a toggle switch widget, it would probably be implemented like this. But currently anyone who needs it can just copy those 20 lines of code, and then customize it if they want.

Yes, this is just to provide it in an easier and simpler way.

@emilk
Copy link
Owner

emilk commented Apr 21, 2024

As DataTrinity pointed out, this is a bad way of implementing a toggle switch.

At some point I'd like to have a global option to show checkboxes as toggle switches, i.e. like a styling option. But this PR is not it.

@emilk emilk closed this Apr 21, 2024
@rustbasic
Copy link
Contributor Author

As DataTrinity pointed out, this is a bad way of implementing a toggle switch.

At some point I'd like to have a global option to show checkboxes as toggle switches, i.e. like a styling option. But this PR is not it.

Okay. I thought it would be better to have something simple to implement rather than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants