Skip to content

Commit

Permalink
Toggle switch now becomes blue when ON (rerun-io#6494)
Browse files Browse the repository at this point in the history
### What

Make it clearer when toggles are ON vs. OFF with some color.


![Export-1717515899832](https://github.com/rerun-io/rerun/assets/49431240/43538e36-72f1-49d0-b847-9ad6d1556bea)


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6494?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6494?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6494)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
abey79 authored Jun 7, 2024
1 parent 5a10357 commit fdf659e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1564,16 +1564,17 @@ checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30"
[[package]]
name = "ecolor"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"bytemuck",
"emath",
"serde",
]

[[package]]
name = "eframe"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ahash",
"bytemuck",
Expand Down Expand Up @@ -1609,7 +1610,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"accesskit",
"ahash",
Expand All @@ -1626,7 +1627,7 @@ dependencies = [
[[package]]
name = "egui-wgpu"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ahash",
"bytemuck",
Expand All @@ -1645,7 +1646,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"accesskit_winit",
"ahash",
Expand Down Expand Up @@ -1685,7 +1686,7 @@ dependencies = [
[[package]]
name = "egui_extras"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ahash",
"egui",
Expand All @@ -1701,7 +1702,7 @@ dependencies = [
[[package]]
name = "egui_glow"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ahash",
"bytemuck",
Expand All @@ -1719,7 +1720,7 @@ dependencies = [
[[package]]
name = "egui_plot"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ahash",
"egui",
Expand Down Expand Up @@ -1762,7 +1763,7 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "emath"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"bytemuck",
"serde",
Expand Down Expand Up @@ -1863,7 +1864,7 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.27.2"
source = "git+https://github.com/emilk/egui.git?rev=cbb5d6aa936c7498214dba03b594fbe75dbe7488#cbb5d6aa936c7498214dba03b594fbe75dbe7488"
source = "git+https://github.com/emilk/egui.git?rev=2545939c150379b85517de691da56a46f5ee0d1d#2545939c150379b85517de691da56a46f5ee0d1d"
dependencies = [
"ab_glyph",
"ahash",
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ missing_errors_doc = "allow"
# As a last resport, patch with a commit to our own repository.
# ALWAYS document what PR the commit hash is part of, or when it was merged into the upstream trunk.

ecolor = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
eframe = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
egui = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
egui_plot = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
emath = { git = "https://github.com/emilk/egui.git", rev = "cbb5d6aa936c7498214dba03b594fbe75dbe7488" } # egui master 2024-06-05
ecolor = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
eframe = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
egui = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
egui_plot = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06
emath = { git = "https://github.com/emilk/egui.git", rev = "2545939c150379b85517de691da56a46f5ee0d1d" } # egui master 2024-06-06

# Useful while developing:
# ecolor = { path = "../../egui/crates/ecolor" }
Expand Down
19 changes: 13 additions & 6 deletions crates/re_ui/src/ui_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,20 +876,27 @@ pub trait UiExt {
let how_on = ui.ctx().animate_bool(response.id, *on);
let visuals = ui.style().interact(&response);
let expanded_rect = visual_rect.expand(visuals.expansion);
let fg_fill = visuals.bg_fill;
let bg_fill = visuals.text_color();
let fg_fill_off = visuals.bg_fill;
let fg_fill_on = egui::Color32::from_rgba_premultiplied(0, 128, 255, 255);
let fg_fill = fg_fill_off.lerp_to_gamma(fg_fill_on, how_on);
let bg_fill_off = visuals.text_color();

let rounding = 0.5 * expanded_rect.height();
ui.painter()
.rect(expanded_rect, rounding, bg_fill, egui::Stroke::NONE);
.rect_filled(expanded_rect, rounding, bg_fill_off);
let circle_x = egui::lerp(
(expanded_rect.left() + rounding)..=(expanded_rect.right() - rounding),
how_on,
);

let circle_center = egui::pos2(circle_x, expanded_rect.center().y);
let circle_radius = 0.3 * expanded_rect.height();
ui.painter()
.circle(circle_center, circle_radius, fg_fill, egui::Stroke::NONE);
let circle_radius_off = 0.3 * expanded_rect.height();
let circle_radius_on = 0.35 * expanded_rect.height();
ui.painter().circle_filled(
circle_center,
egui::lerp(circle_radius_off..=circle_radius_on, how_on),
fg_fill,
);
}

response
Expand Down

0 comments on commit fdf659e

Please sign in to comment.