Skip to content

Commit

Permalink
Make initial text argument optional
Browse files Browse the repository at this point in the history
This allows the user to clear the initial_text field by supplying a
`None`
  • Loading branch information
FenrirWolf committed Feb 15, 2024
1 parent 22773f6 commit 9eea3f0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,18 +499,23 @@ impl SoftwareKeyboard {
/// use ctru::applets::swkbd::SoftwareKeyboard;
/// let mut keyboard = SoftwareKeyboard::default();
///
/// keyboard.set_initial_text("Write here what you like!");
/// keyboard.set_initial_text(Some("Write here what you like!"));
/// #
/// # }
#[doc(alias = "swkbdSetInitialText")]
pub fn set_initial_text(&mut self, text: &str) {
unsafe {
self.initial_text = Some(CString::new(text).unwrap());
pub fn set_initial_text(&mut self, text: Option<&str>) {
if let Some(text) = text {
let initial_text = CString::new(text).unwrap();

ctru_sys::swkbdSetInitialText(
self.state.as_mut(),
self.initial_text.as_ref().unwrap().as_ptr(),
);
unsafe {
ctru_sys::swkbdSetInitialText(self.state.as_mut(), initial_text.as_ptr());
}

self.initial_text = Some(initial_text);
} else {
unsafe { ctru_sys::swkbdSetInitialText(self.state.as_mut(), std::ptr::null()) };

self.initial_text = None;
}
}

Expand Down

0 comments on commit 9eea3f0

Please sign in to comment.