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

Style container's label as unnamed #4975

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ fn show_list_item_for_container_child(
(
Item::Container(*container_id),
ListItem::new(ctx.re_ui, format!("{:?}", container.container_kind))
.label_style(re_ui::LabelStyle::Unnamed)
.with_icon(icon_for_container_kind(&container.container_kind))
.with_buttons(|re_ui, ui| {
let response = re_ui
Expand Down
127 changes: 78 additions & 49 deletions crates/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use re_viewer_context::{

use crate::container::blueprint_id_to_tile_id;
use crate::{
container::Contents, space_view_entity_picker::SpaceViewEntityPicker,
container::Contents, icon_for_container_kind, space_view_entity_picker::SpaceViewEntityPicker,
space_view_heuristics::default_created_space_views,
system_execution::execute_systems_for_space_views, SpaceViewBlueprint, ViewportBlueprint,
};
Expand Down Expand Up @@ -238,6 +238,11 @@ impl<'a, 'b> Viewport<'a, 'b> {
let executed_systems_per_space_view =
execute_systems_for_space_views(ctx, tree, &blueprint.space_views);

let mut contents_per_tile_id = HashMap::default();
blueprint.for_each_contents(&mut |contents| {
contents_per_tile_id.insert(contents.as_tile_id(), *contents);
});
abey79 marked this conversation as resolved.
Show resolved Hide resolved

ui.scope(|ui| {
ui.spacing_mut().item_spacing.x = re_ui::ReUi::view_padding();

Expand All @@ -250,6 +255,7 @@ impl<'a, 'b> Viewport<'a, 'b> {
maximized: &mut maximized,
edited: false,
executed_systems_per_space_view,
contents_per_tile_id,
};

tree.ui(&mut tab_viewer, ui);
Expand Down Expand Up @@ -520,6 +526,9 @@ struct TabViewer<'a, 'b> {
/// List of query & system execution results for each space view.
executed_systems_per_space_view: HashMap<SpaceViewId, (ViewQuery<'a>, SystemExecutionOutput)>,

/// List of contents for each tile id
contents_per_tile_id: HashMap<egui_tiles::TileId, Contents>,

/// The user edited the tree.
edited: bool,
}
Expand Down Expand Up @@ -592,26 +601,6 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
}
}

fn tab_title_for_tile(
&mut self,
tiles: &egui_tiles::Tiles<SpaceViewId>,
tile_id: egui_tiles::TileId,
) -> egui::WidgetText {
if let Some(tile) = tiles.get(tile_id) {
match tile {
egui_tiles::Tile::Pane(pane) => self.tab_title_for_pane(pane),

// E.g. a tab with a grid of other tiles
egui_tiles::Tile::Container(container) => {
format!("{:?} Container", container.kind()).into()
}
}
} else {
re_log::warn_once!("SpaceViewId missing during tab_title_for_tile");
self.ctx.re_ui.error_text("Internal error").into()
}
}

#[allow(clippy::fn_params_excessive_bools)]
fn tab_ui(
&mut self,
Expand All @@ -631,8 +620,28 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
tab_widget.paint(ui);
}

if let Some(egui_tiles::Tile::Pane(space_view_id)) = tiles.get(tile_id) {
item_ui::select_hovered_on_click(self.ctx, &response, Item::SpaceView(*space_view_id));
match tiles.get(tile_id) {
Some(egui_tiles::Tile::Pane(space_view_id)) => {
item_ui::select_hovered_on_click(
self.ctx,
&response,
Item::SpaceView(*space_view_id),
);
}

Some(egui_tiles::Tile::Container(_)) => {
if let Some(Contents::Container(container_id)) =
self.contents_per_tile_id.get(&tile_id)
{
item_ui::select_hovered_on_click(
self.ctx,
&response,
Item::Container(*container_id),
);
}
}

None => {}
}

response
Expand Down Expand Up @@ -783,39 +792,59 @@ impl TabWidget {
active: bool,
gamma: f32,
) -> Self {
// Not all tabs are for tiles (space views) - some are for containers (e.g. a grid of space views).
let space_view = if let Some(egui_tiles::Tile::Pane(space_view_id)) = tiles.get(tile_id) {
tab_viewer.space_views.get(space_view_id)
} else {
None
let mut user_named = false;
let mut text: egui::WidgetText;
let icon;
let mut item = None;
abey79 marked this conversation as resolved.
Show resolved Hide resolved

match tiles.get(tile_id) {
Some(egui_tiles::Tile::Pane(space_view_id)) => {
if let Some(space_view) = tab_viewer.space_views.get(space_view_id) {
user_named = space_view.display_name.is_some();
icon = space_view
.class(tab_viewer.ctx.space_view_class_registry)
.icon();
text = tab_viewer.tab_title_for_pane(space_view_id);
item = Some(Item::SpaceView(*space_view_id));
} else {
re_log::warn_once!("Space View {space_view_id} not found");
text = tab_viewer.ctx.re_ui.error_text("Unknown Space View").into();
icon = &re_ui::icons::SPACE_VIEW_GENERIC;
}
}
Some(egui_tiles::Tile::Container(container)) => {
if let Some(Contents::Container(container_id)) =
tab_viewer.contents_per_tile_id.get(&tile_id)
{
text = format!("{:?}", container.kind()).into();
icon = icon_for_container_kind(&container.kind());
item = Some(Item::Container(*container_id));
} else {
re_log::warn_once!("Container for tile ID {tile_id:?} not found");
text = tab_viewer.ctx.re_ui.error_text("Unknown Container").into();
icon = &re_ui::icons::SPACE_VIEW_GENERIC;
}
}
None => {
re_log::warn_once!("Tile {tile_id:?} not found");
text = tab_viewer.ctx.re_ui.error_text("Internal error").into();
icon = &re_ui::icons::SPACE_VIEW_UNKNOWN;
}
};
let selected = space_view.map_or(false, |space_view| {
tab_viewer
.ctx
.selection()
.contains_item(&Item::SpaceView(space_view.id))
});
let named = space_view.map_or(false, |space_view| space_view.display_name.is_some());

let hovered = space_view.map_or(false, |space_view| {
tab_viewer
.ctx
.hovered()
.contains_item(&Item::SpaceView(space_view.id))
});
let hovered = item
.as_ref()
.map_or(false, |item| tab_viewer.ctx.hovered().contains_item(item));
let selected = item
.as_ref()
.map_or(false, |item| tab_viewer.ctx.selection().contains_item(item));

// tab icon
let icon_size = ReUi::small_icon_size();
let icon_width_plus_padding = icon_size.x + ReUi::text_to_icon_padding();
let icon = space_view.map_or(&re_ui::icons::SPACE_VIEW_GENERIC, |space_view| {
space_view
.class(tab_viewer.ctx.space_view_class_registry)
.icon()
});

// tab title
let mut text = tab_viewer.tab_title_for_tile(tiles, tile_id);
if !named {
if !user_named {
//TODO(ab): use design tokens
text = text.italics();
}
Expand Down Expand Up @@ -857,7 +886,7 @@ impl TabWidget {
icon_rect,
bg_color,
text_color,
unnamed_style: !named,
unnamed_style: !user_named,
}
}

Expand Down
31 changes: 31 additions & 0 deletions crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,37 @@ impl ViewportBlueprint {
new_ids
}

/// Walk the entire container and space view hierarchy.
///
/// The passed function is not called for the root item.
pub fn for_each_contents(&self, f: &mut impl FnMut(&Contents)) {
if let Some(root_container) = self.root_container {
self.for_each_contents_in_container(f, &root_container);
}
}

/// Walk a subtree of the container and space view hierarchy.
///
/// The passed function is not called for the provided container.
pub fn for_each_contents_in_container(
&self,
f: &mut impl FnMut(&Contents),
container_id: &ContainerId,
) {
if let Some(container) = self.container(container_id) {
for contents in &container.contents {
f(contents);

match contents {
Contents::Container(container_id) => {
self.for_each_contents_in_container(f, container_id);
}
Contents::SpaceView(_) => {}
}
}
}
}

/// Given a predicate, finds the (first) matching contents by recursively walking from the root
/// container.
pub fn find_contents_by(&self, predicate: &impl Fn(&Contents) -> bool) -> Option<Contents> {
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl Viewport<'_, '_> {
.selected(ctx.selection().contains_item(&item))
.draggable(true)
.drop_target_style(self.state.is_candidate_drop_parent_container(container_id))
.label_style(re_ui::LabelStyle::Unnamed)
.with_icon(crate::icon_for_container_kind(
&container_blueprint.container_kind,
))
Expand Down
Loading