Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(rendering): scale text wrap allowance with output resolution
Aditya Garud4f18e3d2720e
diff --git a/crates/rendering/src/layers/text.rs b/crates/rendering/src/layers/text.rsindex 4a368f71c..8c4971397 100644--- a/crates/rendering/src/layers/text.rs+++ b/crates/rendering/src/layers/text.rs@@ -10,7 +10,7 @@ use glyphon::{use log::warn;use wgpu::{Device, Queue, include_wgsl, util::DeviceExt};-use crate::text::{PreparedText, StaggerEdge, stagger_alpha};+use crate::text::{PreparedText, REFERENCE_HEIGHT, StaggerEdge, stagger_alpha};#[derive(PartialEq)]struct ShapeKey {@@ -507,7 +507,7 @@ impl TextLayer {// the editor genuinely wrapped too.let output_width = output_px[0];let wrap_width = if width < output_width * 0.98 {- (width * 1.05 + 4.0).min(output_width.max(width))+ (width * 1.05 + 4.0 * output_px[1] / REFERENCE_HEIGHT).min(output_width.max(width))} else {width};@@ -1015,6 +1015,26 @@ mod gpu_tests {pixels[index..index + 4].try_into().unwrap()}+ #[test]+ #[ignore = "requires a working wgpu adapter"]+ fn text_wrap_width_scales_with_output_resolution() {+ let (device, queue) = device().expect("A working wgpu adapter is required for this test");+ let mut layer = TextLayer::new(&device, &queue);+ let mut overlay = text([100.0, 100.0, 600.0, 300.0], [0.0; 4]);+ overlay.background_color = None;+ overlay.content = "A line of text near the wrap boundary".to_string();++ layer.prepare(&device, &queue, (1920, 1080), &[overlay.clone()]);+ let width_1080 = layer.buffers[0].size().0.unwrap();++ overlay.bounds = [200.0, 200.0, 1200.0, 600.0];+ overlay.font_size *= 2.0;+ layer.prepare(&device, &queue, (3840, 2160), &[overlay]);+ let width_2160 = layer.buffers[0].size().0.unwrap();++ assert_eq!(width_2160, width_1080 * 2.0);+ }+#[test]#[ignore = "requires a working wgpu adapter"]fn reused_shaping_renders_exactly_like_fresh_shaping_and_follows_edits() {diff --git a/crates/rendering/src/text.rs b/crates/rendering/src/text.rsindex 9f72eca35..e6dd650b0 100644--- a/crates/rendering/src/text.rs+++ b/crates/rendering/src/text.rs@@ -5,7 +5,7 @@ use cap_project::{TextAlign, TextAnimation, TextBackgroundStyle, TextSegment, XY/// export resolution. `size` only positions and wraps the text — it never/// affects glyph size (that coupling is baked away by the config migration/// in cap_project).-const REFERENCE_HEIGHT: f32 = 1080.0;+pub(crate) const REFERENCE_HEIGHT: f32 = 1080.0;pub const MIN_FONT_SIZE: f32 = 8.0;pub const MAX_FONT_SIZE: f32 = 480.0;