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

Add support for editing a space view's space origin #4848

Merged
merged 21 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
52 changes: 52 additions & 0 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,58 @@ impl ReUi {
response
}

/// Popup similar to [`egui::popup_below_widget`] but suitable for use with
/// [`crate::list_item::ListItem`].
pub fn list_item_popup<R>(
ui: &egui::Ui,
popup_id: egui::Id,
widget_response: &egui::Response,
vertical_offset: f32,
add_contents: impl FnOnce(&mut egui::Ui) -> R,
) -> Option<R> {
if !ui.memory(|mem| mem.is_popup_open(popup_id)) {
return None;
}

let pos = widget_response.rect.left_bottom() + egui::vec2(0.0, vertical_offset);
let pivot = Align2::LEFT_TOP;

let mut ret = None;
egui::Area::new(popup_id)
.order(egui::Order::Foreground)
.constrain(true)
.fixed_pos(pos)
.pivot(pivot)
.show(ui.ctx(), |ui| {
let frame = egui::Frame {
fill: ui.visuals().panel_fill,
..Default::default()
};
let frame_margin = frame.total_margin();
frame.show(ui, |ui| {
ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| {
ui.set_width(widget_response.rect.width() - frame_margin.sum().x);

ui.set_clip_rect(ui.cursor());

egui::ScrollArea::vertical().show(ui, |ui| {
egui::Frame {
//TODO(ab): use design token
inner_margin: egui::Margin::symmetric(8.0, 0.0),
..Default::default()
}
.show(ui, |ui| ret = Some(add_contents(ui)))
})
})
})
});

if ui.input(|i| i.key_pressed(egui::Key::Escape)) || widget_response.clicked_elsewhere() {
ui.memory_mut(|mem| mem.close_popup());
}
ret
}

pub fn panel_content<R>(
&self,
ui: &mut egui::Ui,
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl AppState {
&ctx,
ui,
&mut viewport,
&spaces_info,
app_blueprint.selection_panel_expanded,
);

Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod welcome_screen;
pub(crate) mod add_space_view_or_container_modal;
pub(crate) mod memory_panel;
pub(crate) mod selection_panel;
pub(crate) mod space_view_space_origin_ui;
pub(crate) mod visible_history;

pub use blueprint_panel::blueprint_panel_ui;
Expand Down
38 changes: 23 additions & 15 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use re_viewer_context::{
};
use re_viewport::{
external::re_space_view::blueprint::components::QueryExpressions, icon_for_container_kind,
Viewport, ViewportBlueprint,
SpaceInfoCollection, Viewport, ViewportBlueprint,
};

use crate::ui::add_space_view_or_container_modal::AddSpaceViewOrContainerModal;
Expand Down Expand Up @@ -72,6 +72,7 @@ impl SelectionPanel {
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
viewport: &mut Viewport<'_, '_>,
spaces_info: &SpaceInfoCollection,
expanded: bool,
) {
let screen_width = ui.ctx().screen_rect().width();
Expand Down Expand Up @@ -121,7 +122,7 @@ impl SelectionPanel {
.show(ui, |ui| {
ui.add_space(ui.spacing().item_spacing.y);
ctx.re_ui.panel_content(ui, |_, ui| {
self.contents(ctx, ui, viewport);
self.contents(ctx, ui, viewport, spaces_info);
});
});
});
Expand All @@ -133,6 +134,7 @@ impl SelectionPanel {
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
viewport: &mut Viewport<'_, '_>,
spaces_info: &SpaceInfoCollection,
) {
re_tracing::profile_function!();

Expand Down Expand Up @@ -166,7 +168,13 @@ impl SelectionPanel {
}

Item::SpaceView(space_view_id) => {
space_view_top_level_properties(ui, ctx, viewport.blueprint, space_view_id);
space_view_top_level_properties(
ui,
ctx,
viewport.blueprint,
spaces_info,
space_view_id,
);
}

_ => {}
Expand Down Expand Up @@ -196,6 +204,8 @@ impl SelectionPanel {
}
});
}

self.add_space_view_or_container_modal.ui(ui, ctx, viewport);
}

fn container_children(
Expand Down Expand Up @@ -223,8 +233,6 @@ impl SelectionPanel {
});
});

self.add_space_view_or_container_modal.ui(ui, ctx, viewport);

let show_content = |ui: &mut egui::Ui| {
let mut has_child = false;
for &child_tile_id in container.children() {
Expand Down Expand Up @@ -513,6 +521,7 @@ fn space_view_top_level_properties(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
spaces_info: &SpaceInfoCollection,
space_view_id: &SpaceViewId,
) {
if let Some(space_view) = viewport.space_view(space_view_id) {
Expand All @@ -525,25 +534,23 @@ fn space_view_top_level_properties(
string.",
);
ui.text_edit_singleline(&mut name);
ui.end_row();

space_view.set_display_name(ctx, if name.is_empty() { None } else { Some(name) });

ui.end_row();

ui.label("Space origin").on_hover_text(
"The origin Entity for this Space View. For spatial Space Views, the Space \
View's origin is the same as this Entity's origin and all transforms are \
relative to it.",
);
let (query, store) =
guess_query_and_store_for_selected_entity(ctx, &space_view.space_origin);
item_ui::entity_path_button(
ctx,
&query,
store,

super::space_view_space_origin_ui::space_view_space_origin_widget_ui(
ui,
Some(*space_view_id),
&space_view.space_origin,
ctx,
spaces_info,
space_view,
);

ui.end_row();

ui.label("Type")
Expand All @@ -553,6 +560,7 @@ fn space_view_top_level_properties(
.class(ctx.space_view_class_registry)
.display_name(),
);

ui.end_row();
});
}
Expand Down
Loading
Loading