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

Make the entity path header "sticky" in the dataframe view #7394

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
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
Loading