|
|
@ -19,68 +19,72 @@ pub struct Swkbd { |
|
|
|
/// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other
|
|
|
|
/// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other
|
|
|
|
/// systems it's the same as a Normal keyboard.
|
|
|
|
/// systems it's the same as a Normal keyboard.
|
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
|
|
|
|
#[repr(u32)] |
|
|
|
pub enum Kind { |
|
|
|
pub enum Kind { |
|
|
|
Normal, |
|
|
|
Normal = ctru_sys::SWKBD_TYPE_NORMAL, |
|
|
|
Qwerty, |
|
|
|
Qwerty = ctru_sys::SWKBD_TYPE_QWERTY, |
|
|
|
Numpad, |
|
|
|
Numpad = ctru_sys::SWKBD_TYPE_NUMPAD, |
|
|
|
Western, |
|
|
|
Western = ctru_sys::SWKBD_TYPE_WESTERN, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Represents which button the user pressed to close the software keyboard.
|
|
|
|
/// Represents which button the user pressed to close the software keyboard.
|
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
|
|
|
|
#[repr(u32)] |
|
|
|
pub enum Button { |
|
|
|
pub enum Button { |
|
|
|
Left, |
|
|
|
Left = ctru_sys::SWKBD_BUTTON_LEFT, |
|
|
|
Middle, |
|
|
|
Middle = ctru_sys::SWKBD_BUTTON_MIDDLE, |
|
|
|
Right, |
|
|
|
Right = ctru_sys::SWKBD_BUTTON_RIGHT, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Error type for the software keyboard.
|
|
|
|
/// Error type for the software keyboard.
|
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
|
|
|
|
#[repr(i32)] |
|
|
|
pub enum Error { |
|
|
|
pub enum Error { |
|
|
|
InvalidInput, |
|
|
|
InvalidInput = ctru_sys::SWKBD_INVALID_INPUT, |
|
|
|
OutOfMem, |
|
|
|
OutOfMem = ctru_sys::SWKBD_OUTOFMEM, |
|
|
|
HomePressed, |
|
|
|
HomePressed = ctru_sys::SWKBD_HOMEPRESSED, |
|
|
|
ResetPressed, |
|
|
|
ResetPressed = ctru_sys::SWKBD_RESETPRESSED, |
|
|
|
PowerPressed, |
|
|
|
PowerPressed = ctru_sys::SWKBD_POWERPRESSED, |
|
|
|
ParentalOk, |
|
|
|
ParentalOk = ctru_sys::SWKBD_PARENTAL_OK, |
|
|
|
ParentalFail, |
|
|
|
ParentalFail = ctru_sys::SWKBD_PARENTAL_FAIL, |
|
|
|
BannedInput, |
|
|
|
BannedInput = ctru_sys::SWKBD_BANNED_INPUT, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Restrictions on keyboard input
|
|
|
|
/// Restrictions on keyboard input
|
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
|
|
|
|
#[repr(u32)] |
|
|
|
pub enum ValidInput { |
|
|
|
pub enum ValidInput { |
|
|
|
Anything, |
|
|
|
Anything = ctru_sys::SWKBD_ANYTHING, |
|
|
|
NotEmpty, |
|
|
|
NotEmpty = ctru_sys::SWKBD_NOTEMPTY, |
|
|
|
NotEmptyNotBlank, |
|
|
|
NotEmptyNotBlank = ctru_sys::SWKBD_NOTEMPTY_NOTBLANK, |
|
|
|
NotBlank, |
|
|
|
NotBlank = ctru_sys::SWKBD_NOTBLANK, |
|
|
|
FixedLen, |
|
|
|
FixedLen = ctru_sys::SWKBD_FIXEDLEN, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bitflags! { |
|
|
|
bitflags! { |
|
|
|
/// Keyboard feature flags
|
|
|
|
/// Keyboard feature flags
|
|
|
|
pub struct Features: u32 { |
|
|
|
pub struct Features: u32 { |
|
|
|
const PARENTAL_PIN = 1 << 0; |
|
|
|
const ParentalPin = ctru_sys::SWKBD_PARENTAL; |
|
|
|
const DARKEN_TOP_SCREEN = 1 << 1; |
|
|
|
const DarkenTopScreen = ctru_sys::SWKBD_DARKEN_TOP_SCREEN; |
|
|
|
const PREDICTIVE_INPUT = 1 << 2; |
|
|
|
const PredictiveInput = ctru_sys::SWKBD_PREDICTIVE_INPUT; |
|
|
|
const MULTILINE = 1 << 3; |
|
|
|
const Multiline = ctru_sys::SWKBD_MULTILINE; |
|
|
|
const FIXED_WIDTH = 1 << 4; |
|
|
|
const FixedWidth = ctru_sys::SWKBD_FIXED_WIDTH; |
|
|
|
const ALLOW_HOME = 1 << 5; |
|
|
|
const AllowHome = ctru_sys::SWKBD_ALLOW_HOME; |
|
|
|
const ALLOW_RESET = 1 << 6; |
|
|
|
const AllowReset = ctru_sys::SWKBD_ALLOW_RESET; |
|
|
|
const ALLOW_POWER = 1 << 7; |
|
|
|
const AllowPower = ctru_sys::SWKBD_ALLOW_POWER; |
|
|
|
const DEFAULT_QWERTY = 1 << 8; |
|
|
|
const DefaultQwerty = ctru_sys::SWKBD_DEFAULT_QWERTY; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bitflags! { |
|
|
|
bitflags! { |
|
|
|
/// Keyboard input filtering flags
|
|
|
|
/// Keyboard input filtering flags
|
|
|
|
pub struct Filters: u32 { |
|
|
|
pub struct Filters: u32 { |
|
|
|
const DIGITS = 1 << 0; |
|
|
|
const DIGITS = ctru_sys::SWKBD_FILTER_DIGITS; |
|
|
|
const AT = 1 << 1; |
|
|
|
const AT = ctru_sys::SWKBD_FILTER_AT; |
|
|
|
const PERCENT = 1 << 2; |
|
|
|
const PERCENT = ctru_sys::SWKBD_FILTER_PERCENT; |
|
|
|
const BACKSLASH = 1 << 3; |
|
|
|
const BACKSLASH = ctru_sys::SWKBD_FILTER_BACKSLASH; |
|
|
|
const PROFANITY = 1 << 4; |
|
|
|
const PROFANITY = ctru_sys::SWKBD_FILTER_PROFANITY; |
|
|
|
const CALLBACK = 1 << 5; |
|
|
|
const CALLBACK = ctru_sys::SWKBD_FILTER_CALLBACK; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -90,7 +94,7 @@ impl Swkbd { |
|
|
|
pub fn init(keyboard_type: Kind, num_buttons: i32) -> Self { |
|
|
|
pub fn init(keyboard_type: Kind, num_buttons: i32) -> Self { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
let mut state = Box::<SwkbdState>::default(); |
|
|
|
let mut state = Box::<SwkbdState>::default(); |
|
|
|
swkbdInit(state.as_mut(), keyboard_type as u32, num_buttons, -1); |
|
|
|
swkbdInit(state.as_mut(), keyboard_type.into(), num_buttons, -1); |
|
|
|
Swkbd { state } |
|
|
|
Swkbd { state } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -123,7 +127,7 @@ impl Swkbd { |
|
|
|
/// this software keyboard.
|
|
|
|
/// this software keyboard.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// If the buffer is too small to contain the entire sequence received from the keyboard,
|
|
|
|
/// If the buffer is too small to contain the entire sequence received from the keyboard,
|
|
|
|
/// the output will be truncated but should still be well-formed UTF-8
|
|
|
|
/// the output will be truncated but should still be well-formed UTF-8.
|
|
|
|
pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result<Button, Error> { |
|
|
|
pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result<Button, Error> { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) { |
|
|
|
match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) { |
|
|
@ -143,7 +147,7 @@ impl Swkbd { |
|
|
|
|
|
|
|
|
|
|
|
/// Configures input validation for this keyboard
|
|
|
|
/// Configures input validation for this keyboard
|
|
|
|
pub fn set_validation(&mut self, validation: ValidInput, filters: Filters) { |
|
|
|
pub fn set_validation(&mut self, validation: ValidInput, filters: Filters) { |
|
|
|
self.state.valid_input = validation as i32; |
|
|
|
self.state.valid_input = validation.into(); |
|
|
|
self.state.filter_flags = filters.bits; |
|
|
|
self.state.filter_flags = filters.bits; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -173,7 +177,7 @@ impl Swkbd { |
|
|
|
let nul_terminated: String = text.chars().chain(once('\0')).collect(); |
|
|
|
let nul_terminated: String = text.chars().chain(once('\0')).collect(); |
|
|
|
swkbdSetButton( |
|
|
|
swkbdSetButton( |
|
|
|
self.state.as_mut(), |
|
|
|
self.state.as_mut(), |
|
|
|
button as u32, |
|
|
|
button.into(), |
|
|
|
nul_terminated.as_ptr(), |
|
|
|
nul_terminated.as_ptr(), |
|
|
|
submit, |
|
|
|
submit, |
|
|
|
); |
|
|
|
); |
|
|
@ -210,3 +214,27 @@ impl Default for Swkbd { |
|
|
|
Swkbd::init(Kind::Normal, 2) |
|
|
|
Swkbd::init(Kind::Normal, 2) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Kind> for u32 { |
|
|
|
|
|
|
|
fn from(value: Kind) -> Self { |
|
|
|
|
|
|
|
value as u32 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Button> for u32 { |
|
|
|
|
|
|
|
fn from(value: Button) -> Self { |
|
|
|
|
|
|
|
value as u32 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Error> for u32 { |
|
|
|
|
|
|
|
fn from(value: Error) -> Self { |
|
|
|
|
|
|
|
value as u32 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<ValidInput> for i32 { |
|
|
|
|
|
|
|
fn from(value: ValidInput) -> Self { |
|
|
|
|
|
|
|
value as i32 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|