Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop-gpui): show the loading glass in the camera preview

Richie McIlroy605684be67a4
diff --git a/apps/desktop-gpui/src/camera_window.rs b/apps/desktop-gpui/src/camera_window.rs
index 5e9b1a035..c76750e37 100644
--- a/apps/desktop-gpui/src/camera_window.rs
+++ b/apps/desktop-gpui/src/camera_window.rs
@@ -58,6 +58,7 @@ use gpui::{
use serde_json::Value;
use crate::{
+ camera_loading,
feeds::Feeds,
platform,
store::{self, BlurMode, CameraShape, CameraWindowState},
@@ -75,6 +76,8 @@ pub const CAMERA_PRESET_LARGE: f32 = 400.;
pub const CAMERA_TOOLBAR_HEIGHT: f32 = 56.;
/// `CAMERA_WIDE_ASPECT_RATIO`.
const WIDE_ASPECT: f32 = 16. / 9.;
+const LOADING_FADE_OUT_SECONDS: f32 = 0.28;
+const CUTOUT_REVEAL_SECONDS: f32 = 0.45;
pub fn clamp_size(scale: f32) -> f32 {
scale.clamp(CAMERA_MIN_SIZE, CAMERA_MAX_SIZE)
@@ -969,6 +972,8 @@ struct CameraPreviewView {
retained_dims: Option<(usize, usize)>,
retained_captured_at: Option<Instant>,
reveal_started: Option<Instant>,
+ loading_started: Option<Instant>,
+ loading_fade_started: Option<Instant>,
retained_invalidated: bool,
selection_revision: u64,
frame_revision: Option<u64>,
@@ -1057,6 +1062,8 @@ impl CameraPreviewView {
retained_dims,
retained_captured_at,
reveal_started: None,
+ loading_started: None,
+ loading_fade_started: None,
retained_invalidated: false,
selection_revision: 0,
frame_revision: None,
@@ -1112,7 +1119,7 @@ impl CameraPreviewView {
}
impl Render for CameraPreviewView {
- fn render(&mut self, window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
+ fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
#[cfg(target_os = "macos")]
if self.painted_cutout_frame.as_ref().is_some_and(|painted| {
self.cutout_frame
@@ -1152,6 +1159,35 @@ impl Render for CameraPreviewView {
let theme = self.theme;
let radius = self.radius;
+ let showing_frame = self.latest_frame.is_some() || self.retained.is_some();
+ let has_issue = self.camera_error.is_some() || self.effect_issue.is_some();
+
+ let loading = if !showing_frame {
+ self.loading_fade_started = None;
+ let started = *self.loading_started.get_or_insert_with(Instant::now);
+ Some((started, 1., !has_issue && !cx.reduce_motion()))
+ } else if let Some(started) = self.loading_started {
+ let fade_started = *self.loading_fade_started.get_or_insert_with(Instant::now);
+ let fade_seconds = if radius > 0. {
+ LOADING_FADE_OUT_SECONDS
+ } else {
+ CUTOUT_REVEAL_SECONDS
+ };
+ let progress = fade_started.elapsed().as_secs_f32() / fade_seconds;
+ if progress < 1. && !cx.reduce_motion() {
+ Some((
+ started,
+ 1. - progress * progress * (3. - 2. * progress),
+ true,
+ ))
+ } else {
+ self.loading_started = None;
+ self.loading_fade_started = None;
+ None
+ }
+ } else {
+ None
+ };
let mut container = div()
.relative()
.size_full()
@@ -1201,10 +1237,15 @@ impl Render for CameraPreviewView {
if let Some(image) = self.cutout_frame.clone() {
self.painted_cutout_frame = Some(image.clone());
self.paints.fetch_add(1, Ordering::Relaxed);
+ // The cutout window is transparent, so the person fades in while
+ // the loading disc fades out; a raw surface cannot take opacity,
+ // but the bubble's opaque glass covers it during its own fade.
+ let reveal = loading.map_or(1., |(_, opacity, _)| 1. - opacity);
container = container.child(
gpui::img(image)
.size_full()
- .object_fit(gpui::ObjectFit::Cover),
+ .object_fit(gpui::ObjectFit::Cover)
+ .opacity(reveal),
);
}
@@ -1237,19 +1278,10 @@ impl Render for CameraPreviewView {
};
}
- let showing_frame = self.latest_frame.is_some() || self.retained.is_some();
-
- if !showing_frame {
- container = container.child(
- div()
- .size_full()
- .flex()
- .items_center()
- .justify_center()
- .text_size(px(16.))
- .text_color(theme.gray_11)
- .child("Loading camera..."),
- );
+ if let Some((started, opacity, animate)) = loading {
+ container = container.child(camera_loading::camera_loading(
+ started, radius, opacity, animate, !has_issue,
+ ));
}
// `CameraIssueOverlay` (`camera.tsx:911-955`): a black/75 wash over