Skip to content

Commit 04bb859

Browse files
authored
Tweak light mode colors (#10013)
### Related * Part of #9953 ### What Add specific light mode colors for: * bread crumbs * blueprint time panel * loop selection * loop-all button
1 parent 77dbc99 commit 04bb859

File tree

6 files changed

+66
-37
lines changed

6 files changed

+66
-37
lines changed

crates/viewer/re_selection_panel/src/item_heading_with_breadcrumbs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ pub fn item_heading_with_breadcrumbs(
5151

5252
// First the C>R>U>M>B>S>
5353
{
54+
let breadcrumb_text_color = ui.design_tokens().breadcrumb_text_color();
5455
let previous_style = ui.style().clone();
5556
// Dimmer colors for breadcrumbs
5657
let visuals = ui.visuals_mut();
57-
visuals.widgets.inactive.fg_stroke.color = egui::hex_color!("#6A8CD0"); // TODO(#3133): use design tokens
58+
visuals.widgets.inactive.fg_stroke.color = breadcrumb_text_color;
5859
item_bread_crumbs_ui(ctx, viewport, ui, item);
5960
ui.set_style(previous_style);
6061
}
@@ -251,7 +252,7 @@ pub fn separator_icon_ui(ui: &mut egui::Ui) {
251252
ui.add(
252253
icons::BREADCRUMBS_SEPARATOR
253254
.as_image()
254-
.tint(ui.visuals().text_color().gamma_multiply(0.65)),
255+
.tint(ui.design_tokens().breadcrumb_separator_color()),
255256
);
256257
}
257258

crates/viewer/re_time_panel/src/time_control_ui.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ You can also define your own timelines, e.g. for sensor time or camera frame num
195195
}
196196
}
197197
Looping::All => {
198-
ui.visuals_mut().selection.bg_fill =
199-
re_ui::DesignTokens::loop_everything_color();
198+
ui.visuals_mut().selection.bg_fill = ui.design_tokens().loop_everything_color();
200199
if ui
201200
.large_button_selected(icon, true)
202201
.on_hover_text("Looping entire recording")

crates/viewer/re_time_panel/src/time_selection_ui.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use egui::{CursorIcon, Id, NumExt as _, Rect};
22

33
use re_log_types::{Duration, ResolvedTimeRangeF, TimeInt, TimeReal, TimeType};
4+
use re_ui::UiExt as _;
45
use re_viewer_context::{Looping, TimeControl};
56

67
use super::time_ranges_ui::TimeRangesUi;
@@ -26,9 +27,11 @@ pub fn loop_selection_ui(
2627
let is_active = time_ctrl.looping() == Looping::Selection;
2728

2829
let selection_color = if is_active {
29-
re_ui::DesignTokens::loop_selection_color().gamma_multiply(0.7)
30+
ui.design_tokens().loop_selection_color()
3031
} else {
31-
re_ui::DesignTokens::loop_selection_color().gamma_multiply(0.5)
32+
ui.design_tokens()
33+
.loop_selection_color()
34+
.gamma_multiply(0.7)
3235
};
3336

3437
let pointer_pos = ui.input(|i| i.pointer.hover_pos());

crates/viewer/re_ui/src/design_token_colors.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(clippy::unwrap_used)]
22
#![allow(clippy::enum_glob_use)] // Nice to have for the color variants
33

4-
use egui::{Color32, Theme};
4+
use egui::{Color32, Theme, hex_color};
55

66
use crate::{
77
DesignTokens,
@@ -61,13 +61,19 @@ impl DesignTokens {
6161
}
6262

6363
/// The color we use to mean "loop this selection"
64-
pub fn loop_selection_color() -> Color32 {
65-
Color32::from_rgb(1, 37, 105) // from figma 2023-02-09
64+
pub fn loop_selection_color(&self) -> Color32 {
65+
match self.theme {
66+
Theme::Dark => hex_color!("#012569B2"),
67+
Theme::Light => hex_color!("#6386C9B2"),
68+
}
6669
}
6770

6871
/// The color we use to mean "loop all the data"
69-
pub fn loop_everything_color() -> Color32 {
70-
Color32::from_rgb(2, 80, 45) // from figma 2023-02-09
72+
pub fn loop_everything_color(&self) -> Color32 {
73+
match self.theme {
74+
Theme::Dark => Color32::from_rgb(2, 80, 45), // from figma 2023-02-09
75+
Theme::Light => hex_color!("#06A35C"),
76+
}
7177
}
7278

7379
/// Used by the "add view or container" modal.
@@ -86,6 +92,27 @@ impl DesignTokens {
8692
}
8793
}
8894

95+
pub fn breadcrumb_text_color(&self) -> Color32 {
96+
match self.theme {
97+
Theme::Dark => egui::hex_color!("#6A8CD0"),
98+
Theme::Light => self.color(ColorToken::blue(S300)),
99+
}
100+
}
101+
102+
pub fn breadcrumb_separator_color(&self) -> Color32 {
103+
match self.theme {
104+
Theme::Dark => self.color(ColorToken::blue(S500)),
105+
Theme::Light => self.color(ColorToken::blue(S400)),
106+
}
107+
}
108+
109+
pub fn blueprint_time_panel_bg_fill(&self) -> Color32 {
110+
match self.theme {
111+
Theme::Dark => egui::hex_color!("#141326"),
112+
Theme::Light => self.color(ColorToken::blue(S900)),
113+
}
114+
}
115+
89116
/// Color for notification panel background
90117
pub fn notification_panel_background_color(&self) -> Color32 {
91118
match self.theme {

crates/viewer/re_ui/src/design_tokens.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use crate::{
1616
#[derive(Debug)]
1717
pub struct DesignTokens {
1818
pub theme: egui::Theme,
19-
pub json: serde_json::Value,
19+
20+
typography: Typography,
2021

2122
/// Color table for all colors used in the UI.
2223
///
2324
/// Loaded at startup from `design_tokens.json`.
2425
pub(crate) color_table: ColorTable, // Not public, because all colors should go via design_token_colors.rs
2526

26-
// TODO(ab): get rid of these, they should be function calls like the rest.
27+
// TODO(ab): get rid of these, they should be function calls in design_token_colors.rs like the rest.
2728
pub top_bar_color: Color32,
2829
pub bottom_bar_color: Color32,
2930
pub bottom_bar_stroke: egui::Stroke,
@@ -36,16 +37,27 @@ pub struct DesignTokens {
3637
impl DesignTokens {
3738
/// Load design tokens from `data/design_tokens_*.json`.
3839
pub fn load(theme: Theme) -> Self {
39-
match theme {
40+
let json: serde_json::Value = match theme {
4041
egui::Theme::Dark => {
41-
let json: serde_json::Value =
42-
serde_json::from_str(include_str!("../data/design_tokens_dark.json"))
43-
.expect("Failed to parse data/design_tokens_dark.json");
42+
serde_json::from_str(include_str!("../data/design_tokens_dark.json"))
43+
.expect("Failed to parse data/design_tokens_dark.json")
44+
}
45+
46+
egui::Theme::Light => {
47+
serde_json::from_str(include_str!("../data/design_tokens_light.json"))
48+
.expect("Failed to parse data/design_tokens_light.json")
49+
}
50+
};
4451

45-
let color_table = load_color_table(&json);
52+
let typography: Typography = get_alias(&json, "{Alias.Typography.Default.value}");
4653

54+
let color_table = load_color_table(&json);
55+
56+
match theme {
57+
egui::Theme::Dark => {
4758
Self {
4859
theme,
60+
typography,
4961
top_bar_color: color_table.gray(S100),
5062
bottom_bar_color: color_table.gray(S150),
5163
bottom_bar_stroke: egui::Stroke::new(1.0, color_table.gray(S250)),
@@ -58,19 +70,13 @@ impl DesignTokens {
5870
shadow_gradient_dark_start: Color32::from_black_alpha(77), //TODO(ab): use ColorToken!
5971
tab_bar_color: color_table.gray(S200),
6072
native_frame_stroke: egui::Stroke::new(1.0, color_table.gray(S250)),
61-
json,
6273
color_table,
6374
}
6475
}
6576
egui::Theme::Light => {
66-
let json: serde_json::Value =
67-
serde_json::from_str(include_str!("../data/design_tokens_light.json"))
68-
.expect("Failed to parse data/design_tokens_light.json");
69-
70-
let color_table = load_color_table(&json);
71-
7277
Self {
7378
theme,
79+
typography,
7480
top_bar_color: color_table.gray(S800),
7581
bottom_bar_color: color_table.gray(S950),
7682
bottom_bar_stroke: egui::Stroke::new(1.0, color_table.gray(S800)),
@@ -83,7 +89,6 @@ impl DesignTokens {
8389
shadow_gradient_dark_start: Color32::from_black_alpha(10), //TODO(ab): use ColorToken!
8490
tab_bar_color: color_table.gray(S900),
8591
native_frame_stroke: egui::Stroke::new(1.0, color_table.gray(S250)),
86-
json,
8792
color_table,
8893
}
8994
}
@@ -110,11 +115,8 @@ impl DesignTokens {
110115
}
111116

112117
pub(crate) fn set_fonts(&self, ctx: &egui::Context) {
113-
let typography_default: Typography =
114-
get_alias(&self.json, "{Alias.Typography.Default.value}");
115-
116-
assert_eq!(typography_default.fontFamily, "Inter");
117-
assert_eq!(typography_default.fontWeight, "Medium");
118+
assert_eq!(self.typography.fontFamily, "Inter");
119+
assert_eq!(self.typography.fontWeight, "Medium");
118120
let mut font_definitions = egui::FontDefinitions::default();
119121
font_definitions.font_data.insert(
120122
"Inter-Medium".into(),
@@ -131,10 +133,7 @@ impl DesignTokens {
131133
}
132134

133135
fn set_text_styles(&self, egui_style: &mut egui::Style) {
134-
let typography_default: Typography =
135-
get_alias(&self.json, "{Alias.Typography.Default.value}");
136-
137-
let font_size = parse_px(&typography_default.fontSize);
136+
let font_size = parse_px(&self.typography.fontSize);
138137

139138
for text_style in [
140139
egui::TextStyle::Body,
@@ -609,7 +608,7 @@ fn follow_path<'json>(
609608
// ----------------------------------------------------------------------------
610609

611610
#[allow(non_snake_case)]
612-
#[derive(serde::Deserialize)]
611+
#[derive(Debug, serde::Deserialize)]
613612
struct Typography {
614613
fontSize: String,
615614
fontWeight: String,

crates/viewer/re_viewer/src/app_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl AppState {
467467
// Give the blueprint time panel a distinct color from the normal time panel:
468468
ui.design_tokens()
469469
.bottom_panel_frame()
470-
.fill(egui::hex_color!("#141326")),
470+
.fill(ui.design_tokens().blueprint_time_panel_bg_fill()),
471471
);
472472

473473
{

0 commit comments

Comments
 (0)