Skip to main content

libobs_wrapper\data\properties\types/
text.rs

1use getters0::Getters;
2
3use crate::{
4    data::properties::{get_enum, macros::unsafe_is_of_type_result, ObsTextInfoType, ObsTextType},
5    run_with_obs,
6};
7
8use super::PropertyCreationInfo;
9
10#[derive(Debug, Getters, Clone)]
11#[skip_new]
12pub struct ObsTextProperty {
13    name: String,
14    description: Option<String>,
15    monospace: bool,
16    text_type: ObsTextType,
17    info_type: ObsTextInfoType,
18    word_wrap: bool,
19}
20
21impl TryFrom<PropertyCreationInfo> for ObsTextProperty {
22    type Error = crate::utils::ObsError;
23
24    fn try_from(
25        PropertyCreationInfo {
26            name,
27            description,
28            pointer,
29            runtime,
30        }: PropertyCreationInfo,
31    ) -> Result<Self, Self::Error> {
32        run_with_obs!(runtime, (pointer), move || {
33            unsafe_is_of_type_result!(Text, pointer)?;
34
35            let info_type = get_enum!(pointer, text_info_type, ObsTextInfoType)?;
36            let text_type = get_enum!(pointer, text_type, ObsTextType)?;
37
38            let monospace = unsafe {
39                // SAFETY: PropertyCreationInfo borrows an unchanged parent tree retained by
40                // property_ptr_to_struct throughout this inline actor conversion.
41                libobs::obs_property_text_monospace(pointer.0)
42            };
43            let word_wrap = unsafe {
44                // SAFETY: PropertyCreationInfo borrows an unchanged parent tree retained by
45                // property_ptr_to_struct throughout this inline actor conversion.
46                libobs::obs_property_text_info_word_wrap(pointer.0)
47            };
48
49            Ok(ObsTextProperty {
50                name,
51                description,
52                monospace,
53                text_type,
54                info_type,
55                word_wrap,
56            })
57        })?
58    }
59}