libobs_wrapper\data\properties\types/
mod.rs1mod 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 name: String,
18 description: Option<String>,
19 pointer: Sendable<*mut libobs::obs_property>,
20 runtime: ObsRuntime,
21}
22
23impl PropertyCreationInfo {
24 pub(crate) unsafe fn new(
30 name: String,
31 description: Option<String>,
32 pointer: Sendable<*mut libobs::obs_property>,
33 runtime: ObsRuntime,
34 ) -> Self {
35 Self {
36 name,
37 description,
38 pointer,
39 runtime,
40 }
41 }
42}
43
44use std::ffi::CStr;
45
46pub use button::*;
47pub use editable_list::*;
48use libobs::obs_property;
49pub use list::*;
50pub use number::*;
51pub use path::*;
52pub use text::*;
53
54use crate::{run_with_obs, runtime::ObsRuntime, unsafe_send::Sendable, utils::ObsError};
55
56use super::{macros::impl_general_property, ObsProperty, ObsPropertyType};
57
58impl ObsPropertyType {
59 unsafe fn inner_to_property_struct(
63 &self,
64 runtime: &ObsRuntime,
65 pointer: Sendable<*mut obs_property>,
66 ) -> Result<ObsProperty, ObsError> {
67 let (name, description) = run_with_obs!(runtime, (pointer), move || {
68 let name = unsafe {
69 libobs::obs_property_name(pointer.0)
71 };
72 if name.is_null() {
73 return Err(ObsError::NullPointer(Some(
74 "Property name pointer is null".to_string(),
75 )));
76 }
77
78 let name = unsafe {
79 CStr::from_ptr(name)
82 };
83 let name = name.to_string_lossy().to_string();
84
85 let description = unsafe { libobs::obs_property_description(pointer.0) };
86 let description = if description.is_null() {
87 None
88 } else {
89 let description = unsafe {
90 CStr::from_ptr(description)
93 };
94 Some(description.to_string_lossy().to_string())
95 };
96
97 Ok((name, description))
98 })??;
99
100 let info = PropertyCreationInfo::new(
101 name,
102 description,
103 pointer,
104 runtime.clone(), );
106
107 let data = match self {
108 ObsPropertyType::Invalid => ObsProperty::Invalid,
109 ObsPropertyType::Bool => ObsProperty::Bool,
110 ObsPropertyType::Int => ObsProperty::Int(ObsNumberProperty::<i32>::try_from(info)?),
111 ObsPropertyType::Float => ObsProperty::Float(ObsNumberProperty::<f64>::try_from(info)?),
112 ObsPropertyType::Text => ObsProperty::Text(ObsTextProperty::try_from(info)?),
113 ObsPropertyType::Path => ObsProperty::Path(ObsPathProperty::try_from(info)?),
114 ObsPropertyType::List => ObsProperty::List(ObsListProperty::try_from(info)?),
115 ObsPropertyType::Color => ObsProperty::Color(ObsColorProperty::try_from(info)?),
116 ObsPropertyType::Button => ObsProperty::Button(ObsButtonProperty::try_from(info)?),
117 ObsPropertyType::Font => ObsProperty::Font(ObsFontProperty::try_from(info)?),
118 ObsPropertyType::EditableList => {
119 ObsProperty::EditableList(ObsEditableListProperty::try_from(info)?)
120 }
121 ObsPropertyType::FrameRate => {
122 ObsProperty::FrameRate(ObsFrameRateProperty::try_from(info)?)
123 }
124 ObsPropertyType::Group => ObsProperty::Group(ObsGroupProperty::try_from(info)?),
125 ObsPropertyType::ColorAlpha => {
126 ObsProperty::ColorAlpha(ObsColorAlphaProperty::try_from(info)?)
127 }
128 };
129
130 Ok(data)
131 }
132
133 pub(in crate::data::properties) unsafe fn get_property_struct(
137 &self,
138 runtime: &ObsRuntime,
139 pointer: Sendable<*mut obs_property>,
140 ) -> Result<ObsProperty, ObsError> {
141 self.inner_to_property_struct(runtime, pointer)
142 }
143}