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

Improve selection and hover behavior of viewport's tabs #4424

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
39 changes: 19 additions & 20 deletions crates/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::BTreeMap;

use ahash::HashMap;
use egui_tiles::Behavior as _;
use re_data_ui::item_ui;

use re_ui::{Icon, ReUi};
use re_viewer_context::{
Expand Down Expand Up @@ -326,7 +327,15 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
tab_widget.paint(ui);
}

self.on_tab_button(tiles, tile_id, response)
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)],
);
}

response
}

fn drag_ui(
Expand All @@ -351,25 +360,6 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
});
}

fn on_tab_button(
&mut self,
tiles: &egui_tiles::Tiles<SpaceViewId>,
tile_id: egui_tiles::TileId,
button_response: egui::Response,
) -> egui::Response {
if button_response.clicked() {
if let Some(egui_tiles::Tile::Pane(space_view_id)) = tiles.get(tile_id) {
self.ctx
.set_single_selection(&Item::SpaceView(*space_view_id));
} else {
// Clicked a group tab - we don't support selecting that yet,
// so deselect whatever was selected to make it less confusing:
self.ctx.rec_cfg.selection_state.clear_current();
}
}
button_response
}

fn retain_pane(&mut self, space_view_id: &SpaceViewId) -> bool {
self.space_views.contains_key(space_view_id)
}
Expand Down Expand Up @@ -523,6 +513,13 @@ impl TabWidget {
.contains(&Item::SpaceView(space_view.id))
});

let hovered = space_view.map_or(false, |space_view| {
tab_viewer
.ctx
.hovered()
.contains(&Item::SpaceView(space_view.id))
});

// tab icon
let icon_size = ReUi::small_icon_size();
let icon_width_plus_padding = icon_size.x + ReUi::text_to_icon_padding();
Expand Down Expand Up @@ -553,6 +550,8 @@ impl TabWidget {

let bg_color = if selected {
ui.visuals().selection.bg_fill
} else if hovered {
ui.visuals().widgets.hovered.bg_fill
} else {
tab_viewer.tab_bar_color(ui.visuals())
};
Expand Down
Loading