From f5a82152394fde4d8f740f664ab7737b82861618 Mon Sep 17 00:00:00 2001 From: cashmere Date: Tue, 28 Jul 2026 19:41:16 +0200 Subject: feat: GPUI desktop port foundation - scene crate: full project/scene/element model, serde round-trip proven against the web SerializedProject shape - transfer crate: .ocp zip container, cross-compat with web fflate archives proven in both directions - storage crate: filesystem project store replacing IndexedDB, .ocp import/export - media crate: ffmpeg-next 8 decoder (frames, audio, thumbnails, waveform summaries) - playback crate: wall-clock anchored, frame-rounded playback clock - gpu crate: native texture readback; compositor renders headless offscreen on Vulkan (spike test) - flake devshell: rust toolchain, GPUI native deps, ffmpeg dev, bindgen clang args; GPUI hello-world builds - port plan in notes/gpui-port.md --- rust/crates/timeline/src/placement/insert_index.rs | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 rust/crates/timeline/src/placement/insert_index.rs (limited to 'rust/crates/timeline/src/placement/insert_index.rs') diff --git a/rust/crates/timeline/src/placement/insert_index.rs b/rust/crates/timeline/src/placement/insert_index.rs new file mode 100644 index 00000000..b0feaec6 --- /dev/null +++ b/rust/crates/timeline/src/placement/insert_index.rs @@ -0,0 +1,81 @@ +use scene::SceneTracks; + +use super::InsertDirection; +use crate::types::TrackType; + +pub fn get_default_insert_index_for_track(tracks: &SceneTracks, track_type: TrackType) -> usize { + if track_type == TrackType::Audio { + return tracks.overlay.len() + 1 + tracks.audio.len(); + } + + if track_type == TrackType::Effect { + return 0; + } + + tracks.overlay.len() +} + +pub fn get_highest_insert_index_for_track(tracks: &SceneTracks, track_type: TrackType) -> usize { + if track_type == TrackType::Audio { + return tracks.overlay.len() + 1; + } + + 0 +} + +pub struct PreferredNewTrackPlacement { + pub insert_index: usize, + pub insert_position: Option, +} + +pub fn resolve_preferred_new_track_placement( + tracks: &SceneTracks, + track_type: TrackType, + preferred_index: usize, + direction: InsertDirection, +) -> PreferredNewTrackPlacement { + let track_count = tracks.overlay.len() + 1 + tracks.audio.len(); + if track_count == 0 { + return PreferredNewTrackPlacement { + insert_index: 0, + insert_position: (track_type == TrackType::Audio) + .then_some(InsertDirection::Below), + }; + } + + let safe_preferred_index = preferred_index.min(track_count - 1); + let main_track_index = tracks.overlay.len(); + + if track_type == TrackType::Audio { + if safe_preferred_index <= main_track_index { + return PreferredNewTrackPlacement { + insert_index: main_track_index + 1, + insert_position: Some(InsertDirection::Below), + }; + } + + return PreferredNewTrackPlacement { + insert_index: match direction { + InsertDirection::Above => safe_preferred_index, + InsertDirection::Below => safe_preferred_index + 1, + }, + insert_position: Some(direction), + }; + } + + let insert_index = match direction { + InsertDirection::Above => safe_preferred_index, + InsertDirection::Below => safe_preferred_index + 1, + }; + if insert_index > main_track_index { + return PreferredNewTrackPlacement { + insert_index: main_track_index, + insert_position: Some(InsertDirection::Above), + }; + } + + PreferredNewTrackPlacement { + insert_index, + insert_position: Some(direction), + } +} -- cgit v1.3.1