nappgui 0.2.0

Rust bindings to NAppGUI
Documentation
pub(crate) mod button;
pub(crate) mod cell;
pub(crate) mod combo;
pub(crate) mod control;
pub(crate) mod edit;
pub(crate) mod imageview;
pub(crate) mod label;
pub(crate) mod layout;
pub(crate) mod listbox;
pub(crate) mod menu;
pub(crate) mod menuitem;
pub(crate) mod panel;
pub(crate) mod popup;
pub(crate) mod progress;
pub(crate) mod slider;
pub(crate) mod splitview;
pub(crate) mod tableview;
pub(crate) mod textview;
pub(crate) mod updown;
pub(crate) mod view;
pub(crate) mod webview;
pub(crate) mod window;

/// Common dialogs are default windows provided by the operating system to perform daily tasks such
/// as: Open files, select colors, fonts, etc.
pub mod dialog;
/// Events are messages that are generated by the user interface and that can be handled by the
pub mod event;

use crate::draw_2d::ImageInner;
pub use {
    button::*, cell::*, combo::*, control::*, edit::*, imageview::*, label::*, layout::*,
    listbox::*, menu::*, menuitem::*, panel::*, popup::*, progress::*, slider::*, splitview::*,
    tableview::*, textview::*, updown::*, view::*, webview::*, window::*,
};

/// Get image from resource
pub fn gui_image(rid: &str) -> ImageInner {
    let rid = std::ffi::CString::new(rid).unwrap();
    let image = unsafe { nappgui_sys::gui_image(rid.as_ptr()) } as *mut nappgui_sys::Image;
    ImageInner { inner: image }
}

/// Get a text string through its resource identifier.
pub fn gui_text(rid: &str) -> String {
    let rid = std::ffi::CString::new(rid).unwrap();
    let text = unsafe { nappgui_sys::gui_text(rid.as_ptr()) };
    let text = unsafe { std::ffi::CStr::from_ptr(text) };
    text.to_string_lossy().to_string()
}

/// Get the contents of a file through its resource identifier.
pub fn gui_file(rid: &str) -> (&[u8], usize) {
    let mut size = 0u32;
    let rid = std::ffi::CString::new(rid).unwrap();
    let file = unsafe { nappgui_sys::gui_file(rid.as_ptr(), &mut size) };
    (
        unsafe { std::slice::from_raw_parts(file, size as usize) },
        size as usize,
    )
}

/// Nappgui resource handler.
pub type NappguiResourceHandler =
    unsafe extern "C" fn(locale: *const std::ffi::c_char) -> *mut nappgui_sys::ResPack;

/// Register a resource package.
pub fn gui_respack(handler: NappguiResourceHandler) {
    unsafe {
        nappgui_sys::gui_respack(Some(handler));
    }
}

/// Set the language of the registered resources with gui_respack.
pub fn gui_language(language: &str) {
    let language = std::ffi::CString::new(language).unwrap();
    unsafe {
        nappgui_sys::gui_language(language.as_ptr());
    }
}