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

Limit the size of component tooltips with UiVerbosity::Reduced #3171

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Changes from 2 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
26 changes: 23 additions & 3 deletions crates/re_data_ui/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use egui::NumExt;
use re_data_store::{EntityPath, InstancePath};
use re_query::ComponentWithInstances;
use re_types::ComponentName;
Expand Down Expand Up @@ -44,6 +45,13 @@ impl DataUi for EntityComponentWithInstances {
UiVerbosity::Reduced | UiVerbosity::All => false,
};

// in some cases, we don't want to display all instances
let max_row = match verbosity {
UiVerbosity::Small => 0,
UiVerbosity::Reduced => num_instances.at_most(4),
UiVerbosity::All => num_instances,
};

if num_instances == 0 {
ui.weak("(empty)");
} else if num_instances == 1 {
Expand All @@ -69,7 +77,7 @@ impl DataUi for EntityComponentWithInstances {
egui_extras::TableBuilder::new(ui)
.resizable(false)
.vscroll(true)
.auto_shrink([false, true])
.auto_shrink([true, true])
.max_scroll_height(100.0)
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
.columns(egui_extras::Column::auto(), 2)
Expand All @@ -85,8 +93,20 @@ impl DataUi for EntityComponentWithInstances {
.body(|mut body| {
re_ui::ReUi::setup_table_body(&mut body);
let row_height = re_ui::ReUi::table_line_height();
body.rows(row_height, num_instances, |index, mut row| {
if let Some(instance_key) = instance_keys.get(index) {
body.rows(row_height, max_row, |index, mut row| {
if index == max_row - 1 && num_instances > max_row {
// last row, suggest that there is more.
row.col(|ui| {
ui.label(format!(
abey79 marked this conversation as resolved.
Show resolved Hide resolved
"{} more…",
abey79 marked this conversation as resolved.
Show resolved Hide resolved
re_format::format_large_number(
(num_instances - max_row + 1) as _
)
));
});

row.col(|_| {});
} else if let Some(instance_key) = instance_keys.get(index) {
row.col(|ui| {
let instance_path =
InstancePath::instance(self.entity_path.clone(), *instance_key);
Expand Down