-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Theme Switch Widget #4805
Add Theme Switch Widget #4805
Conversation
I forgot to mention that I'd be happy to split this up into smaller PRs if needed :) Some individual parts that could be extracted:
|
Just curious, how did you obtain the current system theme in egui? |
@AurevoirXavier egui itself currently doesn't know about the system theme. It relies on The way that the switch widget currently recognizes dark vs. light mode is by checking If you want to know the system theme and are using eframe then you can get |
This is a very pretty theme selector, but I worry it is a bit overkill for the default one in egui for several reasons: A) it adds a lot of code to maintain I suggest you create this as a 3rd party crate instead, and for egui make a much simpler drop-down menu. |
Thank you for the kind words I totally understand the reasoning behind not wanting this in egui itself. Time for Would you be interested in upstreaming some of the following things from this PR (as individual PRs of course):
|
I agree with this. To be honest, I ask that question because I want one for my app, but in a combobox. This one feels a bit overkill for my app. (just as @emilk mentioned, it's too pretty and will look out of place in my poor UI) |
I'm closing this as I have published a crate for this and extracted the "salvageable" parts into two separate PRs. |
Extracted out of #4805 I'm using this widget type in [`egui-theme-switch`] but since it's not built in I have to call `accesskit_node_builder` which is a bit cumbersome :) * [x] I have followed the instructions in the PR template [`egui-theme-switch`]: https://github.com/bash/egui-theme-switch/blob/main/src/lib.rs
Extracted out of #4805 In [`egui-theme-switch`] I'm allocating a response inside the closure passed to `with_accessibility_parent` so that my radio buttons have the radio group as parent. I'm working around the lack of return value with a custom extension trait for now: [`ContextExt`] * [x] I have followed the instructions in the PR template [`egui-theme-switch`]: https://github.com/bash/egui-theme-switch/blob/main/src/lib.rs [`ContextExt`]: https://github.com/bash/egui-theme-switch/blob/main/src/context_ext.rs
Extracted out of emilk#4805 I'm using this widget type in [`egui-theme-switch`] but since it's not built in I have to call `accesskit_node_builder` which is a bit cumbersome :) * [x] I have followed the instructions in the PR template [`egui-theme-switch`]: https://github.com/bash/egui-theme-switch/blob/main/src/lib.rs
Extracted out of emilk#4805 In [`egui-theme-switch`] I'm allocating a response inside the closure passed to `with_accessibility_parent` so that my radio buttons have the radio group as parent. I'm working around the lack of return value with a custom extension trait for now: [`ContextExt`] * [x] I have followed the instructions in the PR template [`egui-theme-switch`]: https://github.com/bash/egui-theme-switch/blob/main/src/lib.rs [`ContextExt`]: https://github.com/bash/egui-theme-switch/blob/main/src/context_ext.rs
I got a juust a bit sidetracked while working on #4490 because I realized that the global dark/light mode toggle would be missing a "follow system" option.
My solution is a custom switch widget with three options: follow system, dark and light.
(follow system is disabled for now but is supported by the widget)
The icons are hand-drawn because:
I tested the widget on my Mac with VoiceOver on to ensure that the widget is announced as
Theme, radio group
and each radio button is announced as<label>, <n> out of 3
.The widget and the accompanying
ThemePreference
type are bothpub(crate)
for now, but I intend to make them public in #4744.