Skip to content

Commit

Permalink
Convert graph view to egui::Scene (#8847)
Browse files Browse the repository at this point in the history
### Related

* Closes #8478

### What

Title.
  • Loading branch information
grtlr authored Jan 30, 2025
1 parent e3990f8 commit 2dd6e80
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 184 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]]
name = "ecolor"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"bytemuck",
"color-hex",
Expand All @@ -1974,7 +1974,7 @@ checksum = "18aade80d5e09429040243ce1143ddc08a92d7a22820ac512610410a4dd5214f"
[[package]]
name = "eframe"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"ahash",
"bytemuck",
Expand Down Expand Up @@ -2013,7 +2013,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"accesskit",
"ahash",
Expand All @@ -2031,7 +2031,7 @@ dependencies = [
[[package]]
name = "egui-wgpu"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"ahash",
"bytemuck",
Expand All @@ -2050,7 +2050,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"accesskit_winit",
"ahash",
Expand Down Expand Up @@ -2091,7 +2091,7 @@ dependencies = [
[[package]]
name = "egui_extras"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"ahash",
"egui",
Expand All @@ -2108,7 +2108,7 @@ dependencies = [
[[package]]
name = "egui_glow"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"ahash",
"bytemuck",
Expand All @@ -2125,7 +2125,7 @@ dependencies = [
[[package]]
name = "egui_kittest"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"dify",
"eframe",
Expand Down Expand Up @@ -2196,7 +2196,7 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "emath"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"bytemuck",
"serde",
Expand Down Expand Up @@ -2312,7 +2312,7 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"
dependencies = [
"ab_glyph",
"ahash",
Expand All @@ -2331,7 +2331,7 @@ dependencies = [
[[package]]
name = "epaint_default_fonts"
version = "0.30.0"
source = "git+https://github.com/emilk/egui.git?branch=master#bc5f908b80cbcb20a728b36d20df860d90a29263"
source = "git+https://github.com/emilk/egui.git?branch=master#83649f2e295a4c27ea08023b6e7f591d3e60ea7f"

[[package]]
name = "equivalent"
Expand Down Expand Up @@ -3902,7 +3902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]

[[package]]
Expand Down Expand Up @@ -5493,7 +5493,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]

[[package]]
Expand Down Expand Up @@ -10032,7 +10032,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]

[[package]]
Expand Down
1 change: 0 additions & 1 deletion crates/viewer/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod section_collapsing_header;
pub mod syntax_highlighting;
mod ui_ext;
mod ui_layout;
pub mod zoom_pan_area;

use egui::Color32;
use egui::NumExt as _;
Expand Down
114 changes: 0 additions & 114 deletions crates/viewer/re_ui/src/zoom_pan_area.rs

This file was deleted.

10 changes: 1 addition & 9 deletions crates/viewer/re_view_graph/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use re_types::{
components::Position2D,
Archetype as _,
};
use re_ui::zoom_pan_area::fit_to_rect_in_scene;
use re_viewer_context::{TypedComponentFallbackProvider, ViewStateExt as _};

use crate::{ui::GraphViewState, GraphView};
Expand All @@ -22,14 +21,7 @@ impl TypedComponentFallbackProvider<VisualBounds2D> for GraphView {
};

match state.layout_state.bounding_rect() {
Some(rect) if valid_bound(&rect) => {
if let Some(rect_in_ui) = state.rect_in_ui {
let ui_from_world = fit_to_rect_in_scene(rect_in_ui, rect);
(ui_from_world.inverse() * rect_in_ui).into()
} else {
rect.into()
}
}
Some(rect) if valid_bound(&rect) => rect.into(),
_ => VisualBounds2D::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_view_graph/src/ui/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub enum LevelOfDetail {
}

impl LevelOfDetail {
pub fn from_scaling(zoom: f32) -> Self {
if zoom < 0.20 {
pub fn from_scaling(scale: f32) -> Self {
if scale < 0.20 {
Self::Low
} else {
Self::Full
Expand Down
1 change: 0 additions & 1 deletion crates/viewer/re_view_graph/src/ui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::layout::{ForceLayoutParams, ForceLayoutProvider, Layout, LayoutReques
pub struct GraphViewState {
pub layout_state: LayoutState,
pub visual_bounds: Option<VisualBounds2D>,
pub rect_in_ui: Option<Rect>,
}

impl GraphViewState {
Expand Down
71 changes: 32 additions & 39 deletions crates/viewer/re_view_graph/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use egui::Response;
use re_log_types::EntityPath;
use re_types::{
blueprint::{
Expand All @@ -10,11 +9,7 @@ use re_types::{
},
ViewClassIdentifier,
};
use re_ui::{
self,
zoom_pan_area::{fit_to_rect_in_scene, zoom_pan_area},
ModifiersMarkdown, MouseButtonMarkdown, UiExt as _,
};
use re_ui::{self, ModifiersMarkdown, MouseButtonMarkdown, UiExt as _};
use re_view::{
controls::{DRAG_PAN2D_BUTTON, ZOOM_SCROLL_MODIFIER},
view_property_ui,
Expand Down Expand Up @@ -182,34 +177,33 @@ Display a graph of nodes and edges.
let request = LayoutRequest::from_graphs(graphs.iter());
let layout = state.layout_state.get(request, params);

// Prepare the view and the transformations.
let rect_in_ui = *state.rect_in_ui.insert(ui.max_rect());

let mut ui_from_world = fit_to_rect_in_scene(rect_in_ui, rect_in_scene.into());

// We store a copy of the transformation to see if it has changed.
let ui_from_world_ref = ui_from_world;

let level_of_detail = LevelOfDetail::from_scaling(ui_from_world.scaling);

let mut hover_click_item: Option<(Item, Response)> = None;

let resp = zoom_pan_area(ui, &mut ui_from_world, |ui| {
let mut world_bounding_rect = egui::Rect::NOTHING;

for graph in &graphs {
let graph_rect = draw_graph(
ui,
ctx,
graph,
layout,
query,
level_of_detail,
&mut hover_click_item,
);
world_bounding_rect = world_bounding_rect.union(graph_rect);
}
});
let mut scene_rect = egui::Rect::from(rect_in_scene);
let scene_rect_ref = scene_rect;

// To determine the overall scale factor needed for the level-of-details
// computation, we need to look at the two dimensions separately due to letter-boxing.
let rect_in_ui = ui.max_rect();
let scale = rect_in_ui.size() / scene_rect.size();

let level_of_detail = LevelOfDetail::from_scaling(scale.min_elem());

let mut hover_click_item: Option<(Item, egui::Response)> = None;

let resp = egui::Scene::new()
.show(ui, &mut scene_rect, |ui| {
for graph in &graphs {
draw_graph(
ui,
ctx,
graph,
layout,
query,
level_of_detail,
&mut hover_click_item,
);
}
})
.response;

if let Some((item, response)) = hover_click_item {
ctx.handle_select_hover_drag_interactions(&response, item, false);
Expand All @@ -224,15 +218,14 @@ Display a graph of nodes and edges.
}

// Update blueprint if changed
let updated_rect_in_scene =
blueprint::components::VisualBounds2D::from(ui_from_world.inverse() * rect_in_ui);
let updated_bounds = blueprint::components::VisualBounds2D::from(scene_rect);
if resp.double_clicked() {
bounds_property.reset_blueprint_component::<blueprint::components::VisualBounds2D>(ctx);
} else if ui_from_world != ui_from_world_ref {
bounds_property.save_blueprint_component(ctx, &updated_rect_in_scene);
} else if scene_rect != scene_rect_ref {
bounds_property.save_blueprint_component(ctx, &updated_bounds);
}
// Update stored bounds on the state, so visualizers see an up-to-date value.
state.visual_bounds = Some(updated_rect_in_scene);
state.visual_bounds = Some(updated_bounds);

if state.layout_state.is_in_progress() {
ui.ctx().request_repaint();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2dd6e80

Please sign in to comment.