Skip to content

Commit

Permalink
Make the entity path header "sticky" in the dataframe view (#7394)
Browse files Browse the repository at this point in the history
### 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`.
  • Loading branch information
abey79 authored Sep 10, 2024
1 parent e9b02e3 commit 1923ba5
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions crates/viewer/re_space_view_dataframe/src/dataframe_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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!();
Expand All @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 1923ba5

Please sign in to comment.