use crate::gui::ControlTrait;
macro_rules! impl_i32_to_enum {
($type: ty, $range: expr) => {
impl TryFrom<i32> for $type {
type Error = crate::error::NappguiError;
fn try_from(value: i32) -> Result<Self, Self::Error> {
if !($range).contains(&value) {
return Err(crate::error::NappguiError::Internal(
crate::error::NappguiErrorKind::UndefinedEnumTransmute,
));
} else {
Ok(unsafe { std::mem::transmute(value) })
}
}
}
};
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum Align {
Left = 1,
Center = 2,
Right = 3,
Justify = 4,
}
impl_i32_to_enum!(Align, 1..=4);
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiState {
On = 1,
Off = 0,
Mixed = 2,
}
impl_i32_to_enum!(GuiState, 0..=2);
#[derive(Clone, Copy)]
pub struct FontStyle {
pub is_normal: bool,
pub is_bold: bool,
pub is_italic: bool,
pub is_strike_out: bool,
pub is_underlined: bool,
pub is_subscript: bool,
pub is_superscript: bool,
pub is_pixels: bool,
pub is_points: bool,
pub is_cell: bool,
}
impl Default for FontStyle {
fn default() -> Self {
Self {
is_normal: true,
is_bold: false,
is_italic: false,
is_strike_out: false,
is_underlined: false,
is_subscript: false,
is_superscript: false,
is_pixels: false,
is_points: false,
is_cell: false,
}
}
}
impl FontStyle {
pub(crate) fn to_fstyle_t(&self) -> u32 {
let mut style = nappgui_sys::_fstyle_t_ekFNORMAL;
if self.is_bold {
style |= nappgui_sys::_fstyle_t_ekFBOLD;
}
if self.is_italic {
style |= nappgui_sys::_fstyle_t_ekFITALIC;
}
if self.is_strike_out {
style |= nappgui_sys::_fstyle_t_ekFSTRIKEOUT;
}
if self.is_underlined {
style |= nappgui_sys::_fstyle_t_ekFUNDERLINE;
}
if self.is_subscript {
style |= nappgui_sys::_fstyle_t_ekFSUBSCRIPT;
}
if self.is_superscript {
style |= nappgui_sys::_fstyle_t_ekFSUPSCRIPT;
}
if self.is_pixels {
style |= nappgui_sys::_fstyle_t_ekFPIXELS;
}
if self.is_points {
style |= nappgui_sys::_fstyle_t_ekFPOINTS;
}
if self.is_cell {
style |= nappgui_sys::_fstyle_t_ekFCELL;
}
style as _
}
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum Scale {
None = 1,
Auto = 2,
Aspect = 3,
AspectDW = 4,
Adjust = 5,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiOrient {
Horizontal = 1,
Vertical = 2,
}
impl_i32_to_enum!(GuiOrient, 1..=2);
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum SplitMode {
Normal = 1,
Fixed0 = 2,
Fixed1 = 3,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiTab {
Key = 1,
BackKey = 2,
Next = 3,
Prev = 4,
Move = 5,
Click = 6,
}
impl_i32_to_enum!(GuiTab, 1..=6);
pub struct FocusInfo {
pub action: GuiTab,
pub(crate) next: *mut nappgui_sys::GuiControl,
}
impl FocusInfo {
pub fn next<T>(&self) -> Option<T>
where
T: ControlTrait,
{
T::from_control_ptr(self.next)
}
}
#[derive(Clone, Copy)]
pub struct WindowFlags {
pub has_outer_border: bool,
pub has_title_bar: bool,
pub has_maximize_button: bool,
pub has_minimize_button: bool,
pub has_close_button: bool,
pub has_resizable_borders: bool,
pub process_return_key: bool,
pub process_escape_key: bool,
pub avoid_hiding_modal: bool,
}
impl Default for WindowFlags {
fn default() -> Self {
Self {
has_outer_border: false,
has_title_bar: true,
has_maximize_button: false,
has_minimize_button: true,
has_close_button: true,
has_resizable_borders: true,
process_return_key: false,
process_escape_key: false,
avoid_hiding_modal: false,
}
}
}
#[allow(missing_docs)]
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum KeyCode {
Undefined = 0,
KeyA = 1,
KeyS = 2,
KeyD = 3,
KeyF = 4,
KeyH = 5,
KeyG = 6,
KeyZ = 7,
KeyX = 8,
KeyC = 9,
KeyV = 10,
Backslash = 11,
KeyB = 12,
KeyQ = 13,
KeyW = 14,
KeyE = 15,
KeyR = 16,
KeyY = 17,
KeyT = 18,
Digit1 = 19,
Digit2 = 20,
Digit3 = 21,
Digit4 = 22,
Digit6 = 23,
Digit5 = 24,
Digit9 = 25,
Digit7 = 26,
Digit8 = 27,
Digit0 = 28,
RCURLY = 29,
KeyO = 30,
KeyU = 31,
LeftCurlyBrace = 32,
KeyI = 33,
KeyP = 34,
Enter = 35,
KeyL = 36,
KeyJ = 37,
Semicolon = 38,
KeyK = 39,
QuestionMark = 40,
Comma = 41,
Minus = 42,
KeyN = 43,
KeyM = 44,
Period = 45,
Tab = 46,
Space = 47,
GreaterThanLessThan = 48,
Back = 49,
Escape = 50,
F17 = 51,
NumpadDecimal = 52,
NumpadMultiply = 53,
NumpadAdd = 54,
NumLock = 55,
NumpadDivide = 56,
NumpadEnter = 57,
NumpadMinus = 58,
F18 = 59,
F19 = 60,
NumpadEqual = 61,
Numpad0 = 62,
Numpad1 = 63,
Numpad2 = 64,
Numpad3 = 65,
Numpad4 = 66,
Numpad5 = 67,
Numpad6 = 68,
Numpad7 = 69,
Numpad8 = 70,
Numpad9 = 71,
F5 = 72,
F6 = 73,
F7 = 74,
F3 = 75,
F8 = 76,
F9 = 77,
F11 = 78,
F13 = 79,
F16 = 80,
F14 = 81,
F10 = 82,
F12 = 83,
F15 = 84,
PageUp = 85,
Home = 86,
Delete = 87,
F4 = 88,
PageDown = 89,
F2 = 90,
End = 91,
F1 = 92,
Left = 93,
Right = 94,
Down = 95,
Up = 96,
ShiftLeft = 97,
ShiftRight = 98,
ControlLeft = 99,
ControlRight = 100,
AltLeft = 101,
AltRight = 102,
Insert = 103,
Exclamation = 104,
Menu = 105,
SuperLeft = 106,
SuperRight = 107,
CapsLock = 108,
Tilde = 109,
Backquote = 110,
Add = 111,
}
impl_i32_to_enum!(KeyCode, 0..=111);
#[allow(missing_docs)]
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum ModifierKey {
None = 0,
Shift = 1,
Control = 2,
Alt = 4,
Command = 8,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiFocus {
Changed = 1,
Keep = 2,
NoNext = 3,
NoResign = 4,
NoAccept = 5,
}
impl_i32_to_enum!(GuiFocus, 1..=5);
impl WindowFlags {
pub(crate) fn to_window_flag_t(&self) -> u32 {
let mut result = 0;
if self.has_outer_border {
result |= nappgui_sys::_window_flag_t_ekWINDOW_EDGE;
}
if self.has_title_bar {
result |= nappgui_sys::_window_flag_t_ekWINDOW_TITLE;
}
if self.has_maximize_button {
result |= nappgui_sys::_window_flag_t_ekWINDOW_MAX;
}
if self.has_minimize_button {
result |= nappgui_sys::_window_flag_t_ekWINDOW_MIN;
}
if self.has_close_button {
result |= nappgui_sys::_window_flag_t_ekWINDOW_CLOSE;
}
if self.has_resizable_borders {
result |= nappgui_sys::_window_flag_t_ekWINDOW_RESIZE;
}
if self.process_return_key {
result |= nappgui_sys::_window_flag_t_ekWINDOW_RETURN;
}
if self.process_escape_key {
result |= nappgui_sys::_window_flag_t_ekWINDOW_ESC;
}
if self.avoid_hiding_modal {
result |= nappgui_sys::_window_flag_t_ekWINDOW_MODAL_NOHIDE;
}
result as u32
}
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiClose {
Cancel = 1,
Accept = 2,
Close = 3,
Deactivate = 4,
}
impl_i32_to_enum!(GuiClose, 1..=4);
#[repr(i32)]
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiCursor {
Arrow = 1,
Hand = 2,
VerticalBar = 3,
Cross = 4,
HorizontalResize = 5,
VerticalResize = 6,
User = 7,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Point2D {
pub x: f32,
pub y: f32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Trans2D {
pub i: Point2D,
pub j: Point2D,
pub position: Point2D,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Size2D {
pub width: f32,
pub height: f32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Rect2D {
pub position: Point2D,
pub size: Size2D,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum PixFormat {
Index1 = 1,
Index2 = 2,
Index4 = 3,
Index8 = 4,
Gray8 = 5,
RGB24 = 6,
RGBA32 = 7,
Image = 8,
}
impl_i32_to_enum!(PixFormat, 1..=8);
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiMouse {
Left = 1,
Right = 2,
Middle = 3,
}
impl_i32_to_enum!(GuiMouse, 1..=3);
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum GuiScroll {
Begin = 1,
End = 2,
StepLeft = 3,
StepRight = 4,
PageLeft = 5,
PageRight = 6,
Thumb = 7,
}
impl_i32_to_enum!(GuiScroll, 1..=7);
#[repr(i32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum EventType {
Label = 1024,
Button = 1025,
PopUp = 1026,
ListBox = 1027,
Slider = 1028,
UpDown = 1029,
TextFilter = 1030,
TextChange = 1031,
FocusResign = 1032,
FocusAccept = 1033,
Focus = 1034,
Menu = 1035,
Draw = 1036,
Overlay = 1037,
Resize = 1038,
Enter = 1039,
Exit = 1040,
Move = 1041,
Down = 1042,
Up = 1043,
Click = 1044,
Drag = 1045,
Wheel = 1046,
KeyDown = 1047,
KeyUp = 1048,
Scroll = 1049,
WindowMoved = 1050,
WindowSizing = 1051,
WindowSize = 1052,
WindowClose = 1053,
Color = 1054,
Theme = 1055,
ObjectChange = 1056,
TableNRows = 1057,
TableBegin = 1058,
TableEnd = 1059,
TableCell = 1060,
TableSelected = 1061,
TableHeadClick = 1062,
TableRowClick = 1063,
}
impl_i32_to_enum!(EventType, 1024..=1063);
pub use crate::gui::event::*;