BlueGit

ict rusty-teams

fix(calls): speaker stage shows the whole 16:9 picture

Img with an aspect ratio ignores its set height inside the stage, so Contain letterboxed against a taller box and the bottom was clipped. The stage now sizes the picture itself with contain_size. The demo camera pattern draws a border and a circle to make cropping visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-14 · 6 weeks ago

Hash
3721e2a0e8e065e94ff3310345268c054cb55520
Parent
66f7b201
5 files changed +75 −14
crates/app/src/call/mod.rs +1 −1
@@ -70,7 +70,7 @@ pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAU
70 70 pub use preview::{CameraPreview, preview_backgrounds};
71 71 pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
72 72 pub use ring::{MissedCall, RingEntry, Rings};
73 pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, gallery_grid, split_overflow};
73 pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, contain_size, filmstrip, focus_stage_size, gallery_grid, split_overflow};
74 74 pub use schedule::{FormValues, Invitee, default_window, draft_from_form};
75 75 pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};
76 76 pub use report::load_enabled as load_report_enabled;
@@ -70,7 +70,7 @@ pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAU
70pub use preview::{CameraPreview, preview_backgrounds};
70pub use preview::{CameraPreview, preview_backgrounds};
71pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
71pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
72pub use ring::{MissedCall, RingEntry, Rings};
72pub use ring::{MissedCall, RingEntry, Rings};
73pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, gallery_grid, split_overflow};
73pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, contain_size, filmstrip, focus_stage_size, gallery_grid, split_overflow};
74pub use schedule::{FormValues, Invitee, default_window, draft_from_form};
74pub use schedule::{FormValues, Invitee, default_window, draft_from_form};
75pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};
75pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};
76pub use report::load_enabled as load_report_enabled;
76pub use report::load_enabled as load_report_enabled;
crates/app/src/call/stage_layout.rs +33 −0
@@ -68,6 +68,22 @@ pub struct Filmstrip {
68 68 pub overflow: Overflow,
69 69 }
70 70
71 pub fn focus_stage_size(stage: (f32, f32), padding: f32, gap: f32, filmstrip_height: Option<f32>) -> (f32, f32) {
72 let strip = filmstrip_height.map_or(0., |height| height + gap);
73 (
74 (stage.0 - 2. * padding).max(0.),
75 (stage.1 - 2. * padding - strip).max(0.),
76 )
77 }
78
79 pub fn contain_size(container: (f32, f32), picture: (f32, f32)) -> (f32, f32) {
80 if picture.0 <= 0. || picture.1 <= 0. {
81 return (0., 0.);
82 }
83 let scale = (container.0 / picture.0).min(container.1 / picture.1).max(0.);
84 (picture.0 * scale, picture.1 * scale)
85 }
86
71 87 pub fn filmstrip(
72 88 others: usize,
73 89 own_cells: usize,
@@ -219,6 +235,23 @@ impl VisibleRotation {
219 235 mod tests {
220 236 use super::*;
221 237
238 #[test]
239 fn contain_letterboxes_wide_and_tall_containers() {
240 let (wide_width, wide_height) = contain_size((1000., 400.), (640., 360.));
241 assert!((wide_width - 711.111).abs() < 0.01);
242 assert!((wide_height - 400.).abs() < 0.01);
243 assert_eq!(contain_size((400., 1000.), (640., 360.)), (400., 225.));
244 assert_eq!(contain_size((640., 360.), (640., 360.)), (640., 360.));
245 assert_eq!(contain_size((100., 100.), (0., 0.)), (0., 0.));
246 }
247
248 #[test]
249 fn focus_stage_takes_the_stage_minus_padding_and_filmstrip() {
250 assert_eq!(focus_stage_size((1000., 600.), 24., 20., Some(100.)), (952., 432.));
251 assert_eq!(focus_stage_size((1000., 600.), 24., 20., None), (952., 552.));
252 assert_eq!(focus_stage_size((10., 10.), 24., 20., Some(100.)), (0., 0.));
253 }
254
222 255 fn names(count: usize) -> Vec<String> {
223 256 (0..count).map(|index| format!("p{index}")).collect()
224 257 }
@@ -68,6 +68,22 @@ pub struct Filmstrip {
68 pub overflow: Overflow,
68 pub overflow: Overflow,
69}
69}
70
70
71pub fn focus_stage_size(stage: (f32, f32), padding: f32, gap: f32, filmstrip_height: Option<f32>) -> (f32, f32) {
72 let strip = filmstrip_height.map_or(0., |height| height + gap);
73 (
74 (stage.0 - 2. * padding).max(0.),
75 (stage.1 - 2. * padding - strip).max(0.),
76 )
77}
78
79pub fn contain_size(container: (f32, f32), picture: (f32, f32)) -> (f32, f32) {
80 if picture.0 <= 0. || picture.1 <= 0. {
81 return (0., 0.);
82 }
83 let scale = (container.0 / picture.0).min(container.1 / picture.1).max(0.);
84 (picture.0 * scale, picture.1 * scale)
85}
86
71pub fn filmstrip(
87pub fn filmstrip(
72 others: usize,
88 others: usize,
73 own_cells: usize,
89 own_cells: usize,
@@ -219,6 +235,23 @@ impl VisibleRotation {
219mod tests {
235mod tests {
220 use super::*;
236 use super::*;
221
237
238 #[test]
239 fn contain_letterboxes_wide_and_tall_containers() {
240 let (wide_width, wide_height) = contain_size((1000., 400.), (640., 360.));
241 assert!((wide_width - 711.111).abs() < 0.01);
242 assert!((wide_height - 400.).abs() < 0.01);
243 assert_eq!(contain_size((400., 1000.), (640., 360.)), (400., 225.));
244 assert_eq!(contain_size((640., 360.), (640., 360.)), (640., 360.));
245 assert_eq!(contain_size((100., 100.), (0., 0.)), (0., 0.));
246 }
247
248 #[test]
249 fn focus_stage_takes_the_stage_minus_padding_and_filmstrip() {
250 assert_eq!(focus_stage_size((1000., 600.), 24., 20., Some(100.)), (952., 432.));
251 assert_eq!(focus_stage_size((1000., 600.), 24., 20., None), (952., 552.));
252 assert_eq!(focus_stage_size((10., 10.), 24., 20., Some(100.)), (0., 0.));
253 }
254
222 fn names(count: usize) -> Vec<String> {
255 fn names(count: usize) -> Vec<String> {
223 (0..count).map(|index| format!("p{index}")).collect()
256 (0..count).map(|index| format!("p{index}")).collect()
224 }
257 }
crates/app/src/views/call_layouts.rs +6 −3
@@ -20,7 +20,7 @@ use super::widgets::icon;
20 20 use crate::app_state::AppState;
21 21 use crate::call::{
22 22 ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,
23 filmstrip, gallery_grid, shown_bubbles, split_overflow,
23 filmstrip, focus_stage_size, gallery_grid, shown_bubbles, split_overflow,
24 24 };
25 25 use calling::{TileDetail, VideoWant};
26 26 use crate::theme;
@@ -444,10 +444,12 @@ fn speaker_body(
444 444 stage: (f32, f32),
445 445 ) -> AnyElement {
446 446 let SpeakerSplit { focus, others, own_cells, plan } = speaker_split(model, stage);
447 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
448 let has_filmstrip = plan.overflow.shown + own_cells + usize::from(plan.overflow.hidden > 0) > 0;
449 let focus_size = focus_stage_size(stage, GRID_PADDING, TILE_GAP, has_filmstrip.then_some(size.height));
447 450 let main = focus
448 451 .as_ref()
449 .and_then(|focus| render_focus_stage(app, state, focus, now));
450 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
452 .and_then(|focus| render_focus_stage(app, state, focus, focus_size, now));
451 453 let shown = &others[..plan.overflow.shown];
452 454 let mut tiles: Vec<AnyElement> = shown
453 455 .iter()
@@ -478,6 +480,7 @@ fn speaker_body(
478 480 .min_h_0()
479 481 .w_full()
480 482 .items_center()
483 .justify_center()
481 484 .children(main),
482 485 )
483 486 .when(!tiles.is_empty(), |column| {
@@ -20,7 +20,7 @@ use super::widgets::icon;
20use crate::app_state::AppState;
20use crate::app_state::AppState;
21use crate::call::{
21use crate::call::{
22 ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,
22 ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,
23 filmstrip, gallery_grid, shown_bubbles, split_overflow,
23 filmstrip, focus_stage_size, gallery_grid, shown_bubbles, split_overflow,
24};
24};
25use calling::{TileDetail, VideoWant};
25use calling::{TileDetail, VideoWant};
26use crate::theme;
26use crate::theme;
@@ -444,10 +444,12 @@ fn speaker_body(
444 stage: (f32, f32),
444 stage: (f32, f32),
445) -> AnyElement {
445) -> AnyElement {
446 let SpeakerSplit { focus, others, own_cells, plan } = speaker_split(model, stage);
446 let SpeakerSplit { focus, others, own_cells, plan } = speaker_split(model, stage);
447 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
448 let has_filmstrip = plan.overflow.shown + own_cells + usize::from(plan.overflow.hidden > 0) > 0;
449 let focus_size = focus_stage_size(stage, GRID_PADDING, TILE_GAP, has_filmstrip.then_some(size.height));
447 let main = focus
450 let main = focus
448 .as_ref()
451 .as_ref()
449 .and_then(|focus| render_focus_stage(app, state, focus, now));
452 .and_then(|focus| render_focus_stage(app, state, focus, focus_size, now));
450 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
451 let shown = &others[..plan.overflow.shown];
453 let shown = &others[..plan.overflow.shown];
452 let mut tiles: Vec<AnyElement> = shown
454 let mut tiles: Vec<AnyElement> = shown
453 .iter()
455 .iter()
@@ -478,6 +480,7 @@ fn speaker_body(
478 .min_h_0()
480 .min_h_0()
479 .w_full()
481 .w_full()
480 .items_center()
482 .items_center()
483 .justify_center()
481 .children(main),
484 .children(main),
482 )
485 )
483 .when(!tiles.is_empty(), |column| {
486 .when(!tiles.is_empty(), |column| {
crates/app/src/views/call_organizer.rs +28 −9
@@ -21,7 +21,7 @@ use super::call_people::add_people_item;
21 21 use super::call_view::{BANNER_HEIGHT, CONTROL_SIZE, MENU_WIDTH, round_control};
22 22 use super::widgets::{Corner, corner_badge, count_badge, icon};
23 23 use crate::app_state::AppState;
24 use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus};
24 use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size};
25 25 use crate::notice::truncated;
26 26 use crate::theme;
27 27
@@ -35,6 +35,7 @@ const CAPTION_TOP: f32 = 72.;
35 35 const CAPTION_FADE_SECONDS: f32 = 1.;
36 36 const CAPTION_BACKGROUND: f32 = 0.72;
37 37 const FOCUS_RADIUS: f32 = 12.;
38 const FOCUS_BORDER: f32 = 2.;
38 39 const FOCUS_AVATAR: f32 = 140.;
39 40 const CHIP_HEIGHT: f32 = 24.;
40 41 const MORE_SIZE: f32 = 28.;
@@ -698,6 +699,7 @@ pub fn render_focus_stage(
698 699 app: &Entity<AppState>,
699 700 state: &AppState,
700 701 focus: &Focus,
702 size: (f32, f32),
701 703 now: Instant,
702 704 ) -> Option<AnyElement> {
703 705 let call = state.call.as_ref()?;
@@ -723,10 +725,27 @@ pub fn render_focus_stage(
723 725 };
724 726 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
725 727 let picture = match image {
726 Some(image) => img(ImageSource::Render(image))
727 .size_full()
728 .object_fit(ObjectFit::Contain)
729 .into_any_element(),
728 Some(image) => {
729 let picture_size = image.size(0);
730 let (width, height) = contain_size(
731 (size.0 - 2. * FOCUS_BORDER, size.1 - 2. * FOCUS_BORDER),
732 (picture_size.width.0 as f32, picture_size.height.0 as f32),
733 );
734 div()
735 .size_full()
736 .flex()
737 .items_center()
738 .justify_center()
739 .child(
740 img(ImageSource::Render(image))
741 .w(px(width))
742 .h(px(height))
743 .flex_none()
744 .object_fit(ObjectFit::Fill)
745 .rounded(px(FOCUS_RADIUS)),
746 )
747 .into_any_element()
748 }
730 749 None => div()
731 750 .size_full()
732 751 .flex()
@@ -743,13 +762,13 @@ pub fn render_focus_stage(
743 762 let stage = div()
744 763 .id("call-focus-stage")
745 764 .relative()
746 .flex_1()
747 .min_w_0()
748 .h_full()
765 .w(px(size.0))
766 .h(px(size.1))
767 .flex_none()
749 768 .overflow_hidden()
750 769 .rounded(px(FOCUS_RADIUS))
751 770 .bg(hsla(0., 0., 0.04, 1.))
752 .border_2()
771 .border(px(FOCUS_BORDER))
753 772 .border_color(if speaking {
754 773 theme::green()
755 774 } else {
@@ -21,7 +21,7 @@ use super::call_people::add_people_item;
21use super::call_view::{BANNER_HEIGHT, CONTROL_SIZE, MENU_WIDTH, round_control};
21use super::call_view::{BANNER_HEIGHT, CONTROL_SIZE, MENU_WIDTH, round_control};
22use super::widgets::{Corner, corner_badge, count_badge, icon};
22use super::widgets::{Corner, corner_badge, count_badge, icon};
23use crate::app_state::AppState;
23use crate::app_state::AppState;
24use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus};
24use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size};
25use crate::notice::truncated;
25use crate::notice::truncated;
26use crate::theme;
26use crate::theme;
27
27
@@ -35,6 +35,7 @@ const CAPTION_TOP: f32 = 72.;
35const CAPTION_FADE_SECONDS: f32 = 1.;
35const CAPTION_FADE_SECONDS: f32 = 1.;
36const CAPTION_BACKGROUND: f32 = 0.72;
36const CAPTION_BACKGROUND: f32 = 0.72;
37const FOCUS_RADIUS: f32 = 12.;
37const FOCUS_RADIUS: f32 = 12.;
38const FOCUS_BORDER: f32 = 2.;
38const FOCUS_AVATAR: f32 = 140.;
39const FOCUS_AVATAR: f32 = 140.;
39const CHIP_HEIGHT: f32 = 24.;
40const CHIP_HEIGHT: f32 = 24.;
40const MORE_SIZE: f32 = 28.;
41const MORE_SIZE: f32 = 28.;
@@ -698,6 +699,7 @@ pub fn render_focus_stage(
698 app: &Entity<AppState>,
699 app: &Entity<AppState>,
699 state: &AppState,
700 state: &AppState,
700 focus: &Focus,
701 focus: &Focus,
702 size: (f32, f32),
701 now: Instant,
703 now: Instant,
702) -> Option<AnyElement> {
704) -> Option<AnyElement> {
703 let call = state.call.as_ref()?;
705 let call = state.call.as_ref()?;
@@ -723,10 +725,27 @@ pub fn render_focus_stage(
723 };
725 };
724 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
726 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
725 let picture = match image {
727 let picture = match image {
726 Some(image) => img(ImageSource::Render(image))
728 Some(image) => {
727 .size_full()
729 let picture_size = image.size(0);
728 .object_fit(ObjectFit::Contain)
730 let (width, height) = contain_size(
729 .into_any_element(),
731 (size.0 - 2. * FOCUS_BORDER, size.1 - 2. * FOCUS_BORDER),
732 (picture_size.width.0 as f32, picture_size.height.0 as f32),
733 );
734 div()
735 .size_full()
736 .flex()
737 .items_center()
738 .justify_center()
739 .child(
740 img(ImageSource::Render(image))
741 .w(px(width))
742 .h(px(height))
743 .flex_none()
744 .object_fit(ObjectFit::Fill)
745 .rounded(px(FOCUS_RADIUS)),
746 )
747 .into_any_element()
748 }
730 None => div()
749 None => div()
731 .size_full()
750 .size_full()
732 .flex()
751 .flex()
@@ -743,13 +762,13 @@ pub fn render_focus_stage(
743 let stage = div()
762 let stage = div()
744 .id("call-focus-stage")
763 .id("call-focus-stage")
745 .relative()
764 .relative()
746 .flex_1()
765 .w(px(size.0))
747 .min_w_0()
766 .h(px(size.1))
748 .h_full()
767 .flex_none()
749 .overflow_hidden()
768 .overflow_hidden()
750 .rounded(px(FOCUS_RADIUS))
769 .rounded(px(FOCUS_RADIUS))
751 .bg(hsla(0., 0., 0.04, 1.))
770 .bg(hsla(0., 0., 0.04, 1.))
752 .border_2()
771 .border(px(FOCUS_BORDER))
753 .border_color(if speaking {
772 .border_color(if speaking {
754 theme::green()
773 theme::green()
755 } else {
774 } else {
crates/calling/src/video_pattern.rs +7 −1
@@ -12,6 +12,7 @@ pub const CAMERA_HEIGHT: u32 = 360;
12 12 pub const SCREEN_WIDTH: u32 = 1280;
13 13 pub const SCREEN_HEIGHT: u32 = 720;
14 14 const SQUARE: u32 = 64;
15 const BORDER: u32 = 2;
15 16 const BLOCK_ROWS: u32 = 6;
16 17
17 18 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -63,7 +64,12 @@ fn paint_camera(
63 64 for column in 0..width {
64 65 let inside = column >= square_x && column < square_x + SQUARE && row >= square_y && row < square_y + SQUARE;
65 66 let shade = ((column + tick * 3) * 255 / width) as u8;
66 y_plane[(row * stride_y + column) as usize] = if inside { 235 } else { shade / 2 + 24 };
67 let on_border = column < BORDER || row < BORDER || column >= width - BORDER || row >= height - BORDER;
68 let delta_x = column as i64 - width as i64 / 2;
69 let delta_y = row as i64 - height as i64 / 2;
70 let radius = height as i64 / 2 - 8;
71 let on_circle = (delta_x * delta_x + delta_y * delta_y - radius * radius).abs() < radius * 6;
72 y_plane[(row * stride_y + column) as usize] = if on_border || on_circle || inside { 235 } else { shade / 2 + 24 };
67 73 }
68 74 }
69 75 for row in 0..height / 2 {
@@ -12,6 +12,7 @@ pub const CAMERA_HEIGHT: u32 = 360;
12pub const SCREEN_WIDTH: u32 = 1280;
12pub const SCREEN_WIDTH: u32 = 1280;
13pub const SCREEN_HEIGHT: u32 = 720;
13pub const SCREEN_HEIGHT: u32 = 720;
14const SQUARE: u32 = 64;
14const SQUARE: u32 = 64;
15const BORDER: u32 = 2;
15const BLOCK_ROWS: u32 = 6;
16const BLOCK_ROWS: u32 = 6;
16
17
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -63,7 +64,12 @@ fn paint_camera(
63 for column in 0..width {
64 for column in 0..width {
64 let inside = column >= square_x && column < square_x + SQUARE && row >= square_y && row < square_y + SQUARE;
65 let inside = column >= square_x && column < square_x + SQUARE && row >= square_y && row < square_y + SQUARE;
65 let shade = ((column + tick * 3) * 255 / width) as u8;
66 let shade = ((column + tick * 3) * 255 / width) as u8;
66 y_plane[(row * stride_y + column) as usize] = if inside { 235 } else { shade / 2 + 24 };
67 let on_border = column < BORDER || row < BORDER || column >= width - BORDER || row >= height - BORDER;
68 let delta_x = column as i64 - width as i64 / 2;
69 let delta_y = row as i64 - height as i64 / 2;
70 let radius = height as i64 / 2 - 8;
71 let on_circle = (delta_x * delta_x + delta_y * delta_y - radius * radius).abs() < radius * 6;
72 y_plane[(row * stride_y + column) as usize] = if on_border || on_circle || inside { 235 } else { shade / 2 + 24 };
67 }
73 }
68 }
74 }
69 for row in 0..height / 2 {
75 for row in 0..height / 2 {