-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Space view screenshotting in native viewer (#8258)
### Related * Closes #3941 * Uses emilk/egui#5416 * Uses emilk/egui#5426 * Follow-up: #8264 ### What Right-click the name of any space view to get the option to copy its contents as a screenshot, or save it to disk: ![image](https://github.com/user-attachments/assets/0a0c5215-9042-4989-9e4a-62f76823588a) -> ![image](https://github.com/user-attachments/assets/ec222323-4692-4fd2-ae7b-2342996829a3) #### Details The implementation simply takes a full-screen screenshot and crops the result. The previous attempt (behind a feature-flag) only captured things that were rendered with `re_renderer`, i.e. did not include any egui elements, like labels. So it also only worked on spatial views. This PR work on _all_ space views, and could also be extended to work on containers etc. ### Limitations Not yet implemented on web. See #8264 ### TODO * [x] Point commit hash to egui `master` --------- Co-authored-by: Andreas Reich <[email protected]>
- Loading branch information
Showing
24 changed files
with
336 additions
and
245 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
crates/viewer/re_context_menu/src/actions/screenshot_action.rs
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,78 @@ | ||
use re_viewer_context::{ | ||
Item, PublishedSpaceViewInfo, ScreenshotTarget, SpaceViewId, SpaceViewRectPublisher, | ||
}; | ||
|
||
use crate::{ContextMenuAction, ContextMenuContext}; | ||
|
||
/// Space view screenshot action. | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub enum ScreenshotAction { | ||
/// Screenshot the space view, and copy the results to clipboard. | ||
CopyScreenshot, | ||
|
||
/// Screenshot the space view, and save the results to disk. | ||
SaveScreenshot, | ||
} | ||
|
||
impl ContextMenuAction for ScreenshotAction { | ||
/// Do we have a context menu for this selection? | ||
fn supports_selection(&self, ctx: &ContextMenuContext<'_>) -> bool { | ||
// Allow if there is a single space view selected. | ||
ctx.selection.len() == 1 | ||
&& ctx | ||
.selection | ||
.iter() | ||
.all(|(item, _)| self.supports_item(ctx, item)) | ||
} | ||
|
||
/// Do we have a context menu for this item? | ||
fn supports_item(&self, ctx: &ContextMenuContext<'_>, item: &Item) -> bool { | ||
let Item::SpaceView(space_view_id) = item else { | ||
return false; | ||
}; | ||
|
||
ctx.egui_context.memory_mut(|mem| { | ||
mem.caches | ||
.cache::<SpaceViewRectPublisher>() | ||
.get(space_view_id) | ||
.is_some() | ||
}) | ||
} | ||
|
||
fn label(&self, _ctx: &ContextMenuContext<'_>) -> String { | ||
match self { | ||
Self::CopyScreenshot => "Copy screenshot".to_owned(), | ||
Self::SaveScreenshot => "Save screenshot…".to_owned(), | ||
} | ||
} | ||
|
||
fn process_space_view(&self, ctx: &ContextMenuContext<'_>, space_view_id: &SpaceViewId) { | ||
let Some(space_view_info) = ctx.egui_context.memory_mut(|mem| { | ||
mem.caches | ||
.cache::<SpaceViewRectPublisher>() | ||
.get(space_view_id) | ||
.cloned() | ||
}) else { | ||
return; | ||
}; | ||
|
||
let PublishedSpaceViewInfo { name, rect } = space_view_info; | ||
|
||
let rect = rect.shrink(1.75); // Hacky: Shrink so we don't accidentally include the border of the space-view. | ||
|
||
let target = match self { | ||
Self::CopyScreenshot => ScreenshotTarget::CopyToClipboard, | ||
Self::SaveScreenshot => ScreenshotTarget::SaveToDisk, | ||
}; | ||
|
||
ctx.egui_context | ||
.send_viewport_cmd(egui::ViewportCommand::Screenshot(egui::UserData::new( | ||
re_viewer_context::ScreenshotInfo { | ||
ui_rect: Some(rect), | ||
pixels_per_point: ctx.egui_context.pixels_per_point(), | ||
name, | ||
target, | ||
}, | ||
))); | ||
} | ||
} |
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
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 was deleted.
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
Oops, something went wrong.