Skip to content
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

Fix ugly UI for some arrow data #5235

Merged
merged 5 commits into from
Feb 20, 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
33 changes: 21 additions & 12 deletions crates/re_data_ui/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,45 @@ fn arrow_ui(ui: &mut egui::Ui, verbosity: UiVerbosity, array: &dyn arrow2::array
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i32>>() {
if utf8.len() == 1 {
let string = utf8.value(0);
text_ui(string, ui, verbosity);
text_ui(ui, verbosity, string);
return;
}
}
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i64>>() {
if utf8.len() == 1 {
let string = utf8.value(0);
text_ui(string, ui, verbosity);
text_ui(ui, verbosity, string);
return;
}
}

let num_bytes = array.total_size_bytes();
if num_bytes < 256 {
if num_bytes < 3000 {
// Print small items:
let mut string = String::new();
let display = arrow2::array::get_display(array, "null");
if display(&mut string, 0).is_ok() {
ui.label(string);
text_ui(ui, verbosity, &string);
return;
}
}

// Fallback:
ui.label(format!(
"{} of {:?}",
re_format::format_bytes(num_bytes as _),
array.data_type()
));
let bytes = re_format::format_bytes(num_bytes as _);

// TODO(emilk): pretty-print data type
let data_type_formatted = format!("{:?}", array.data_type());

if data_type_formatted.len() < 20 {
// e.g. "4.2 KiB of Float32"
text_ui(ui, verbosity, &format!("{bytes} of {data_type_formatted}"));
} else {
// Huge datatype, probably a union horror show
ui.label(format!("{bytes} of data"));
}
}

fn text_ui(string: &str, ui: &mut egui::Ui, verbosity: UiVerbosity) {
fn text_ui(ui: &mut egui::Ui, verbosity: UiVerbosity, string: &str) {
let font_id = egui::TextStyle::Monospace.resolve(ui.style());
let color = ui.visuals().text_color();
let wrap_width = ui.available_width();
Expand All @@ -143,11 +150,13 @@ fn text_ui(string: &str, ui: &mut egui::Ui, verbosity: UiVerbosity) {
}
}

let galley = ui.fonts(|f| f.layout_job(layout_job)); // We control the text layout; not the label

if needs_scroll_area {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.label(layout_job);
ui.label(galley);
});
} else {
ui.label(layout_job);
ui.label(galley);
}
}
2 changes: 2 additions & 0 deletions crates/re_ui/src/design_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ fn apply_design_tokens(ctx: &egui::Context) -> DesignTokens {
egui_style.spacing.scroll.bar_width = 6.0;
egui_style.spacing.scroll.bar_outer_margin = 2.0;

egui_style.spacing.tooltip_width = 720.0;

// don't color hyperlinks #2733
egui_style.visuals.hyperlink_color = default;

Expand Down
Loading