Browse Source

Rename variables for clarity

pull/163/head
Fenrir 10 months ago
parent
commit
becdc05abd
  1. 28
      ctru-rs/src/applets/swkbd.rs

28
ctru-rs/src/applets/swkbd.rs

@ -24,7 +24,7 @@ type CallbackFunction = dyn Fn(&str) -> (CallbackResult, Option<Cow<str>>);
#[doc(alias = "SwkbdState")] #[doc(alias = "SwkbdState")]
pub struct SoftwareKeyboard { pub struct SoftwareKeyboard {
state: Box<SwkbdState>, state: Box<SwkbdState>,
callback: Option<Box<CallbackFunction>>, filter_callback: Option<Box<CallbackFunction>>,
initial_text: Option<CString>, initial_text: Option<CString>,
} }
@ -212,7 +212,7 @@ bitflags! {
// Internal book-keeping struct used to send data to `aptSetMessageCallback` when calling the software keyboard. // Internal book-keeping struct used to send data to `aptSetMessageCallback` when calling the software keyboard.
struct MessageCallbackData { struct MessageCallbackData {
callback: *const Box<CallbackFunction>, filter_callback: *const Box<CallbackFunction>,
swkbd_shared_mem_ptr: *mut libc::c_void, swkbd_shared_mem_ptr: *mut libc::c_void,
} }
@ -241,7 +241,7 @@ impl SoftwareKeyboard {
ctru_sys::swkbdInit(state.as_mut(), keyboard_type.into(), buttons.into(), -1); ctru_sys::swkbdInit(state.as_mut(), keyboard_type.into(), buttons.into(), -1);
Self { Self {
state, state,
callback: None, filter_callback: None,
initial_text: None, initial_text: None,
} }
} }
@ -357,7 +357,7 @@ impl SoftwareKeyboard {
/// # /// #
/// # } /// # }
pub fn set_filter_callback(&mut self, callback: Option<Box<CallbackFunction>>) { pub fn set_filter_callback(&mut self, callback: Option<Box<CallbackFunction>>) {
self.callback = callback; self.filter_callback = callback;
} }
/// Configure the maximum number of digits that can be entered in the keyboard when the [`Filters::DIGITS`] flag is enabled. /// Configure the maximum number of digits that can be entered in the keyboard when the [`Filters::DIGITS`] flag is enabled.
@ -712,7 +712,7 @@ impl SoftwareKeyboard {
}; };
} }
if self.callback.is_some() { if self.filter_callback.is_some() {
swkbd.filter_flags |= SWKBD_FILTER_CALLBACK; swkbd.filter_flags |= SWKBD_FILTER_CALLBACK;
} else { } else {
swkbd.filter_flags &= !SWKBD_FILTER_CALLBACK; swkbd.filter_flags &= !SWKBD_FILTER_CALLBACK;
@ -722,19 +722,19 @@ impl SoftwareKeyboard {
unsafe { unsafe {
swkbd.__bindgen_anon_1.reserved.fill(0); swkbd.__bindgen_anon_1.reserved.fill(0);
let mut callback_data = MessageCallbackData { let mut message_callback_data = MessageCallbackData {
callback: std::ptr::null(), filter_callback: std::ptr::null(),
swkbd_shared_mem_ptr, swkbd_shared_mem_ptr,
}; };
// We need to pass a thin pointer to the boxed closure over FFI. Since we know that the callback will finish before // We need to pass a thin pointer to the boxed closure over FFI. Since we know that the message callback will finish before
// `self` is allowed to be moved again, we can safely use a pointer to the local value contained in `self.callback` // `self` is allowed to be moved again, we can safely use a pointer to the local value contained in `self.filter_callback`
if let Some(ref_to_boxed_closure) = self.callback.as_ref() { if let Some(ref_to_boxed_closure) = self.filter_callback.as_ref() {
callback_data.callback = ref_to_boxed_closure as *const _; message_callback_data.filter_callback = ref_to_boxed_closure as *const _;
aptSetMessageCallback( aptSetMessageCallback(
Some(Self::swkbd_message_callback), Some(Self::swkbd_message_callback),
std::ptr::addr_of_mut!(callback_data).cast(), std::ptr::addr_of_mut!(message_callback_data).cast(),
) )
} }
@ -745,7 +745,7 @@ impl SoftwareKeyboard {
swkbd_shared_mem_handle, swkbd_shared_mem_handle,
); );
if self.callback.is_some() { if self.filter_callback.is_some() {
aptSetMessageCallback(None, std::ptr::null_mut()); aptSetMessageCallback(None, std::ptr::null_mut());
} }
@ -821,7 +821,7 @@ impl SoftwareKeyboard {
let text8 = text16.to_string(); let text8 = text16.to_string();
let filter_callback = unsafe { &**data.callback }; let filter_callback = unsafe { &**data.filter_callback };
let (result, retmsg) = filter_callback(&text8); let (result, retmsg) = filter_callback(&text8);

Loading…
Cancel
Save