Skip to content
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
30 changes: 17 additions & 13 deletions crates/viewer/re_view/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
//! For zooming and panning we use the modifiers in the default [`egui::InputOptions`].

use egui::{Modifiers, os::OperatingSystem};
use egui::{Key, KeyboardShortcut, Modifiers, PointerButton, os::OperatingSystem};

/// Which mouse button to drag for panning a 2D view.
pub const DRAG_PAN2D_BUTTON: egui::PointerButton = egui::PointerButton::Primary;
pub const DRAG_PAN2D_BUTTON: PointerButton = PointerButton::Primary;

/// Rectangles drawn with this mouse button zoom in 2D views.
pub const SELECTION_RECT_ZOOM_BUTTON: egui::PointerButton = egui::PointerButton::Secondary;
pub const SELECTION_RECT_ZOOM_BUTTON: PointerButton = PointerButton::Secondary;

/// Clicking this button moves the timeline to where the cursor is.
pub const MOVE_TIME_CURSOR_BUTTON: egui::PointerButton = egui::PointerButton::Secondary;
pub const MOVE_TIME_CURSOR_BUTTON: PointerButton = PointerButton::Secondary;

/// Which mouse button to drag for panning a 2D view.
pub const DRAG_PAN3D_BUTTON: egui::PointerButton = egui::PointerButton::Secondary;
pub const DRAG_PAN3D_BUTTON: PointerButton = PointerButton::Secondary;

/// Which mouse button to drag for rotating a 3D view.
pub const ROTATE3D_BUTTON: egui::PointerButton = egui::PointerButton::Primary;
pub const ROTATE3D_BUTTON: PointerButton = PointerButton::Primary;

/// Which mouse button rolls the camera.
pub const ROLL_MOUSE: egui::PointerButton = egui::PointerButton::Middle;
pub const ROLL_MOUSE: PointerButton = PointerButton::Middle;

/// Which mouse button rolls the camera if the roll modifier is pressed.
pub const ROLL_MOUSE_ALT: egui::PointerButton = egui::PointerButton::Primary;
pub const ROLL_MOUSE_ALT: PointerButton = PointerButton::Primary;

/// See [`ROLL_MOUSE_ALT`].
pub const ROLL_MOUSE_MODIFIER: egui::Modifiers = egui::Modifiers::ALT;
pub const ROLL_MOUSE_MODIFIER: Modifiers = Modifiers::ALT;

/// Which modifier speeds up the 3D camera movement.
pub const SPEED_UP_3D_MODIFIER: egui::Modifiers = egui::Modifiers::SHIFT;
pub const SPEED_UP_3D_MODIFIER: Modifiers = Modifiers::SHIFT;

/// Key to restore the camera.
pub const TRACKED_OBJECT_RESTORE_KEY: egui::Key = egui::Key::Escape;
pub const TRACKED_OBJECT_RESTORE_KEY: Key = Key::Escape;

/// Toggle the currently selected view to be maximized or not.
// NOTE: we use CTRL and not COMMAND, because ⌘+M minimizes the whole window on macOS.
pub const TOGGLE_MAXIMIZE_VIEW: KeyboardShortcut = KeyboardShortcut::new(Modifiers::CTRL, Key::M);

pub struct RuntimeModifiers {}

impl RuntimeModifiers {
pub fn slow_down(os: &OperatingSystem) -> Modifiers {
match os {
egui::os::OperatingSystem::Mac => egui::Modifiers::CTRL,
_ => egui::Modifiers::ALT,
egui::os::OperatingSystem::Mac => Modifiers::CTRL,
_ => Modifiers::ALT,
}
}
}
20 changes: 19 additions & 1 deletion crates/viewer/re_viewer_context/src/selection_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use itertools::Itertools as _;
use parking_lot::Mutex;

use re_entity_db::EntityPath;
use re_global_context::resolve_mono_instance_path_item;
use re_global_context::{ViewId, resolve_mono_instance_path_item};
use re_log_types::StoreKind;

use crate::ViewerContext;
Expand Down Expand Up @@ -123,6 +123,24 @@ impl ItemCollection {
) -> Self {
Self(items.into_iter().collect())
}

/// Is this view the selected one (and no other)?
pub fn is_view_the_only_selected(&self, needle: &ViewId) -> bool {
let mut is_selected = false;
for item in self.iter_items() {
let item_is_view = match item {
Item::View(id) | Item::DataResult(id, _) => id == needle,
_ => false,
};

if item_is_view {
is_selected = true;
} else {
return false; // More than one view selected
}
}
is_selected
}
}

impl IntoIterator for ItemCollection {
Expand Down
34 changes: 31 additions & 3 deletions crates/viewer/re_viewport/src/viewport_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use egui_tiles::{Behavior as _, EditAction};

use re_context_menu::{SelectionUpdateBehavior, context_menu_ui_for_item};
use re_log_types::{EntityPath, ResolvedEntityPathRule, RuleEffect};
use re_ui::{ContextExt as _, Icon, UiExt as _, design_tokens_of_visuals};
use re_ui::{ContextExt as _, Help, Icon, IconText, UiExt as _, design_tokens_of_visuals};
use re_view::controls::TOGGLE_MAXIMIZE_VIEW;
use re_viewer_context::{
Contents, DragAndDropFeedback, DragAndDropPayload, Item, PublishedViewInfo,
SystemExecutionOutput, ViewId, ViewQuery, ViewStates, ViewerContext, icon_for_container_kind,
Expand Down Expand Up @@ -530,17 +531,44 @@ impl<'a> egui_tiles::Behavior<ViewId> for TilesDelegate<'a, '_> {
// Show minimize-button:
if ui
.small_icon_button(&re_ui::icons::MINIMIZE)
.on_hover_text("Restore - show all spaces")
.on_hover_ui(|ui| {
Help::new_without_title()
.control(
"Restore - show all spaces",
IconText::from_keyboard_shortcut(ui.ctx().os(), TOGGLE_MAXIMIZE_VIEW),
)
.ui(ui);
})
.clicked()
|| ui.input_mut(|input| input.consume_shortcut(&TOGGLE_MAXIMIZE_VIEW))
{
*self.maximized = None;
}
} else if num_views > 1 {
// Show maximize-button:
let is_view_the_only_selected =
self.ctx.selection().is_view_the_only_selected(&view_id);
let toggle = is_view_the_only_selected
&& ui.input_mut(|input| input.consume_shortcut(&TOGGLE_MAXIMIZE_VIEW));
if ui
.small_icon_button(&re_ui::icons::MAXIMIZE)
.on_hover_text("Maximize view")
.on_hover_ui(|ui| {
if is_view_the_only_selected {
Help::new_without_title()
.control(
"Maximize view",
IconText::from_keyboard_shortcut(
ui.ctx().os(),
TOGGLE_MAXIMIZE_VIEW,
),
)
.ui(ui);
} else {
ui.label("Maximize view");
}
})
.clicked()
|| toggle
{
*self.maximized = Some(view_id);
// Just maximize - don't select. See https://github.com/rerun-io/rerun/issues/2861
Expand Down
Loading