#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
pub(crate) mod util;
pub mod core;
pub mod draw_2d;
pub mod gui;
pub mod osapp;
pub mod prelude {
use std::{fmt, io, string::FromUtf8Error};
use nappgui_sys::{dbindst_t, ferror_t};
pub type GuiState = nappgui_sys::gui_state_t;
pub type GuiOrient = nappgui_sys::gui_orient_t;
pub type GuiCursor = nappgui_sys::gui_cursor_t;
pub type GuiFocus = nappgui_sys::gui_focus_t;
pub type WindowFlag = nappgui_sys::window_flag_t;
pub type Align = nappgui_sys::align_t;
pub type FStyle = nappgui_sys::fstyle_t;
pub type PixFormat = nappgui_sys::pixformat_t;
pub type Vkey = nappgui_sys::vkey_t;
pub type T2Df = nappgui_sys::T2Df;
pub type S2Df = nappgui_sys::S2Df;
pub type V2Df = nappgui_sys::V2Df;
pub type SplitMode = nappgui_sys::split_mode_t;
pub type DBindState = nappgui_sys::dbindst_t;
#[derive(Debug)]
#[non_exhaustive]
pub enum NappguiError {
IoError(io::Error),
Utf8Error(FromUtf8Error),
NullError(std::ffi::NulError),
Internal(NappguiErrorKind),
EnvVarError(std::env::VarError),
ParseIntError(std::num::ParseIntError),
Unknown(String),
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum NappguiErrorKind {
FExists,
FNoPath,
FNoFile,
FBigName,
FNoFiles,
FNoEmpty,
FNoAccess,
FLock,
FBig,
FSeekNeg,
FUnDef,
DbindMemberExists,
DbindTypeExists,
DbindTypeUsed,
DbindAliasSize,
UndefinedError,
}
impl From<ferror_t> for NappguiError {
fn from(err: ferror_t) -> NappguiError {
let err_kind = match err {
ferror_t::ekFEXISTS => NappguiErrorKind::FExists,
ferror_t::ekFNOPATH => NappguiErrorKind::FNoPath,
ferror_t::ekFNOFILE => NappguiErrorKind::FNoFile,
ferror_t::ekFBIGNAME => NappguiErrorKind::FBigName,
ferror_t::ekFNOFILES => NappguiErrorKind::FNoFiles,
ferror_t::ekFNOEMPTY => NappguiErrorKind::FNoEmpty,
ferror_t::ekFNOACCESS => NappguiErrorKind::FNoAccess,
ferror_t::ekFLOCK => NappguiErrorKind::FLock,
ferror_t::ekFUNDEF => NappguiErrorKind::FUnDef,
ferror_t::ekFBIG => NappguiErrorKind::FBig,
ferror_t::ekFSEEKNEG => NappguiErrorKind::FSeekNeg,
_ => NappguiErrorKind::UndefinedError,
};
NappguiError::Internal(err_kind)
}
}
impl From<dbindst_t> for NappguiError {
fn from(err: dbindst_t) -> Self {
let err_kind = match err {
dbindst_t::ekDBIND_MEMBER_EXISTS => NappguiErrorKind::DbindMemberExists,
dbindst_t::ekDBIND_TYPE_EXISTS => NappguiErrorKind::DbindTypeExists,
dbindst_t::ekDBIND_TYPE_USED => NappguiErrorKind::DbindTypeUsed,
dbindst_t::ekDBIND_ALIAS_SIZE => NappguiErrorKind::DbindAliasSize,
_ => NappguiErrorKind::UndefinedError,
};
NappguiError::Internal(err_kind)
}
}
impl std::error::Error for NappguiError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
NappguiError::IoError(err) => Some(err),
NappguiError::NullError(err) => Some(err),
_ => None,
}
}
}
impl fmt::Display for NappguiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
NappguiError::IoError(ref err) => err.fmt(f),
NappguiError::NullError(ref err) => err.fmt(f),
NappguiError::Internal(ref err) => {
write!(f, "An internal error occurred {:?}", err)
}
NappguiError::EnvVarError(ref err) => {
write!(f, "An env var error occurred {:?}", err)
}
NappguiError::Utf8Error(ref err) => {
write!(f, "A UTF8 conversion error occurred {:?}", err)
}
NappguiError::ParseIntError(ref err) => {
write!(f, "An int parsing error occurred {:?}", err)
}
NappguiError::Unknown(ref err) => write!(f, "An unknown error occurred {:?}", err),
}
}
}
impl From<io::Error> for NappguiError {
fn from(err: io::Error) -> NappguiError {
NappguiError::IoError(err)
}
}
impl From<std::ffi::NulError> for NappguiError {
fn from(err: std::ffi::NulError) -> NappguiError {
NappguiError::NullError(err)
}
}
impl From<std::env::VarError> for NappguiError {
fn from(err: std::env::VarError) -> NappguiError {
NappguiError::EnvVarError(err)
}
}
impl From<std::string::FromUtf8Error> for NappguiError {
fn from(err: std::string::FromUtf8Error) -> NappguiError {
NappguiError::Utf8Error(err)
}
}
impl From<std::num::ParseIntError> for NappguiError {
fn from(err: std::num::ParseIntError) -> NappguiError {
NappguiError::ParseIntError(err)
}
}
}