Attribute Macro obs_object_builder

Source
#[obs_object_builder]
Expand description

This macro is used to generate a builder pattern for an obs source.
The attribute should be the id of the source.
The struct should have named fields, each field should have an attribute #[obs_property(type_t="your_type")].
type_t can be enum, enum_string, string, bool or int.

  • enum: the field should be an enum with num_derive::{FromPrimitive, ToPrimitive}.
  • enum_string: the field should be an enum which implements StringEnum.
  • string: the field should be a string.
  • bool: the field should be a bool.
  • type_t: int, the field should be an i64. The attribute can also have a settings_key which is the key used in the settings, if this attribute is not given, the macro defaults to the field name.
    Documentation is inherited from the field to the setter function.
    Example:
use libobs_wrapper::data::StringEnum;
use libobs_source_macro::obs_object_builder;
use num_derive::{FromPrimitive, ToPrimitive};

#[repr(i32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum ObsWindowCaptureMethod {
    MethodAuto = libobs::window_capture_method_METHOD_AUTO,
	MethodBitBlt = libobs::window_capture_method_METHOD_BITBLT,
	MethodWgc = libobs::window_capture_method_METHOD_WGC,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ObsGameCaptureRgbaSpace {
    SRgb,
    RGBA2100pq
}

impl StringEnum for ObsGameCaptureRgbaSpace {
    fn to_str(&self) -> &str {
        match self {
            ObsGameCaptureRgbaSpace::SRgb => "sRGB",
            ObsGameCaptureRgbaSpace::RGBA2100pq => "Rec. 2100 (PQ)"
        }
    }
}

/// Provides a easy to use builder for the window capture source.
#[derive(Debug)]
#[obs_object_builder("window_capture")]
pub struct WindowCaptureSourceBuilder {
#[obs_property(type_t="enum")]
    /// Sets the capture method for the window capture
    capture_method: ObsWindowCaptureMethod,

    /// Sets the window to capture.
    #[obs_property(type_t = "string", settings_key = "window")]
    window_raw: String,

    #[obs_property(type_t = "bool")]
    /// Sets whether the cursor should be captured
    cursor: bool,

    /// Sets the capture mode for the game capture source. Look at doc for `ObsGameCaptureMode`
    #[obs_property(type_t = "enum_string")]
    capture_mode: ObsGameCaptureMode,
}