Browse Source

Merge pull request #139 from adryzz/swkbd-initial-text

add `set_initial_text` swkbd method
pull/145/head
Ian Chamberlain 1 year ago committed by GitHub
parent
commit
4d718c4100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      ctru-rs/src/applets/swkbd.rs

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

@ -7,7 +7,8 @@
use bitflags::bitflags; use bitflags::bitflags;
use ctru_sys::{ use ctru_sys::{
self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState, self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText,
swkbdSetInitialText, SwkbdState,
}; };
use libc; use libc;
use std::fmt::Display; use std::fmt::Display;
@ -336,6 +337,30 @@ impl SoftwareKeyboard {
self.state.max_digits = digits; 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. /// 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. /// The hint text is the text shown in gray before any text gets written in the input box.

Loading…
Cancel
Save