libobs_wrapper\data\properties\types/
mod.rs

1//! # Important Notice
2//! All structs in this module use direct obs calls to get the data from the obs_property_t struct. **ALWAYS MAKE SURE THIS IS RUNNING ON THE OBS THREAD**
3
4mod button;
5impl_general_property!(Color);
6mod editable_list;
7impl_general_property!(Font);
8impl_general_property!(FrameRate);
9impl_general_property!(Group);
10impl_general_property!(ColorAlpha);
11mod list;
12mod number;
13mod path;
14mod text;
15
16pub(crate) struct PropertyCreationInfo {
17    pub name: String,
18    pub description: Option<String>,
19    pub pointer: *mut libobs::obs_property,
20}
21
22use std::ffi::CStr;
23
24pub use button::*;
25pub use editable_list::*;
26use libobs::obs_property;
27pub use list::*;
28pub use number::*;
29pub use path::*;
30pub use text::*;
31
32use super::{macros::impl_general_property, ObsProperty, ObsPropertyType};
33
34impl ObsPropertyType {
35    pub fn to_property_struct(&self, pointer: *mut obs_property) -> ObsProperty {
36        let name = unsafe { libobs::obs_property_name(pointer) };
37        let name = unsafe { CStr::from_ptr(name) };
38        let name = name.to_string_lossy().to_string();
39
40        let description = unsafe { libobs::obs_property_description(pointer) };
41        let description = if description.is_null() {
42            None
43        } else {
44            let description = unsafe { CStr::from_ptr(description) };
45            Some(description.to_string_lossy().to_string())
46        };
47
48        let info = PropertyCreationInfo {
49            name,
50            description,
51            pointer,
52        };
53
54        match self {
55            ObsPropertyType::Invalid => ObsProperty::Invalid("Invalid".to_string()),
56            ObsPropertyType::Bool => ObsProperty::Bool,
57            ObsPropertyType::Int => ObsProperty::Int(ObsNumberProperty::<i32>::from(info)),
58            ObsPropertyType::Float => ObsProperty::Float(ObsNumberProperty::<f64>::from(info)),
59            ObsPropertyType::Text => ObsProperty::Text(ObsTextProperty::from(info)),
60            ObsPropertyType::Path => ObsProperty::Path(ObsPathProperty::from(info)),
61            ObsPropertyType::List => ObsProperty::List(ObsListProperty::from(info)),
62            ObsPropertyType::Color => ObsProperty::Color(ObsColorProperty::from(info)),
63            ObsPropertyType::Button => ObsProperty::Button(ObsButtonProperty::from(info)),
64            ObsPropertyType::Font => ObsProperty::Font(ObsFontProperty::from(info)),
65            ObsPropertyType::EditableList => ObsProperty::EditableList(ObsEditableListProperty::from(info)),
66            ObsPropertyType::FrameRate => ObsProperty::FrameRate(ObsFrameRateProperty::from(info)),
67            ObsPropertyType::Group => ObsProperty::Group(ObsGroupProperty::from(info)),
68            ObsPropertyType::ColorAlpha => ObsProperty::ColorAlpha(ObsColorAlphaProperty::from(info))
69        }
70    }
71}