1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
use core::mem::transmute; use core::slice; use cstr_core::CStr; use ndless_sys::_show_msgbox; use crate::cstr; use crate::prelude::*; #[repr(u32)] #[derive(Debug)] pub enum Button { ONE = 1, TWO = 2, THREE = 3, } pub fn msg(title: impl Into<String>, msg: impl Into<String>) { let title = cstr!(title.into()); let msg = cstr!(msg.into()); unsafe { _show_msgbox(title.as_ptr(), msg.as_ptr(), 0); } } pub fn msg_2b( title: impl Into<String>, msg: impl Into<String>, btn1: impl Into<String>, btn2: impl Into<String>, ) -> Button { let title = cstr!(title.into()); let msg = cstr!(msg.into()); let btn1 = cstr!(btn1.into()); let btn2 = cstr!(btn2.into()); unsafe { transmute(_show_msgbox( title.as_ptr(), msg.as_ptr(), 2, btn1.as_ptr(), btn2.as_ptr(), )) } } pub fn msg_3b( title: impl Into<String>, msg: impl Into<String>, btn1: impl Into<String>, btn2: impl Into<String>, btn3: impl Into<String>, ) -> Button { let title = cstr!(title.into()); let msg = cstr!(msg.into()); let btn1 = cstr!(btn1.into()); let btn2 = cstr!(btn2.into()); let btn3 = cstr!(btn3.into()); unsafe { transmute(_show_msgbox( title.as_ptr(), msg.as_ptr(), 3, btn1.as_ptr(), btn2.as_ptr(), btn3.as_ptr(), )) } } pub fn msg_numeric( title: impl Into<String>, subtitle: impl Into<String>, msg: impl Into<String>, min: i32, max: i32, ) -> Option<i32> { let title = cstr!(title.into()); let subtitle = cstr!(subtitle.into()); let msg = cstr!(msg.into()); let mut num = 0i32; match unsafe { ndless_sys::show_1numeric_input( title.as_ptr(), subtitle.as_ptr(), msg.as_ptr(), &mut num, min, max, ) } { 1 => Some(num), _ => None, } } pub fn msg_2numeric( title: impl Into<String>, subtitle: impl Into<String>, msg1: impl Into<String>, min1: i32, max1: i32, msg2: impl Into<String>, min2: i32, max2: i32, ) -> Option<(i32, i32)> { let title = cstr!(title.into()); let subtitle = cstr!(subtitle.into()); let msg1 = cstr!(msg1.into()); let msg2 = cstr!(msg2.into()); let mut num1 = 0i32; let mut num2 = 0i32; match unsafe { ndless_sys::show_2numeric_input( title.as_ptr(), subtitle.as_ptr(), msg1.as_ptr(), &mut num1, min1, max1, msg2.as_ptr(), &mut num2, min2, max2, ) } { 1 => Some((num1, num2)), _ => None, } } pub fn msg_input( title: impl Into<String>, msg: impl Into<String>, default: impl Into<String>, ) -> Option<String> { let title = cstr!(title.into()); let msg = cstr!(msg.into()); let default = cstr!(default.into()); let mut ptr: *mut cty::c_char = core::ptr::null_mut(); match unsafe { ndless_sys::show_msg_user_input(title.as_ptr(), msg.as_ptr(), default.as_ptr(), &mut ptr) } { -1 => None, len => unsafe { Some( CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts( ptr as *const u8, len as usize + 1, )) .to_string_lossy() .into_owned(), ) }, } }