Browse Source

Simplify some code + rename vars

pull/157/head
Fenrir 10 months ago
parent
commit
b6fc9a2596
  1. 22
      ctru-rs/src/applets/swkbd.rs

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

@ -8,7 +8,7 @@ use ctru_sys::{
self, aptLaunchLibraryApplet, aptSetMessageCallback, envGetAptAppId, svcCloseHandle, self, aptLaunchLibraryApplet, aptSetMessageCallback, envGetAptAppId, svcCloseHandle,
svcCreateMemoryBlock, APT_SendParameter, SwkbdButton, SwkbdDictWord, SwkbdExtra, svcCreateMemoryBlock, APT_SendParameter, SwkbdButton, SwkbdDictWord, SwkbdExtra,
SwkbdLearningData, SwkbdState, SwkbdStatusData, APPID_SOFTWARE_KEYBOARD, APTCMD_MESSAGE, SwkbdLearningData, SwkbdState, SwkbdStatusData, APPID_SOFTWARE_KEYBOARD, APTCMD_MESSAGE,
NS_APPID, SWKBD_CALLBACK_OK, NS_APPID,
}; };
use bitflags::bitflags; use bitflags::bitflags;
@ -723,10 +723,10 @@ impl SoftwareKeyboard {
.take(swkbd.max_text_len as _) .take(swkbd.max_text_len as _)
.chain(once(0)); .chain(once(0));
let mut initial_text_cursor = SWKBD_SHARED_MEM.cast::<u16>(); let mut initial_text_cursor = SWKBD_SHARED_MEM.cast();
for ch in utf16_iter { for code_point in utf16_iter {
*initial_text_cursor = ch; *initial_text_cursor = code_point;
initial_text_cursor = initial_text_cursor.add(1); initial_text_cursor = initial_text_cursor.add(1);
} }
} }
@ -860,7 +860,7 @@ impl SoftwareKeyboard {
let text16 = unsafe { let text16 = unsafe {
widestring::Utf16Str::from_slice_unchecked(std::slice::from_raw_parts( widestring::Utf16Str::from_slice_unchecked(std::slice::from_raw_parts(
SWKBD_SHARED_MEM.add(swkbd.text_offset as _).cast::<u16>(), SWKBD_SHARED_MEM.add(swkbd.text_offset as _).cast(),
swkbd.text_length as usize + 1, swkbd.text_length as usize + 1,
)) ))
}; };
@ -880,8 +880,8 @@ impl SoftwareKeyboard {
let retmsg = if !retmsg.is_null() { let retmsg = if !retmsg.is_null() {
unsafe { unsafe {
let len = libc::strlen(retmsg); let len = libc::strlen(retmsg) + 1;
std::str::from_utf8_unchecked(std::slice::from_raw_parts(retmsg, len + 1)) std::str::from_utf8_unchecked(std::slice::from_raw_parts(retmsg, len))
} }
} else { } else {
"\0" "\0"
@ -889,16 +889,12 @@ impl SoftwareKeyboard {
let callback_msg = &mut swkbd.callback_msg; let callback_msg = &mut swkbd.callback_msg;
if swkbd.callback_result > SWKBD_CALLBACK_OK as _ { for (idx, code_point) in retmsg
for (idx, ch) in retmsg
.encode_utf16() .encode_utf16()
.take(callback_msg.len() - 1) .take(callback_msg.len() - 1)
.enumerate() .enumerate()
{ {
callback_msg[idx] = ch; callback_msg[idx] = code_point;
}
} else {
callback_msg[0] = 0;
} }
let _ = APT_SendParameter( let _ = APT_SendParameter(

Loading…
Cancel
Save