Skip to content

Commit

Permalink
Merge pull request #139 from adryzz/swkbd-initial-text
Browse files Browse the repository at this point in the history
add `set_initial_text` swkbd method
  • Loading branch information
ian-h-chamberlain authored Oct 29, 2023
2 parents a636722 + 2e44275 commit 4d718c4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

use bitflags::bitflags;
use ctru_sys::{
self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState,
self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText,
swkbdSetInitialText, SwkbdState,
};
use libc;
use std::fmt::Display;
Expand Down Expand Up @@ -336,6 +337,30 @@ impl SoftwareKeyboard {
self.state.max_digits = digits;
}

/// Set the initial text for this software keyboard.
///
/// The initial text is the text already written when you open the software keyboard.
///
/// # Example
///
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # fn main() {
/// #
/// use ctru::applets::swkbd::SoftwareKeyboard;
/// let mut keyboard = SoftwareKeyboard::default();
///
/// keyboard.set_initial_text("Write here what you like!");
/// #
/// # }
#[doc(alias = "swkbdSetInitialText")]
pub fn set_initial_text(&mut self, text: &str) {
unsafe {
let nul_terminated: String = text.chars().chain(once('\0')).collect();
swkbdSetInitialText(self.state.as_mut(), nul_terminated.as_ptr());
}
}

/// Set the hint text for this software keyboard.
///
/// The hint text is the text shown in gray before any text gets written in the input box.
Expand Down

0 comments on commit 4d718c4

Please sign in to comment.