From 1923ba56314cb47a8b18e13fa13565914830ee81 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:36:51 +0200 Subject: [PATCH] Make the entity path header "sticky" in the dataframe view (#7394) ### What Make entity path sticky when scrolling laterally (implementation as per the egui_table demo). https://github.com/user-attachments/assets/817f95b4-3002-4464-a2c0-dcfbc3660551 ### 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 the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7394?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7394?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7394) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. --- .../src/dataframe_ui.rs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/viewer/re_space_view_dataframe/src/dataframe_ui.rs b/crates/viewer/re_space_view_dataframe/src/dataframe_ui.rs index c4d0f397661b..0ded69c81d30 100644 --- a/crates/viewer/re_space_view_dataframe/src/dataframe_ui.rs +++ b/crates/viewer/re_space_view_dataframe/src/dataframe_ui.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use std::ops::Range; use anyhow::Context; +use egui::NumExt as _; use itertools::Itertools; use re_chunk_store::{ColumnDescriptor, LatestAtQuery, RowId}; @@ -167,6 +168,10 @@ struct DataframeTableDelegate<'a> { num_rows: u64, } +impl DataframeTableDelegate<'_> { + const LEFT_RIGHT_MARGIN: f32 = 4.0; +} + impl<'a> egui_table::TableDelegate for DataframeTableDelegate<'a> { fn prepare(&mut self, info: &egui_table::PrefetchInfo) { re_tracing::profile_function!(); @@ -190,7 +195,29 @@ impl<'a> egui_table::TableDelegate for DataframeTableDelegate<'a> { .show(ui, |ui| { if cell.row_nr == 0 { if let Some(entity_path) = &self.header_entity_paths[cell.group_index] { - ui.label(entity_path.to_string()); + //TODO(ab): factor this into a helper as soon as we use it elsewhere + let text = entity_path.to_string(); + let font_id = egui::TextStyle::Body.resolve(ui.style()); + let text_color = ui.visuals().text_color(); + let galley = ui + .painter() + .layout(text, font_id, text_color, f32::INFINITY); + + // Put the text leftmost in the clip rect (so it is always visible) + let mut pos = egui::Align2::LEFT_CENTER + .anchor_size( + ui.clip_rect().shrink(Self::LEFT_RIGHT_MARGIN).left_center(), + galley.size(), + ) + .min; + + // … but not so far to the right that it doesn't fit. + pos.x = pos.x.at_most(ui.max_rect().right() - galley.size().x); + + ui.put( + egui::Rect::from_min_size(pos, galley.size()), + egui::Label::new(galley), + ); } } else if cell.row_nr == 1 { ui.strong(self.schema[cell.col_range.start].short_name()); @@ -259,7 +286,7 @@ impl<'a> egui_table::TableDelegate for DataframeTableDelegate<'a> { }; egui::Frame::none() - .inner_margin(egui::Margin::symmetric(4.0, 0.0)) + .inner_margin(egui::Margin::symmetric(Self::LEFT_RIGHT_MARGIN, 0.0)) .show(ui, cell_ui); } }