Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop-gpui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ Recording-specific deviations:
| **Settings button is inert** | The bar's recording-settings popover menu is not built; the same applies to the gear button in the overlay's start cluster. |
| **No overlay blur** | The recording overlay is `bg-gray-1/80` without `backdrop-blur-xs`; this gpui rev has no per-element backdrop blur hook. The target-select overlay's liquid-glass surfaces drop their `backdrop-blur-xl` for the same reason. |
| **Escape is a focused key handler** | The Tauri app registers Escape as a *global* shortcut while the overlays are up; here it is a key handler on the overlay that holds focus (the one on the cursor's display). Escape pressed while another app is active does not dismiss. |
| **Overlay cluster is start-only** | The device row (camera/microphone selects under the start pill), the mode dropdown behind the caret, and the "What is X Mode?" link are deferred — device pickers live in the main window. The area toolbar shows the size readout but not the aspect-ratio/reset/fill/lock controls. |
| **Overlay cluster is start-only** | The device row (camera/microphone selects under the start pill), the mode dropdown behind the caret, and the "What is X Mode?" link are deferred — device pickers live in the main window. The area toolbar shows the size readout and an aspect-ratio control, but not the reset/fill/lock controls. |
| **Camera-only keeps the bubble** | The TSX inlines a camera preview into the camera-only overlay; ours keeps the separate camera preview window it already has. |
| **Camera id is DeviceID-only** | The Tauri app persists `ModelID` when a camera advertises one, so the same camera survives re-plugging into a different port. |
| **Defaults are the builder's** | `desktop_recording_defaults` (studio quality, fps caps, custom cursor) is not applied yet — it reads the Tauri settings store. |
Expand Down
167 changes: 165 additions & 2 deletions apps/desktop-gpui/src/editor_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,62 @@ pub enum CaptionSlider {
Size,
BackgroundOpacity,
FadeDuration,
ManualX,
ManualY,
}

/// Where Manual placement starts for a preset no caption was drawn at yet, as
/// fractions of the frame (`captionPositionCenter`, `CaptionsTab.tsx:362-378`).
pub fn caption_position_center(position: &str) -> (f32, f32) {
match position {
"top-left" => (0.05, 0.08),
"top-center" | "top" => (0.5, 0.08),
"top-right" => (0.95, 0.08),
"bottom-left" => (0.05, 0.85),
"bottom-right" => (0.95, 0.85),
Comment on lines +465 to +469

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Captions jump when switching

Switching a left- or right-aligned caption to Manual still moves it. caption_position_center treats 5% and 95% as the caption’s centre, but the renderer uses those values for its outer edge. A 400-pixel caption on a 1920-pixel frame moves from a 96-pixel left margin to the frame’s edge. Seed Manual from the rendered box centre rather than its edge.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/editor_tabs.rs
Line: 468-472

Comment:
**Captions jump when switching**

Switching a left- or right-aligned caption to Manual still moves it. `caption_position_center` treats 5% and 95% as the caption’s centre, but the renderer uses those values for its outer edge. A 400-pixel caption on a 1920-pixel frame moves from a 96-pixel left margin to the frame’s edge. Seed Manual from the rendered box centre rather than its edge.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept as is, with the comment corrected. The renderer draws left and right presets from a 5% margin, and the box width needed to centre them exactly only exists inside the renderer's text layout, which the editor does not run. The seed matches the previous editor's captionPositionCenter, centred presets keep their spot exactly, and the new sliders move it from there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed properly now: the captions layer records the centre of the box it last drew, as fractions of the frame, with the position it was drawn for (cap_rendering::last_caption_center). Switching to Manual starts from that drawn centre, so a left or right preset keeps its margin; the preset table is only the fallback when nothing has been drawn yet.

_ => (0.5, 0.85),
}
}

pub fn caption_manual_center(settings: &CaptionSettings) -> (f32, f32) {
settings.manual_position.map_or_else(
|| caption_position_center(&settings.position),
|xy| (xy.x, xy.y),
)
}

pub fn set_caption_manual_center(settings: &mut CaptionSettings, x: Option<f32>, y: Option<f32>) {
let (current_x, current_y) = caption_manual_center(settings);
let fraction = |value: f32| (value / 100.).clamp(0., 1.);
settings.position = "manual".to_string();
settings.manual_position = Some(cap_project::XY::new(
x.map_or(current_x, fraction),
y.map_or(current_y, fraction),
));
}

/// Switching the caption position. Entering Manual from a preset seeds the
/// manual centre from that preset (`updateCaptionPosition`,
/// `CaptionsTab.tsx:380-394`); without it Manual drew bottom-centre and had
/// nothing to adjust.
pub fn set_caption_position(settings: &mut CaptionSettings, position: &str) {
set_caption_position_from(settings, position, cap_rendering::last_caption_center);
}

/// [`set_caption_position`] with the renderer's last drawn caption centre
/// supplied: left and right presets align the box's edge to a margin, so
/// only the drawn box says where its centre is.
fn set_caption_position_from(
settings: &mut CaptionSettings,
position: &str,
drawn_center: impl FnOnce(&str) -> Option<(f32, f32)>,
) {
if position == "manual" && settings.position != "manual" {
let (x, y) = drawn_center(&settings.position)
.unwrap_or_else(|| caption_position_center(&settings.position));
settings.manual_position = Some(cap_project::XY::new(x, y));
}
settings.position = position.to_string();
}

impl CaptionSlider {
Expand All @@ -463,6 +519,7 @@ impl CaptionSlider {
Self::BackgroundOpacity => (0., 100., 1.),
// `value={[getSetting("fadeDuration") * 100]}` over 0..50.
Self::FadeDuration => (0., 50., 1.),
Self::ManualX | Self::ManualY => (0., 100., 1.),
}
}

Expand All @@ -472,6 +529,8 @@ impl CaptionSlider {
Self::Size => settings.size as f32,
Self::BackgroundOpacity => settings.background_opacity as f32,
Self::FadeDuration => settings.fade_duration * 100.,
Self::ManualX => caption_manual_center(&settings).0 * 100.,
Self::ManualY => caption_manual_center(&settings).1 * 100.,
}
}
}
Expand Down Expand Up @@ -894,9 +953,8 @@ impl EditorWindow {
let Some((value, _)) = CAPTION_POSITIONS.get(index) else {
return;
};
let value = value.to_string();
self.set_caption_setting("caption-position", window, cx, move |settings| {
settings.position = value
set_caption_position(settings, value)
});
}
SidebarMenu::CaptionAnimation => {
Expand Down Expand Up @@ -1087,6 +1145,8 @@ impl EditorWindow {
CaptionSlider::Size => settings.size = value.round() as u32,
CaptionSlider::BackgroundOpacity => settings.background_opacity = value.round() as u32,
CaptionSlider::FadeDuration => settings.fade_duration = value / 100.,
CaptionSlider::ManualX => set_caption_manual_center(settings, Some(value), None),
CaptionSlider::ManualY => set_caption_manual_center(settings, None, Some(value)),
});
}

Expand Down Expand Up @@ -2847,6 +2907,30 @@ impl EditorWindow {
cx,
)),
)
.children((settings.position == "manual").then(|| {
div()
.flex()
.flex_col()
.gap(px(12.))
.child(
self.slider_field(
"Horizontal Position",
SliderKey::Caption(CaptionSlider::ManualX),
"%",
cx,
)
.into_any_element(),
)
.child(
self.slider_field(
"Vertical Position",
SliderKey::Caption(CaptionSlider::ManualY),
"%",
cx,
)
.into_any_element(),
)
}))
.child(
ui::Field::section(&theme, "Animation").child(
div()
Expand Down Expand Up @@ -3477,6 +3561,85 @@ impl EditorWindow {
mod tests {
use super::*;

/// A left-aligned caption sits a margin in from the edge, its centre a
/// half box width further in. Manual starts at that drawn centre, so
/// switching does not move it.
#[test]
fn manual_caption_position_starts_at_the_drawn_caption() {
let mut settings = CaptionSettings {
position: "bottom-left".into(),
..CaptionSettings::default()
};
set_caption_position_from(&mut settings, "manual", |position| {
(position == "bottom-left").then_some((0.16, 0.86))
});
assert_eq!(
settings.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.16, 0.86))
);

// Nothing drawn yet: the preset's table entry.
let mut settings = CaptionSettings {
position: "top-right".into(),
..CaptionSettings::default()
};
set_caption_position_from(&mut settings, "manual", |_| None);
assert_eq!(
settings.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.95, 0.08))
);
}

/// A 0.6.1 report: with the caption position set to Manual, the captions
/// stayed bottom-centre and nothing could move them. Manual now starts
/// where the preset drew them and the sliders move it.
#[test]
fn manual_caption_position_starts_at_the_preset_and_moves() {
let mut settings = CaptionSettings {
position: "top-center".into(),
..CaptionSettings::default()
};
set_caption_position_from(&mut settings, "manual", |_| None);
assert_eq!(settings.position, "manual");
assert_eq!(
settings.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.5, 0.08))
);

set_caption_manual_center(&mut settings, Some(20.), None);
set_caption_manual_center(&mut settings, None, Some(130.));
assert_eq!(
settings.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.2, 1.0))
);
let mut project = ProjectConfiguration::default();
project.captions = Some(CaptionsData {
settings: settings.clone(),
..CaptionsData::default()
});
assert_eq!(CaptionSlider::ManualX.read(&project), 20.);
assert_eq!(CaptionSlider::ManualY.read(&project), 100.);

// Picking Manual again keeps the adjusted spot.
set_caption_position(&mut settings, "manual");
assert_eq!(
settings.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.2, 1.0))
);

// A slider on a preset switches it to Manual from the preset's spot.
let mut preset = CaptionSettings {
position: "bottom-right".into(),
..CaptionSettings::default()
};
set_caption_manual_center(&mut preset, None, Some(50.));
assert_eq!(preset.position, "manual");
assert_eq!(
preset.manual_position.map(|xy| (xy.x, xy.y)),
Some((0.95, 0.5))
);
}

#[test]
fn every_tab_slider_has_the_range_its_call_site_declares() {
assert_eq!(CameraSlider::Size.limits(), (20., 80., 0.1));
Expand Down
22 changes: 22 additions & 0 deletions apps/desktop-gpui/src/editor_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ fn frame_seconds(frame: u32) -> f64 {
frame as f64 / EDITOR_PREVIEW_FPS as f64
}

/// The new end of a timeline that an edit shortened past the playhead.
fn playhead_past_end(playhead: f64, total: f64) -> Option<f64> {
(total > 0.0 && playhead > total).then_some(total)
}

/// Where a seek leaves the playhead. Paused, the engine echoes the seek back
/// as `playhead_changed(frame)`; storing the frame's own time makes that echo
/// a no-op instead of a second whole-editor rebuild for every scrub step.
Expand Down Expand Up @@ -2291,6 +2296,12 @@ impl EditorWindow {
self.timeline.waveform_paths = waveform_paths;
if self.timeline.total_duration > 0.0 {
self.total = self.timeline.total_duration;
// Deleting or trimming the clip under the playhead shortens the
// timeline past it; bring the playhead back to the new end the way
// `setPlayhead` clamps it (`ED/context.ts:2424`).
if let Some(end) = playhead_past_end(self.playhead, self.total) {
self.apply_seek(end);
}
}
}

Expand Down Expand Up @@ -12256,6 +12267,17 @@ fn hex_to_color(rgba: [u8; 4]) -> cap_project::Color {
mod tests {
use super::*;

/// A 0.6.1 log: the user deleted the clip under the playhead, the
/// timeline shrank to before it, and every preview request past the new
/// end found no segment. The playhead goes back to the end instead.
#[test]
fn a_shortened_timeline_brings_the_playhead_back_to_its_end() {
assert_eq!(playhead_past_end(10.0, 4.0), Some(4.0));
assert_eq!(playhead_past_end(2.0, 4.0), None);
assert_eq!(playhead_past_end(4.0, 4.0), None);
assert_eq!(playhead_past_end(3.0, 0.0), None);
}

#[cfg(target_os = "linux")]
#[gpui::test]
#[ignore = "manual preset menu repaint benchmark"]
Expand Down
Loading
Loading