Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 5, 2024
1 parent 4099cbe commit 13b1e27
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn item_heading_with_breadcrumbs(
);
}

// Show the bread crumbs leading to (but not including) the final item.
fn item_bread_crumbs_ui(
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
Expand All @@ -80,7 +81,8 @@ fn item_bread_crumbs_ui(
) {
match item {
Item::AppId(_) | Item::DataSource(_) | Item::StoreId(_) => {
// TODO(emilk): maybe some of these could have breadcrumbs
// These have no bread crumbs, at least not currently.
// I guess one could argue that the `StoreId` should have the `AppId` as its ancestor?
}
Item::InstancePath(instance_path) => {
let InstancePath {
Expand Down Expand Up @@ -174,13 +176,13 @@ fn item_bread_crumbs_ui(
}
}

// Show the actual item, after all the bread crumbs:
fn last_part_of_item_heading(
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
ui: &mut egui::Ui,
item: &Item,
) {
// Show the actual item, after all the bread crumbs:
let ItemTitle {
icon,
label,
Expand All @@ -198,6 +200,49 @@ fn last_part_of_item_heading(
cursor_interact_with_selectable(ctx, response, item.clone());
}

/// The breadcrumbs of containers and views in the viewport.
fn viewport_breadcrumbs(
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
ui: &mut egui::Ui,
contents: Contents,
) {
let item = Item::from(contents);

if let Some(parent) = viewport.parent(&contents) {
// Recurse!
viewport_breadcrumbs(ctx, viewport, ui, parent.into());
}

let ItemTitle {
icon,
label: _, // ignored: we just show the icon for breadcrumbs
label_style: _, // no label
tooltip,
} = ItemTitle::from_contents(ctx, viewport, &contents);

let mut response = ui.add(
egui::Button::image(icon.as_image().fit_to_original_size(ICON_SCALE))
.image_tint_follows_text_color(true),
);
if let Some(tooltip) = tooltip {
response = response.on_hover_text(tooltip);
}
cursor_interact_with_selectable(ctx, response, item);

separator_icon_ui(ui, icons::BREADCRUMBS_SEPARATOR_BLUEPRINT);
}

fn separator_icon_ui(ui: &mut egui::Ui, icon: re_ui::Icon) {
ui.add(
icon.as_image()
.fit_to_original_size(ICON_SCALE)
.tint(ui.visuals().text_color()),
);
}

/// The breadcrumbs of an entity path,
/// that may or may not be part of a view.
fn entity_path_breadcrumbs(
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
Expand Down Expand Up @@ -251,43 +296,3 @@ fn entity_path_breadcrumbs(

separator_icon_ui(ui, icons::BREADCRUMBS_SEPARATOR_ENTITY);
}

fn viewport_breadcrumbs(
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
ui: &mut egui::Ui,
contents: Contents,
) {
let item = Item::from(contents);

if let Some(parent) = viewport.parent(&contents) {
// Recurse!
viewport_breadcrumbs(ctx, viewport, ui, parent.into());
}

let ItemTitle {
icon,
label: _, // ignored: we just show the icon for breadcrumbs
label_style: _, // no label
tooltip,
} = ItemTitle::from_item(ctx, viewport, ui.style(), &item);

let mut response = ui.add(
egui::Button::image(icon.as_image().fit_to_original_size(ICON_SCALE))
.image_tint_follows_text_color(true),
);
if let Some(tooltip) = tooltip {
response = response.on_hover_text(tooltip);
}
cursor_interact_with_selectable(ctx, response, item);

separator_icon_ui(ui, icons::BREADCRUMBS_SEPARATOR_BLUEPRINT);
}

fn separator_icon_ui(ui: &mut egui::Ui, icon: re_ui::Icon) {
ui.add(
icon.as_image()
.fit_to_original_size(ICON_SCALE)
.tint(ui.visuals().text_color()),
);
}
15 changes: 14 additions & 1 deletion crates/viewer/re_selection_panel/src/item_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use re_log_types::ComponentPath;
use re_ui::{
icons, syntax_highlighting::InstanceInBrackets as InstanceWithBrackets, SyntaxHighlighting as _,
};
use re_viewer_context::{contents_name_style, ContainerId, Item, SpaceViewId, ViewerContext};
use re_viewer_context::{
contents_name_style, ContainerId, Contents, Item, SpaceViewId, ViewerContext,
};
use re_viewport_blueprint::ViewportBlueprint;

#[must_use]
Expand Down Expand Up @@ -141,6 +143,17 @@ impl ItemTitle {
))
}

pub fn from_contents(
ctx: &ViewerContext<'_>,
viewport: &ViewportBlueprint,
contents: &Contents,
) -> Self {
match contents {
Contents::Container(container_id) => Self::from_container_id(viewport, container_id),
Contents::SpaceView(view_id) => Self::from_view_id(ctx, viewport, view_id),
}
}

pub fn from_container_id(viewport: &ViewportBlueprint, container_id: &ContainerId) -> Self {
if let Some(container_blueprint) = viewport.container(container_id) {
let hover_text = if let Some(display_name) = container_blueprint.display_name.as_ref() {
Expand Down

0 comments on commit 13b1e27

Please sign in to comment.