-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nicer (& fixed up) help texts for space views (#2070)
* Nicer (& fixed) help texts for space views * centralize constants for space view controls * fix calling primary mouse button right "primary" would be more correct, but that's a mouth full * update egui for modifiers.contains support * formatting
- Loading branch information
Showing
15 changed files
with
342 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/// Utility for building layout jobs. | ||
pub struct LayoutJobBuilder<'a> { | ||
pub layout_job: egui::text::LayoutJob, | ||
pub re_ui: &'a crate::ReUi, | ||
} | ||
|
||
impl<'a> LayoutJobBuilder<'a> { | ||
pub fn new(re_ui: &'a crate::ReUi) -> Self { | ||
Self { | ||
layout_job: egui::text::LayoutJob::default(), | ||
re_ui, | ||
} | ||
} | ||
|
||
/// Append a generic text block. | ||
pub fn add<'b, T: Into<LayoutJobBuilderBuildingBlock<'b>>>(&mut self, text_block: T) { | ||
let text_block: LayoutJobBuilderBuildingBlock<'_> = text_block.into(); | ||
match text_block { | ||
LayoutJobBuilderBuildingBlock::Body(text) => self.add_body(text), | ||
LayoutJobBuilderBuildingBlock::Key(key) => self.add_key(key), | ||
LayoutJobBuilderBuildingBlock::Modifier(modifier) => self.add_modifier(modifier), | ||
LayoutJobBuilderBuildingBlock::MouseButton(button) => self.add_mouse_button(button), | ||
}; | ||
} | ||
|
||
/// Append body text. | ||
pub fn add_body(&mut self, text: &str) { | ||
self.layout_job | ||
.append(text, 0.0, self.re_ui.text_format_body()); | ||
} | ||
|
||
/// Append text that has special formatting for a button. | ||
pub fn add_button_text(&mut self, text: &str) { | ||
self.layout_job | ||
.append(&text.to_lowercase(), 0.0, self.re_ui.text_format_key()); | ||
} | ||
|
||
/// Append text for a keyboard key. | ||
pub fn add_key(&mut self, key: egui::Key) { | ||
self.add_button_text(key.name()); | ||
} | ||
|
||
/// Append text for one or more modifier keys. | ||
pub fn add_modifier(&mut self, modifier: egui::Modifiers) { | ||
let is_mac = matches!( | ||
self.re_ui.egui_ctx.os(), | ||
egui::os::OperatingSystem::Mac | egui::os::OperatingSystem::IOS | ||
); | ||
let text = egui::ModifierNames::NAMES.format(&modifier, is_mac); | ||
self.add_button_text(&text); | ||
} | ||
|
||
/// Append text for a mouse button. | ||
pub fn add_mouse_button(&mut self, button: egui::PointerButton) { | ||
self.add_button_text(match button { | ||
egui::PointerButton::Primary => "left mouse button", | ||
egui::PointerButton::Secondary => "right mouse button", | ||
egui::PointerButton::Middle => "middle mouse button", | ||
egui::PointerButton::Extra1 => "extra mouse button 1", | ||
egui::PointerButton::Extra2 => "extra mouse button 2", | ||
}); | ||
} | ||
} | ||
|
||
/// Generic building block that the layout job builder can consume. | ||
/// | ||
/// Not meant to be used directly, use [`LayoutJobBuilder::add`] instead. | ||
pub enum LayoutJobBuilderBuildingBlock<'a> { | ||
Body(&'a str), | ||
Key(egui::Key), | ||
Modifier(egui::Modifiers), | ||
MouseButton(egui::PointerButton), | ||
} | ||
|
||
impl<'a> From<&'a str> for LayoutJobBuilderBuildingBlock<'a> { | ||
fn from(text: &'a str) -> Self { | ||
Self::Body(text) | ||
} | ||
} | ||
|
||
impl From<egui::Key> for LayoutJobBuilderBuildingBlock<'_> { | ||
fn from(key: egui::Key) -> Self { | ||
Self::Key(key) | ||
} | ||
} | ||
|
||
impl From<egui::Modifiers> for LayoutJobBuilderBuildingBlock<'_> { | ||
fn from(modifier: egui::Modifiers) -> Self { | ||
Self::Modifier(modifier) | ||
} | ||
} | ||
|
||
impl From<egui::PointerButton> for LayoutJobBuilderBuildingBlock<'_> { | ||
fn from(button: egui::PointerButton) -> Self { | ||
Self::MouseButton(button) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// Modifier to press for scroll to zoom. | ||
pub const ZOOM_SCROLL_MODIFIER: egui::Modifiers = egui::Modifiers::COMMAND; | ||
|
||
/// Modifier to press for scroll to pan horizontally. | ||
pub const HORIZONTAL_SCROLL_MODIFIER: egui::Modifiers = egui::Modifiers::SHIFT; | ||
|
||
/// Which mouse button to drag for panning a 2D view. | ||
pub const DRAG_PAN2D_BUTTON: egui::PointerButton = egui::PointerButton::Primary; | ||
|
||
/// Rectangles drawn with this mouse button zoom in 2D views. | ||
pub const SELECTION_RECT_ZOOM_BUTTON: egui::PointerButton = egui::PointerButton::Secondary; | ||
|
||
/// Clicking this button moves the timeline to where the cursor is. | ||
pub const MOVE_TIME_CURSOR_BUTTON: egui::PointerButton = egui::PointerButton::Secondary; | ||
|
||
/// Which mouse button to drag for panning a 2D view. | ||
pub const DRAG_PAN3D_BUTTON: egui::PointerButton = egui::PointerButton::Secondary; | ||
|
||
/// Which mouse button to drag for rotating a 3D view. | ||
pub const ROTATE3D_BUTTON: egui::PointerButton = egui::PointerButton::Primary; | ||
|
||
/// Which mouse button rolls the camera. | ||
pub const ROLL_MOUSE: egui::PointerButton = egui::PointerButton::Middle; | ||
|
||
/// Which mouse button rolls the camera if the roll modifier is pressed. | ||
pub const ROLL_MOUSE_ALT: egui::PointerButton = egui::PointerButton::Primary; | ||
|
||
/// See [`ROLL_MOUSE_ALT`]. | ||
pub const ROLL_MOUSE_MODIFIER: egui::Modifiers = egui::Modifiers::ALT; | ||
|
||
/// Which modifier speeds up the 3D camera movement. | ||
pub const SPEED_UP_3D_MODIFIER: egui::Modifiers = egui::Modifiers::SHIFT; | ||
|
||
/// Which modifier slows down the 3D camera movement. | ||
pub const SLOW_DOWN_3D_MODIFIER: egui::Modifiers = egui::Modifiers::CTRL; | ||
|
||
/// Key to restore the camera. | ||
pub const TRACKED_CAMERA_RESTORE_KEY: egui::Key = egui::Key::Escape; | ||
|
||
/// Description text for which action resets a space view. | ||
pub const RESET_VIEW_BUTTON_TEXT: &str = "double click"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.