Skip to content

Commit ec62ad9

Browse files
emilkMichaelGrupp
authored andcommitted
Make labels in spatial view translucent
## After <img width="238" height="193" alt="image" src="https://github.com/user-attachments/assets/e2ec234d-c17f-4ed7-abce-c782854ec992" /> <img width="208" height="166" alt="image" src="https://github.com/user-attachments/assets/cca7a353-6bcd-43de-a240-ae75163aa95a" /> <img width="373" height="173" alt="image" src="https://github.com/user-attachments/assets/88ab0ae2-0ef8-48fa-a0c1-3719043235ad" /> <img width="188" height="162" alt="image" src="https://github.com/user-attachments/assets/cae245f9-fb9a-4144-95cc-62071cadaaae" /> ## Before The labels would cover the actual data <img width="358" height="236" alt="image" src="https://github.com/user-attachments/assets/4577ec96-da78-4c19-8f34-919ae3def378" /> <img width="225" height="156" alt="image" src="https://github.com/user-attachments/assets/1c67d5c3-4da3-464e-8bde-2ba5f7586629" /> <img width="515" height="214" alt="image" src="https://github.com/user-attachments/assets/454298e4-bc86-48d4-918e-c9fae5bc89d4" /> Source-Ref: 5904b3167ca4a833a9a52b65e1e161785869c7f7
1 parent 51506ca commit ec62ad9

19 files changed

+51
-41
lines changed

crates/viewer/re_ui/data/dark_theme.ron

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"modal_button_width": 50,
77
"default_modal_width": 400,
88

9+
"spatial_label_bg_opacity": 0.5,
10+
911
"loop_selection_alpha": 0.55, // Multiplied with selection_bg_fill
1012
"loop_selection_alpha_inactive": 0.20, // Multiplied with selection_bg_fill
1113

crates/viewer/re_ui/data/light_theme.ron

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"modal_button_width": 50,
77
"default_modal_width": 400,
88

9+
"spatial_label_bg_opacity": 0.5,
10+
911
"loop_selection_alpha": 0.55, // Multiplied with selection_bg_fill
1012
"loop_selection_alpha_inactive": 0.20, // Multiplied with selection_bg_fill
1113

crates/viewer/re_ui/src/design_tokens.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub struct DesignTokens {
7676
pub success_text_color: Color32,
7777
pub info_text_color: Color32,
7878

79+
/// Opacity multiplier for the background of 2D labels in spatial views.
80+
pub spatial_label_bg_opacity: f32,
81+
7982
/// Background color for viewport views.
8083
pub viewport_background: Color32,
8184

@@ -287,6 +290,8 @@ impl DesignTokens {
287290
success_text_color: get_color("success_text_color"),
288291
info_text_color: get_color("info_text_color"),
289292

293+
spatial_label_bg_opacity: get_scalar("spatial_label_bg_opacity")?,
294+
290295
viewport_background: get_color("viewport_background"),
291296

292297
highlight_color: get_color("highlight_color"),

crates/viewer/re_view_spatial/src/ui.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,26 @@ pub fn create_labels(
215215
for label in labels {
216216
let (wrap_width, text_anchor_pos) = match label.target {
217217
UiLabelTarget::Rect(rect) => {
218-
// TODO(#1640): 2D labels are not visible in 3D for now.
219218
if spatial_kind == SpatialViewKind::ThreeD {
220-
continue;
219+
continue; // TODO(#1640): 2D labels are not visible in 3D for now.
221220
}
222221
let rect_in_ui = ui_from_scene.transform_rect(rect);
223222
(
224223
// Place the text centered below the rect
225224
(rect_in_ui.width() - 4.0).at_least(60.0),
226-
rect_in_ui.center_bottom() + egui::vec2(0.0, 3.0),
225+
rect_in_ui.center_bottom(),
227226
)
228227
}
229228
UiLabelTarget::Point2D(pos) => {
230-
// TODO(#1640): 2D labels are not visible in 3D for now.
231229
if spatial_kind == SpatialViewKind::ThreeD {
232-
continue;
230+
continue; // TODO(#1640): 2D labels are not visible in 3D for now.
233231
}
234232
let pos_in_ui = ui_from_scene.transform_pos(pos);
235-
(f32::INFINITY, pos_in_ui + egui::vec2(0.0, 3.0))
233+
(f32::INFINITY, pos_in_ui)
236234
}
237235
UiLabelTarget::Position3D(pos) => {
238-
// TODO(#1640): 3D labels are not visible in 2D for now.
239236
if spatial_kind == SpatialViewKind::TwoD {
240-
continue;
237+
continue; // TODO(#1640): 3D labels are not visible in 2D for now.
241238
}
242239
let pos_in_ui = ui_from_world_3d * pos.extend(1.0);
243240
if pos_in_ui.w <= 0.0 {
@@ -277,9 +274,10 @@ pub fn create_labels(
277274
})
278275
});
279276

280-
let text_rect = egui::Align2::CENTER_TOP
281-
.anchor_rect(egui::Rect::from_min_size(text_anchor_pos, galley.size()));
282-
let bg_rect = text_rect.expand2(egui::vec2(4.0, 2.0));
277+
let offset = egui::vec2(0.0, 5.0); // Add some margin
278+
let text_rect =
279+
egui::Align2::CENTER_TOP.anchor_size(text_anchor_pos + offset, galley.size());
280+
let bg_rect = text_rect.expand2(egui::vec2(2.0, 0.0));
283281

284282
let highlight = highlights
285283
.entity_highlight(label.labeled_instance.entity_path_hash)
@@ -301,6 +299,9 @@ pub fn create_labels(
301299
HoverHighlight::Hovered => parent_ui.style().visuals.widgets.hovered.bg_fill,
302300
};
303301

302+
let background_color =
303+
background_color.gamma_multiply(parent_ui.tokens().spatial_label_bg_opacity);
304+
304305
let rect_stroke = if is_error {
305306
egui::Stroke::new(1.0, parent_ui.style().visuals.error_fg_color)
306307
} else {
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)