obs_object_builder

Attribute Macro obs_object_builder 

Source
#[obs_object_builder]
Expand description

Generates a builder struct for an OBS object (e.g., a source).

This macro creates a struct that implements ObsObjectBuilder, allowing you to configure and create new instances of an OBS object.

§Arguments

  • attr - The unique ID of the OBS object (e.g., “window_capture”).

§Fields

Each field in the struct must be annotated with #[obs_property(type_t = "...")]. Supported type_t values:

use libobs_wrapper::data::StringEnum;
use libobs_simple_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 an 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,

#[obs_object_builder("my_source")]
pub struct MySourceBuilder {
    #[obs_property(type_t = "string")]
    pub url: String,
}