Skip to content

Commit

Permalink
Limit the size of component tooltips with UiVerbosity::Reduced (#3171)
Browse files Browse the repository at this point in the history
### What

Limit the size of component tooltips with `UiVerbosity::Reduced`

Fixes #3154

<img width="227" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/b0bde6b0-52ba-4d9b-9f4f-e709638de983">


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3171) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3171)
- [Docs
preview](https://rerun.io/preview/35244cb0963af9643740613271415a8b7d4f4475/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/35244cb0963af9643740613271415a8b7d4f4475/examples)
<!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
abey79 and emilk authored Sep 1, 2023
1 parent 6451f78 commit 2f01670
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 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 @@ -43,6 +44,37 @@ 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), // includes "…x more" if any
UiVerbosity::All => num_instances,
};

// Here we enforce that exactly `max_row` rows are displayed, which means that:
// - For `num_instances == max_row`, then `max_row` rows are displayed.
// - For `num_instances == max_row + 1`, then `max_row-1` rows are displayed and "…2 more"
// is appended.
//
// ┏━━━┳━━━┳━━━┳━━━┓
// ┃ 3 ┃ 4 ┃ 5 ┃ 6 ┃ <- num_instances
// ┗━━━┻━━━┻━━━┻━━━┛
// ┌───┬───┬───┬───┐ ┐
// │ x │ x │ x │ x │ │
// ├───┼───┼───┼───┤ │
// │ x │ x │ x │ x │ │
// ├───┼───┼───┼───┤ ├─ max_row == 4
// │ x │ x │ x │ x │ │
// ├───┼───┼───┼───┤ │
// │ │ x │…+2│…+3│ │
// └───┴───┴───┴───┘ ┘
let displayed_row = if num_instances <= max_row {
num_instances
} else {
// this accounts for the "…x more" using a row and handles `num_instances == 0`
max_row.saturating_sub(1)
};

if num_instances == 0 {
ui.weak("(empty)");
} else if num_instances == 1 {
Expand All @@ -68,7 +100,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 @@ -84,7 +116,7 @@ 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| {
body.rows(row_height, displayed_row, |index, mut row| {
if let Some(instance_key) = instance_keys.get(index) {
row.col(|ui| {
let instance_path =
Expand All @@ -111,6 +143,12 @@ impl DataUi for EntityComponentWithInstances {
}
});
});
if num_instances > displayed_row {
ui.label(format!(
"…and {} more.",
re_format::format_large_number((num_instances - displayed_row) as _)
));
}
}
}
}

0 comments on commit 2f01670

Please sign in to comment.