boing 0.7.0

A safe wrapper over libui-ng-sys
Documentation
// SPDX-License-Identifier: MPL-2.0

//! A series of controls aligned to a common line.

use crate::prelude::*;

impl Ui {
    /// Creates a new horizontal [`Axis`].
    ///
    /// Children will be laid out left-to-right along a horizontal line.
    pub fn create_horizontal_axis<'ui>(&'ui self) -> Result<&'ui mut Axis, crate::Error> {
        unsafe { call_libui_new_fn!(ui: self, fn: uiNewHorizontalBox() -> Axis) }
    }

    /// Creates a new vertical [`Axis`].
    ///
    /// Children will be laid out top-to-bottom along a vertical line.
    pub fn create_vertical_axis<'ui>(&'ui self) -> Result<&'ui mut Axis, crate::Error> {
        unsafe { call_libui_new_fn!(ui: self, fn: uiNewVerticalBox() -> Axis) }
    }
}

/// A series of controls aligned to a common line.
///
/// An `Axis` is a container that affixes the centerpoint of child controls to a vertical or
/// horizontal line. Children are appended with [`push_new_child`](Self::push_new_child) and
/// removed with [`remove_child`](Container::remove_child). An axis [can optionally be
/// padded](Self::set_padded), in which case empty space is inserted between adjacent children.
/// (Padding size is determined by the OS.)
///
/// In *libui-ng* parlance, this is equivalent to a `uiBox`. The name `Axis` was chosen to
/// disambiguate from the familiar [`Box`] type in Rust, and also because `Axis` is arguably
/// more descriptive.
#[subcontrol(handle = "uiBox")]
#[derive(Container)]
#[container(
    child_count = "uiBoxNumChildren",
    remove_child = "uiBoxDelete",
)]
pub struct Axis;

impl<'ui> Axis<'ui> {
    /// Determines if this axis is padded.
    ///
    /// Axes are not padded by default.
    #[inline]
    pub fn is_padded(&self) -> bool {
        bool_from_libui(unsafe { uiBoxPadded(self.as_ptr()) })
    }

    /// Sets whether or not this axis is padded.
    #[inline]
    pub fn set_padded(&self, value: bool) {
        unsafe { uiBoxSetPadded(self.as_ptr(), value.into()) };
    }

    /// # Arguments
    ///
    /// When `can_stretch` is `true`, the child control will stretch to fill the axis' container.
    /// Otherwise, controls retain their original size.
    #[bind_push_child(fn = "uiBoxAppend")]
    pub fn push_child(&self, can_stretch: bool, ...) -> _;
}