From 2e442752b47b5b09525560cf2257f1deb3021922 Mon Sep 17 00:00:00 2001 From: Lena Date: Wed, 25 Oct 2023 15:33:12 +0200 Subject: [PATCH] add `set_initial_text` swkbd method --- ctru-rs/src/applets/swkbd.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 8497233..69d4329 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -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; @@ -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.