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

Fix ListItem bugs #6398

Merged
merged 10 commits into from
May 24, 2024
2 changes: 1 addition & 1 deletion crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ fn axis_ui(
ui,
"time_series_selection_ui_y_axis",
true,
list_item2::LabelContent::new("Y Axis"),
list_item2::LabelContent::new("Y axis"),
sub_prop_ui,
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/re_ui/src/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ impl<'a> ListItem<'a> {
pub fn show_hierarchical_with_content<R>(
mut self,
ui: &mut Ui,
id: impl Into<egui::Id>,
id_source: impl std::hash::Hash,
default_open: bool,
add_body: impl FnOnce(&ReUi, &mut egui::Ui) -> R,
) -> ShowCollapsingResponse<R> {
let id = id.into();
let id = ui.id().with(id_source);
emilk marked this conversation as resolved.
Show resolved Hide resolved

let mut state = egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
Expand Down
72 changes: 36 additions & 36 deletions crates/re_ui/src/list_item2/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ impl<'a> ListItem<'a> {
pub fn show_hierarchical_with_children<R>(
mut self,
ui: &mut Ui,
id: impl Into<egui::Id>,
id_source: impl std::hash::Hash,
default_open: bool,
content: impl ListItemContent + 'a,
add_childrens: impl FnOnce(&ReUi, &mut egui::Ui) -> R,
) -> ShowCollapsingResponse<R> {
let id = id.into();
let id = ui.id().with(id_source);

let mut state = egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
Expand Down Expand Up @@ -270,43 +270,43 @@ impl<'a> ListItem<'a> {

let mut collapse_response = None;

if ui.is_rect_visible(bg_rect) {
let visuals = ui.style().interact_selectable(&style_response, selected);

let background_frame = ui.painter().add(egui::Shape::Noop);

// Draw collapsing triangle
if let Some(openness) = collapse_openness {
let triangle_pos = ui.painter().round_pos_to_pixels(egui::pos2(
rect.min.x,
rect.center().y - 0.5 * ReUi::collapsing_triangle_area().y,
));
let triangle_rect =
egui::Rect::from_min_size(triangle_pos, ReUi::collapsing_triangle_area());
let triangle_response = ui.interact(
triangle_rect.expand(3.0), // make it easier to click
id.unwrap_or(ui.id()).with("collapsing_triangle"),
egui::Sense::click(),
);
ReUi::paint_collapsing_triangle(ui, openness, triangle_rect.center(), &visuals);
collapse_response = Some(triangle_response);
}
let visuals = ui.style().interact_selectable(&style_response, selected);

let background_frame = ui.painter().add(egui::Shape::Noop);

// Draw collapsing triangle
if let Some(openness) = collapse_openness {
let triangle_pos = ui.painter().round_pos_to_pixels(egui::pos2(
rect.min.x,
rect.center().y - 0.5 * ReUi::collapsing_triangle_area().y,
));
let triangle_rect =
egui::Rect::from_min_size(triangle_pos, ReUi::collapsing_triangle_area());
let triangle_response = ui.interact(
triangle_rect.expand(3.0), // make it easier to click
id.unwrap_or(ui.id()).with("collapsing_triangle"),
egui::Sense::click(),
);
ReUi::paint_collapsing_triangle(ui, openness, triangle_rect.center(), &visuals);
collapse_response = Some(triangle_response);
}

// Draw content
let mut content_rect = rect;
if collapse_openness.is_some() {
content_rect.min.x += extra_indent + collapse_extra;
}
// Draw content
let mut content_rect = rect;
if collapse_openness.is_some() {
content_rect.min.x += extra_indent + collapse_extra;
}

let content_ctx = ContentContext {
rect: content_rect,
bg_rect,
response: &style_response,
list_item: &self,
layout_info,
};
content.ui(re_ui, ui, &content_ctx);
let content_ctx = ContentContext {
rect: content_rect,
bg_rect,
response: &style_response,
list_item: &self,
layout_info,
};
content.ui(re_ui, ui, &content_ctx);

if ui.is_rect_visible(bg_rect) {
// Ensure the background highlight is drawn over round pixel coordinates. Otherwise,
// there could be artifact between consecutive highlighted items when drawn on
// fractional pixels.
Expand Down
4 changes: 2 additions & 2 deletions crates/re_ui/src/list_item2/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ impl LayoutInfoStack {
/// list items.
pub fn list_item_scope<R>(
ui: &mut egui::Ui,
id_source: impl Into<egui::Id>,
id_source: impl std::hash::Hash,
content: impl FnOnce(&mut egui::Ui) -> R,
) -> R {
let scope_id = ui.id().with(id_source.into());
let scope_id = ui.id().with(id_source);

// read last frame layout statistics and reset for the new frame
let layout_stats = LayoutStatistics::read(ui.ctx(), scope_id);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl SelectionPanel {
UiLayout::SelectionPanelFull
};
for (i, item) in selection.iter_items().enumerate() {
ui.push_id(i, |ui| {
ui.push_id(item, |ui| {
what_is_selected_ui(ui, ctx, viewport.blueprint, item);

match item {
Expand Down
Loading