libui-ng-sys 0.7.0

Bindings to libui-ng
Documentation
// SPDX-License-Identifier: MPL-2.0

//! Bindings to *[libui-ng]*.
//!
//! [libui-ng]: https://github.com/libui-ng/libui-ng

#![allow(
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
)]

macro_rules! reexport {
    ($krate:ident) => {
        pub mod $krate {
            #![doc = concat!(
                "Re-exported items from [`",
                stringify!($krate),
                "`](https://crates.io/crates/",
                stringify!($krate),
                ").",
            )]

            pub use ::$krate::*;
        }
    };
}

reexport!(libc);

// `uiDateTimePicker` functions reference the `tm` struct from `<time.h>`, which we re-export here.
use ::libc::tm;

macro_rules! include_bindings {
    ($name:literal) => {
        include!(concat!(env!("OUT_DIR"), "/", $name, ".rs"));
    };
}

// Include the core, cross-platform bindings.
include_bindings!("bindings");
include_bindings!("bindings-control-sigs");

/// Platform-specific functionality.
pub mod platform {
    macro_rules! def_platform {
        (
            mod: $mod:tt,
            platform: $platform:literal,
            header: $header:literal,
            os: $os:literal
            $(
                , prelude: {
                    $($prelude_item:item)*
                }
            )? $(,)?
        ) => {
            #[doc = concat!("Additional features available on ", $platform, " platforms.")]
            #[cfg(target_os = $os)]
            pub mod $mod {
                use crate::*;

                $(
                    $($prelude_item)*
                )?

                // Include the platform-specific bindings.
                include_bindings!($header);
            }
        };
    }

    def_platform! {
        mod: darwin,
        platform: "Darwin",
        header: "bindings-darwin",
        os: "macos",
        prelude: {
            // TODO: Is there an established crate of Cocoa bindings that can replace this?

            reexport!(objc);

            use ::objc::runtime::BOOL;

            macro_rules! def_classes {
                ($($name:ident)*) => {
                    $(
                        pub type $name = ::objc::runtime::Object;
                    )*
                };
            }

            def_classes! {
                NSControl
                NSString
                NSView
            }

            // See <https://developer.apple.com/documentation/objectivec/nsinteger>.
            pub type NSInteger = libc::c_long;
            // See <https://developer.apple.com/documentation/objectivec/nsuinteger>.
            pub type NSUInteger = libc::c_ulong;
            // See <https://developer.apple.com/documentation/appkit/nscontrolsize>.
            pub type NSControlSize = NSUInteger;
            // See <https://developer.apple.com/documentation/appkit/nslayoutconstraintorientation>.
            pub type NSLayoutConstraintOrientation = NSInteger;
            // See <https://developer.apple.com/documentation/appkit/nslayoutpriority>.
            pub type NSLayoutPriority = libc::c_float;

            // `CGFloat` doesn't appear to have proper Objective-C documentation anymore, so you can
            // see its definition here:
            // <https://github.com/phracker/MacOSX-SDKs/blob/041600eda65c6a668f66cb7d56b7d1da3e8bcc93/MacOSX11.3.sdk/System/Library/Frameworks/CoreGraphics.framework/Versions/A/Headers/CGBase.h#L334-L348>.
            #[cfg(target_pointer_width = "64")]
            pub type CGFloat = libc::c_double;
            #[cfg(not(target_pointer_width = "64"))]
            pub type CGFloat = libc::c_float;
        },
    }
    def_platform! {
        mod: unix,
        platform: "Unix",
        header: "bindings-unix",
        os: "linux",
        prelude: {
            reexport!(glib_sys);
            reexport!(gtk_sys);

            use ::glib_sys::gboolean;
            use ::gtk_sys::GtkContainer;
        },
    }
    def_platform! {
        mod: windows,
        platform: "Windows",
        header: "bindings-windows",
        os: "windows",
        prelude: {
            reexport!(windows_sys);

            use ::windows_sys::Win32::Foundation::{
                BOOL,
                HINSTANCE,
                HWND,
                RECT,
            };

            // `windows_sys` doesn't provide these for some reason, so we have to do this ourselves.
            // See <https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types> for
            // reference.

            pub type DWORD = libc::c_ulong;
            pub type LONG = libc::c_long;
            // TODO: Is this semantically correct?
            pub type LONG_PTR = isize;
            pub type LPCWSTR = *const WCHAR;
            pub type LPVOID = *mut libc::c_void;
            pub type WCHAR = libc::wchar_t;
        },
    }
}