summaryrefslogtreecommitdiff
path: root/rust/crates/timeline/src/placement/compatibility.rs
blob: 9512af49f0e5cf5b3222841a3e7ac3600fcdcbb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::types::{ElementType, TrackType};

pub fn get_track_type_for_element_type(element_type: ElementType) -> TrackType {
    match element_type {
        ElementType::Audio => TrackType::Audio,
        ElementType::Text => TrackType::Text,
        ElementType::Sticker | ElementType::Graphic => TrackType::Graphic,
        ElementType::Effect => TrackType::Effect,
        ElementType::Video | ElementType::Image => TrackType::Video,
    }
}

pub fn can_element_go_on_track(element_type: ElementType, track_type: TrackType) -> bool {
    get_track_type_for_element_type(element_type) == track_type
}

pub struct TrackCompatibility {
    pub is_valid: bool,
    pub error_message: Option<String>,
}

pub fn validate_element_track_compatibility(
    element_type: ElementType,
    track_type: TrackType,
) -> TrackCompatibility {
    let is_valid = can_element_go_on_track(element_type, track_type);

    if !is_valid {
        return TrackCompatibility {
            is_valid: false,
            error_message: Some(format!(
                "{} elements cannot be placed on {} tracks",
                element_type.as_str(),
                track_type.as_str(),
            )),
        };
    }

    TrackCompatibility {
        is_valid: true,
        error_message: None,
    }
}