Skip to content

Improve error message style slightly #8092

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

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/viewer/re_chunk_store_ui/src/arrow_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ pub(crate) fn arrow_ui(ui: &mut egui::Ui, array: &dyn arrow2::array::Array) {
let mut string = String::new();
match display(&mut string, 0) {
Ok(_) => ui.monospace(&string),
Err(err) => ui.error_with_details_on_hover("error").on_hover_ui(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
ui.error_with_details_on_hover(&format!("{err}"));
}),
Err(err) => ui.error_with_details_on_hover(&err.to_string()),
};
return;
} else {
Expand Down
4 changes: 1 addition & 3 deletions crates/viewer/re_chunk_store_ui/src/chunk_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ impl ChunkUi {
crate::arrow_ui::arrow_ui(ui, &*data);
}
Some(Err(err)) => {
ui.error_with_details_on_hover("error").on_hover_ui(|ui| {
ui.label(format!("{err}"));
});
ui.error_with_details_on_hover(&err.to_string());
}
None => {
ui.weak("-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn display_text_ui(
let text = match Text::from_arrow(data) {
Ok(text) => text.first().cloned(),
Err(err) => {
ui.error_with_details_on_hover("failed to deserialize")
ui.error_label("Failed to deserialize")
.on_hover_text(err.to_string());
return;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn display_name_ui(
let name = match Name::from_arrow(data) {
Ok(name) => name.first().cloned(),
Err(err) => {
ui.error_with_details_on_hover("failed to deserialize")
ui.error_label("Failed to deserialize")
.on_hover_text(err.to_string());
return;
}
Expand Down
5 changes: 3 additions & 2 deletions crates/viewer/re_data_ui/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ pub fn show_video_blob_info(
// See also `MediaTypeIsNotAVideo` case above.
}
Err(err) => {
let error_message = format!("Failed to load video: {err}");
if ui_layout.is_single_line() {
ui.error_with_details_on_hover(&format!("Failed to load video: {err}"));
ui.error_with_details_on_hover(&error_message);
} else {
ui.error_label(&format!("Failed to load video: {err}"));
ui.error_label(&error_message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_selection_panel/src/visualizer_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn visualizer_ui(
.lookup_result_by_path(entity_path)
.cloned()
else {
ui.error_with_details_on_hover("Entity not found in view.");
ui.error_label("Entity not found in view");
return;
};
let active_visualizers: Vec<_> = data_result.visualizers.iter().sorted().copied().collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl DisplayColumn {
ui.label(timeline.typ().format(timestamp, ctx.app_options.time_zone));
}
Err(err) => {
ui.error_with_details_on_hover(&format!("{err}"));
ui.error_with_details_on_hover(&err.to_string());
}
}
} else {
Expand Down
20 changes: 13 additions & 7 deletions crates/viewer/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use re_types::{
archetypes::Pinhole, blueprint::components::VisualBounds2D, components::ViewCoordinates,
image::ImageKind,
};
use re_ui::UiExt as _;
use re_ui::{ContextExt as _, UiExt as _};
use re_viewer_context::{
HoverHighlight, SelectionHighlight, SpaceViewHighlights, SpaceViewState, ViewerContext,
};
Expand All @@ -18,7 +18,7 @@ use crate::{
picking::{PickableUiRect, PickingResult},
scene_bounding_boxes::SceneBoundingBoxes,
view_kind::SpatialSpaceViewKind,
visualizers::{SpatialViewVisualizerData, UiLabel, UiLabelTarget},
visualizers::{SpatialViewVisualizerData, UiLabel, UiLabelStyle, UiLabelTarget},
};

use super::{eye::Eye, ui_3d::View3DState};
Expand Down Expand Up @@ -214,13 +214,19 @@ pub fn create_labels(
};

let font_id = egui::TextStyle::Body.resolve(parent_ui.style());
let format = match label.style {
UiLabelStyle::Color(color) => egui::TextFormat::simple(font_id, color),
UiLabelStyle::Error => parent_ui.ctx().error_text_format(),
};
let text_color = format.color;

let galley = parent_ui.fonts(|fonts| {
fonts.layout_job({
egui::text::LayoutJob {
sections: vec![egui::text::LayoutSection {
leading_space: 0.0,
byte_range: 0..label.text.len(),
format: egui::TextFormat::simple(font_id, label.color),
format,
}],
text: label.text.clone(),
wrap: TextWrapping {
Expand All @@ -241,9 +247,9 @@ pub fn create_labels(
let highlight = highlights
.entity_highlight(label.labeled_instance.entity_path_hash)
.index_highlight(label.labeled_instance.instance);
let fill_color = match highlight.hover {
let background_color = match highlight.hover {
HoverHighlight::None => match highlight.selection {
SelectionHighlight::None => parent_ui.style().visuals.widgets.inactive.bg_fill,
SelectionHighlight::None => parent_ui.style().visuals.panel_fill,
SelectionHighlight::SiblingSelection => {
parent_ui.style().visuals.widgets.active.bg_fill
}
Expand All @@ -252,11 +258,11 @@ pub fn create_labels(
HoverHighlight::Hovered => parent_ui.style().visuals.widgets.hovered.bg_fill,
};

label_shapes.push(egui::Shape::rect_filled(bg_rect, 3.0, fill_color));
label_shapes.push(egui::Shape::rect_filled(bg_rect, 3.0, background_color));
label_shapes.push(egui::Shape::galley(
text_rect.center_top(),
galley,
label.color,
text_color,
));

ui_rects.push(PickableUiRect {
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_space_view_spatial/src/visualizers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use depth_images::DepthImageVisualizer;
pub use transform3d_arrows::{add_axis_arrows, AxisLengthDetector, Transform3DArrowsVisualizer};
pub use utilities::{
entity_iterator, process_labels_3d, textured_rect_from_image, SpatialViewVisualizerData,
UiLabel, UiLabelTarget,
UiLabel, UiLabelStyle, UiLabelTarget,
};

/// Shows a loading animation in a spatial view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@ pub enum UiLabelTarget {
Position3D(glam::Vec3),
}

#[derive(Clone)]
pub enum UiLabelStyle {
Color(egui::Color32),

/// Style it like an error message
Error,
}

impl From<egui::Color32> for UiLabelStyle {
fn from(color: egui::Color32) -> Self {
Self::Color(color)
}
}

#[derive(Clone)]
pub struct UiLabel {
pub text: String,
pub color: egui::Color32,

pub style: UiLabelStyle,

/// The shape/position being labeled.
pub target: UiLabelTarget,
Expand Down Expand Up @@ -181,7 +196,7 @@ pub fn process_labels<'a, P: 'a>(
.filter_map(move |(i, (position, label, color))| {
label.map(|label| UiLabel {
text: label,
color: *color,
style: (*color).into(),
target: target_from_position(position),
labeled_instance: InstancePathHash::instance(
entity_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod textured_rect;

pub use labels::{
process_labels, process_labels_2d, process_labels_3d, show_labels_fallback, LabeledBatch,
UiLabel, UiLabelTarget,
UiLabel, UiLabelStyle, UiLabelTarget,
};
pub use proc_mesh_vis::{ProcMeshBatch, ProcMeshDrawableBuilder};
pub use spatial_view_visualizer::SpatialViewVisualizerData;
Expand Down
5 changes: 3 additions & 2 deletions crates/viewer/re_space_view_spatial/src/visualizers/videos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use crate::{
};

use super::{
entity_iterator::process_archetype, SpatialViewVisualizerData, UiLabel, UiLabelTarget,
entity_iterator::process_archetype, SpatialViewVisualizerData, UiLabel, UiLabelStyle,
UiLabelTarget,
};

pub struct VideoFrameReferenceVisualizer {
Expand Down Expand Up @@ -365,7 +366,7 @@ impl VideoFrameReferenceVisualizer {
);
self.data.ui_labels.push(UiLabel {
text: error_string,
color: egui::Color32::LIGHT_RED,
style: UiLabelStyle::Error,
target: UiLabelTarget::Rect(label_target_rect),
labeled_instance: re_entity_db::InstancePathHash::entity_all(entity_path),
});
Expand Down
25 changes: 19 additions & 6 deletions crates/viewer/re_ui/src/context_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use crate::{DesignTokens, TopBarStyle};
pub trait ContextExt {
fn ctx(&self) -> &egui::Context;

// -----------------------------------------------------
// Style-related stuff.
// We could have this on a `StyleExt` trait, but we prefer to have it here on `Context`
// so that it is the same style everywhere (instead of being specific to the parent `ui.style`).

/// Text format used for regular body.
fn text_format_body(&self) -> egui::TextFormat {
egui::TextFormat::simple(
Expand Down Expand Up @@ -56,17 +61,25 @@ pub trait ContextExt {
#[must_use]
fn warning_text(&self, text: impl Into<String>) -> egui::RichText {
let style = self.ctx().style();
egui::RichText::new(text)
.italics()
.color(style.visuals.warn_fg_color)
egui::RichText::new(text).color(style.visuals.warn_fg_color)
}

/// NOTE: duplicated in [`Self::error_text_format`]
#[must_use]
fn error_text(&self, text: impl Into<String>) -> egui::RichText {
let style = self.ctx().style();
egui::RichText::new(text)
.italics()
.color(style.visuals.error_fg_color)
egui::RichText::new(text).color(style.visuals.error_fg_color)
}

/// NOTE: duplicated in [`Self::error_text`]
fn error_text_format(&self) -> egui::TextFormat {
let style = self.ctx().style();
let font_id = egui::TextStyle::Body.resolve(&style);
egui::TextFormat {
font_id,
color: style.visuals.error_fg_color,
..Default::default()
}
}

fn top_bar_style(&self, style_like_web: bool) -> TopBarStyle {
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_viewer_context/src/selection_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum ItemSpaceContext {
}

/// Selection highlight, sorted from weakest to strongest.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum SelectionHighlight {
/// No selection highlight at all.
#[default]
Expand All @@ -53,7 +53,7 @@ pub enum SelectionHighlight {
}

/// Hover highlight, sorted from weakest to strongest.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum HoverHighlight {
/// No hover highlight.
#[default]
Expand Down
Loading