Skip to content

Commit

Permalink
Implement save-view-as-screenshot on web
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 16, 2024
1 parent b68b4e9 commit 1eed6b9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions crates/viewer/re_context_menu/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub(super) mod move_contents_to_new_container;
pub(super) mod remove;
pub(super) mod show_hide;

#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
mod screenshot_action;

#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
pub use screenshot_action::ScreenshotAction;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use re_viewer_context::{Item, PublishedViewInfo, ScreenshotTarget, ViewId, ViewR
use crate::{ContextMenuAction, ContextMenuContext};

/// View screenshot action.
#[cfg(not(target_arch = "wasm32"))]
pub enum ScreenshotAction {
/// Screenshot the view, and copy the results to clipboard.
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
CopyScreenshot,

/// Screenshot the view, and save the results to disk.
Expand Down Expand Up @@ -39,6 +39,7 @@ impl ContextMenuAction for ScreenshotAction {

fn label(&self, _ctx: &ContextMenuContext<'_>) -> String {
match self {
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
Self::CopyScreenshot => "Copy screenshot".to_owned(),
Self::SaveScreenshot => "Save screenshot…".to_owned(),
}
Expand All @@ -59,6 +60,7 @@ impl ContextMenuAction for ScreenshotAction {
let rect = rect.shrink(1.75); // Hacky: Shrink so we don't accidentally include the border of the view.

let target = match self {
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
Self::CopyScreenshot => ScreenshotTarget::CopyToClipboard,
Self::SaveScreenshot => ScreenshotTarget::SaveToDisk,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_context_menu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn action_list(
Box::new(HideAction),
Box::new(RemoveAction),
],
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
vec![
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
Box::new(actions::ScreenshotAction::CopyScreenshot),
Box::new(actions::ScreenshotAction::SaveScreenshot),
],
Expand Down
5 changes: 2 additions & 3 deletions crates/viewer/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,6 @@ impl App {
false
}

#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
fn process_screenshot_result(
&mut self,
image: &Arc<egui::ColorImage>,
Expand All @@ -1623,8 +1622,8 @@ impl App {
};

match target {
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
re_viewer_context::ScreenshotTarget::CopyToClipboard => {
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
re_viewer_context::Clipboard::with(|clipboard| {
clipboard.set_image(
[rgba.width(), rgba.height()],
Expand Down Expand Up @@ -1656,6 +1655,7 @@ impl App {
}
}
} else {
#[cfg(not(target_arch = "wasm32"))] // no full-app screenshotting on web
self.screenshotter.save(image);
}
}
Expand Down Expand Up @@ -1951,7 +1951,6 @@ impl eframe::App for App {
self.store_hub = Some(store_hub);

// Check for returned screenshot:
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): screenshotting on web
egui_ctx.input(|i| {
for event in &i.raw.events {
if let egui::Event::Screenshot {
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_viewer_context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct ScreenshotInfo {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ScreenshotTarget {
/// The screenshot will be copied to the clipboard.
#[cfg(not(target_arch = "wasm32"))] // TODO(#8264): copy-to-screenshot on web
CopyToClipboard,

/// The screenshot will be saved to disk.
Expand Down

0 comments on commit 1eed6b9

Please sign in to comment.