boing 0.7.0

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

//! A text label.

use crate::prelude::*;

impl Ui {
    /// Creates a new [`Label`] with the given text.
    pub fn create_label<'ui>(
        &'ui self,
        text: impl Into<Vec<u8>>,
    ) -> Result<&'ui mut Label, crate::Error> {
        let text = self.make_cstring(text)?;

        unsafe { call_libui_new_fn!(ui: self, fn: uiNewLabel(text.as_ptr()) -> Label) }
    }
}

/// A text label.
#[subcontrol(handle = "uiLabel")]
pub struct Label;

impl Label<'_> {
    /// The text displayed by this label.
    #[bind_text(fn = "uiLabelText")]
    pub fn text(&self) -> _;

    /// Sets the text displayed by this label.
    ///
    /// This overrides the text supplied to [`Ui::create_label`].
    pub fn set_text(&self, text: impl Into<Vec<u8>>) -> Result<(), crate::Error> {
        let text = self.ui.make_cstring(text)?;
        unsafe { uiLabelSetText(self.as_ptr(), text.as_ptr()) };

        Ok(())
    }
}