Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(project): add text styles and animation options

Richie McIlroy68668a3ae8eb
diff --git a/apps/desktop-gpui/src/editor_edits.rs b/apps/desktop-gpui/src/editor_edits.rs
index 95594d451..13ce3bf3e 100644
--- a/apps/desktop-gpui/src/editor_edits.rs
+++ b/apps/desktop-gpui/src/editor_edits.rs
@@ -1526,6 +1526,12 @@ pub fn default_text_segment(start: f64, end: f64, track: u32) -> TextSegment {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: Default::default(),
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration: 0.15,
align: Default::default(),
letter_spacing: 0.0,
diff --git a/apps/desktop-gpui/src/editor_panels.rs b/apps/desktop-gpui/src/editor_panels.rs
index 71a3951cb..54b5e98ba 100644
--- a/apps/desktop-gpui/src/editor_panels.rs
+++ b/apps/desktop-gpui/src/editor_panels.rs
@@ -136,6 +136,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 96.,
font_weight: 700.,
italic: false,
+ uppercase: false,
align: TextAlign::Center,
letter_spacing: -1.,
line_height: 1.1,
@@ -156,6 +157,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 44.,
font_weight: 500.,
italic: false,
+ uppercase: false,
align: TextAlign::Center,
letter_spacing: 0.,
line_height: 1.3,
@@ -176,6 +178,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 40.,
font_weight: 600.,
italic: false,
+ uppercase: false,
align: TextAlign::Left,
letter_spacing: 0.,
line_height: 1.25,
@@ -196,6 +199,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 26.,
font_weight: 700.,
italic: false,
+ uppercase: true,
align: TextAlign::Center,
letter_spacing: 6.,
line_height: 1.2,
@@ -216,6 +220,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 160.,
font_weight: 800.,
italic: false,
+ uppercase: false,
align: TextAlign::Center,
letter_spacing: -2.,
line_height: 1.,
@@ -236,6 +241,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 56.,
font_weight: 500.,
italic: true,
+ uppercase: false,
align: TextAlign::Center,
letter_spacing: 0.,
line_height: 1.35,
@@ -256,6 +262,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 36.,
font_weight: 400.,
italic: false,
+ uppercase: false,
align: TextAlign::Left,
letter_spacing: 0.,
line_height: 1.4,
@@ -276,6 +283,7 @@ pub static TEXT_PRESETS: &[TextPreset] = &[
font_size: 44.,
font_weight: 500.,
italic: false,
+ uppercase: false,
align: TextAlign::Left,
letter_spacing: 0.,
line_height: 1.3,
diff --git a/apps/desktop/src/routes/editor/TextOverlay.tsx b/apps/desktop/src/routes/editor/TextOverlay.tsx
index 2ca0d6fff..965d7e486 100644
--- a/apps/desktop/src/routes/editor/TextOverlay.tsx
+++ b/apps/desktop/src/routes/editor/TextOverlay.tsx
@@ -259,6 +259,7 @@ type SegmentWithDefaults = {
fontSize: number;
fontWeight: number;
italic: boolean;
+ uppercase: boolean;
color: string;
backgroundColor: string | null;
align: TextAlign;
@@ -287,6 +288,7 @@ function normalizeSegment(segment: TauriTextSegment): SegmentWithDefaults {
fontSize: segment.fontSize ?? 48,
fontWeight: segment.fontWeight ?? 700,
italic: segment.italic ?? false,
+ uppercase: styled.uppercase ?? false,
color: segment.color ?? "#ffffff",
backgroundColor: styled.backgroundColor ?? null,
align: styled.align ?? "center",
diff --git a/apps/desktop/src/routes/editor/text-presets.ts b/apps/desktop/src/routes/editor/text-presets.ts
index 750b47e37..9405683e9 100644
--- a/apps/desktop/src/routes/editor/text-presets.ts
+++ b/apps/desktop/src/routes/editor/text-presets.ts
@@ -5,6 +5,7 @@ export type TextPresetStyle = {
fontSize: number;
fontWeight: number;
italic: boolean;
+ uppercase: boolean;
align: TextAlign;
letterSpacing: number;
lineHeight: number;
@@ -34,6 +35,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 96,
fontWeight: 700,
italic: false,
+ uppercase: false,
align: "center",
letterSpacing: -1,
lineHeight: 1.1,
@@ -53,6 +55,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 44,
fontWeight: 500,
italic: false,
+ uppercase: false,
align: "center",
letterSpacing: 0,
lineHeight: 1.3,
@@ -73,6 +76,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 40,
fontWeight: 600,
italic: false,
+ uppercase: false,
align: "left",
letterSpacing: 0,
lineHeight: 1.25,
@@ -92,6 +96,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 26,
fontWeight: 700,
italic: false,
+ uppercase: true,
align: "center",
letterSpacing: 6,
lineHeight: 1.2,
@@ -111,6 +116,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 160,
fontWeight: 800,
italic: false,
+ uppercase: false,
align: "center",
letterSpacing: -2,
lineHeight: 1,
@@ -130,6 +136,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 56,
fontWeight: 500,
italic: true,
+ uppercase: false,
align: "center",
letterSpacing: 0,
lineHeight: 1.35,
@@ -149,6 +156,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 36,
fontWeight: 400,
italic: false,
+ uppercase: false,
align: "left",
letterSpacing: 0,
lineHeight: 1.4,
@@ -168,6 +176,7 @@ export const TEXT_PRESETS: TextPreset[] = [
fontSize: 44,
fontWeight: 500,
italic: false,
+ uppercase: false,
align: "left",
letterSpacing: 0,
lineHeight: 1.3,
diff --git a/apps/desktop/src/routes/editor/text.ts b/apps/desktop/src/routes/editor/text.ts
index 2141eb0c3..808d87881 100644
--- a/apps/desktop/src/routes/editor/text.ts
+++ b/apps/desktop/src/routes/editor/text.ts
@@ -31,6 +31,7 @@ export type TextSegment = {
fontSize: number;
fontWeight: number;
italic: boolean;
+ uppercase: boolean;
color: string;
backgroundColor?: string | null;
fadeDuration: number;
@@ -120,6 +121,7 @@ export const defaultTextSegment = (
fontSize: 48,
fontWeight: 700,
italic: false,
+ uppercase: false,
color: "#ffffff",
backgroundColor: undefined,
fadeDuration: 0.15,
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index d9cae5629..92271d6dc 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -1256,7 +1256,23 @@ export type StyleSegment = { start: number; end: number; track: number; enabled:
export type SystemDiagnostics = { macosVersion: MacOSVersionInfo | null; availableEncoders: string[]; screenCaptureSupported: boolean; metalSupported: boolean; gpuName: string | null }
export type TargetUnderCursor = { display_id: DisplayId | null; window: WindowUnderCursor | null }
export type TextAlign = "left" | "center" | "right"
-export type TextAnimation = "none" | "fade" | "slideUp" | "slideDown" | "pop" | "typewriter"
+export type TextAnimation = "none" | "fade" | "slideUp" | "slideDown" | "slideLeft" | "slideRight" | "pop" | "zoom" | "bounce" | "wipe" | "words" | "letters" | "tracking" | "typewriter"
+/**
+ * How a text segment's optional background hugs the text.
+ */
+export type TextBackgroundStyle =
+/**
+ * One rounded rectangle behind the whole block.
+ */
+"box" |
+/**
+ * A capsule: half-height radius and wider side padding.
+ */
+"pill" |
+/**
+ * A marker stroke per laid-out line, hugging each line's ink.
+ */
+"highlight"
/**
* How a text segment shares the frame with the display recording. The
* variants name where the TEXT sits; the display card makes room for it.
@@ -1278,7 +1294,19 @@ export type TextLayout =
* Text in the right half, display card contained in the left half.
*/
"splitRight"
-export type TextSegment = { start: number; end: number; track?: number; enabled?: boolean; content?: string; center?: XY<number>; size?: XY<number>; fontFamily?: string; fontSize?: number; fontWeight?: number; italic?: boolean; color?: string; backgroundColor?: string | null;
+export type TextSegment = { start: number; end: number; track?: number; enabled?: boolean; content?: string; center?: XY<number>; size?: XY<number>; fontFamily?: string; fontSize?: number; fontWeight?: number; italic?: boolean; color?: string; backgroundColor?: string | null; backgroundStyle?: TextBackgroundStyle; uppercase?: boolean;
+/**
+ * Outline px at the 1080p reference height, like `font_size`; 0 disables.
+ */
+strokeWidth?: number; strokeColor?: string;
+/**
+ * Second colour of a horizontal gradient that starts at `color`.
+ */
+gradientColor?: string | null;
+/**
+ * 0..1 soft halo strength in the text colour.
+ */
+glow?: number;
/**
* Legacy symmetric fade. Superseded by the animation fields below; kept
* so configs written by new builds still fade in old builds. The
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index bae633cbd..4e107005f 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -1134,10 +1134,31 @@ pub enum TextAnimation {
Fade,
SlideUp,
SlideDown,
+ SlideLeft,
+ SlideRight,
Pop,
+ Zoom,
+ Bounce,
+ Wipe,
+ Words,
+ Letters,
+ Tracking,
Typewriter,
}
+/// How a text segment's optional background hugs the text.
+#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+pub enum TextBackgroundStyle {
+ /// One rounded rectangle behind the whole block.
+ #[default]
+ Box,
+ /// A capsule: half-height radius and wider side padding.
+ Pill,
+ /// A marker stroke per laid-out line, hugging each line's ink.
+ Highlight,
+}
+
/// How a text segment shares the frame with the display recording. The
/// variants name where the TEXT sits; the display card makes room for it.
#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -1181,6 +1202,21 @@ pub struct TextSegment {
pub color: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub background_color: Option<String>,
+ #[serde(default)]
+ pub background_style: TextBackgroundStyle,
+ #[serde(default)]
+ pub uppercase: bool,
+ /// Outline px at the 1080p reference height, like `font_size`; 0 disables.
+ #[serde(default)]
+ pub stroke_width: f32,
+ #[serde(default = "TextSegment::default_stroke_color")]
+ pub stroke_color: String,
+ /// Second colour of a horizontal gradient that starts at `color`.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub gradient_color: Option<String>,
+ /// 0..1 soft halo strength in the text colour.
+ #[serde(default)]
+ pub glow: f32,
/// Legacy symmetric fade. Superseded by the animation fields below; kept
/// so configs written by new builds still fade in old builds. The
/// `text_anim_version` migration seeds the animation durations from it.
@@ -1246,6 +1282,10 @@ impl TextSegment {
"#ffffff".to_string()
}
+ fn default_stroke_color() -> String {
+ "#000000".to_string()
+ }
+
fn default_fade_duration() -> f64 {
0.15
}
@@ -3582,6 +3622,12 @@ mod tests {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: TextBackgroundStyle::Box,
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration: 0.15,
align: TextAlign::Center,
letter_spacing: 0.0,
@@ -4191,6 +4237,12 @@ mod tests {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: TextBackgroundStyle::Box,
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration: 0.15,
align: TextAlign::Center,
letter_spacing: 0.0,
@@ -4294,6 +4346,12 @@ mod tests {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: TextBackgroundStyle::Box,
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration,
align: TextAlign::Center,
letter_spacing: 0.0,
diff --git a/crates/rendering/src/takeover.rs b/crates/rendering/src/takeover.rs
index 5ba40d57c..43721a851 100644
--- a/crates/rendering/src/takeover.rs
+++ b/crates/rendering/src/takeover.rs
@@ -168,6 +168,12 @@ mod tests {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: Default::default(),
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration: 0.15,
align: TextAlign::Center,
letter_spacing: 0.0,
diff --git a/crates/rendering/src/text.rs b/crates/rendering/src/text.rs
index 6fdbd8c9a..97480b7c5 100644
--- a/crates/rendering/src/text.rs
+++ b/crates/rendering/src/text.rs
@@ -299,6 +299,12 @@ mod tests {
italic: false,
color: "#ffffff".to_string(),
background_color: None,
+ background_style: Default::default(),
+ uppercase: false,
+ stroke_width: 0.0,
+ stroke_color: "#000000".to_string(),
+ gradient_color: None,
+ glow: 0.0,
fade_duration: 0.15,
align: TextAlign::Center,
letter_spacing: 0.0,