Skip to content

Commit 4a08920

Browse files
author
=
committed
Use Utf16Writer for writing into the error applet
1 parent d7cc62d commit 4a08920

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

ctru-rs/src/applets/error.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use crate::services::{apt::Apt, gfx::Gfx};
77

88
use ctru_sys::{errorConf, errorDisp, errorInit};
99

10-
use std::fmt::Write;
11-
1210
/// Configuration struct to set up the Error applet.
1311
#[doc(alias = "errorConf")]
1412
pub struct PopUp {
@@ -54,17 +52,30 @@ impl PopUp {
5452
Self { state }
5553
}
5654

57-
/// Sets the error text to display.
55+
/// Returns a [`Utf16Writer`] that writes its output to the [`PopUp`]'s internal text buffer.
5856
///
5957
/// # Notes
6058
///
61-
/// The text will be converted to UTF-16 for display with the applet, and the message will be truncated if it exceeds
62-
/// 1900 UTF-16 code units in length after conversion.
59+
/// The input string be converted to UTF-16 for display with the applet, and the message will be
60+
/// truncated if it exceeds 1900 UTF-16 code units in length after conversion.
61+
///
62+
/// # Example
63+
///
64+
/// ```
65+
/// # let _runner = test_runner::GdbRunner::default();
66+
/// # fn main() {
67+
/// #
68+
/// use std::fmt::Write;
69+
///
70+
/// let mut popup = PopUp::new(WordWrap::Enabled);
71+
///
72+
/// let _ = write!(popup.writer(), "Look mom, I'm a custom error message!");
73+
/// #
74+
/// # }
75+
/// ```
6376
#[doc(alias = "errorText")]
64-
pub fn set_text(&mut self, text: &str) {
65-
let mut writer = Utf16Writer::new(&mut self.state.Text);
66-
67-
let _ = writer.write_str(text);
77+
pub fn writer<'a>(&'a mut self) -> Utf16Writer<'a> {
78+
Utf16Writer::new(&mut self.state.Text)
6879
}
6980

7081
/// Launches the error applet.

0 commit comments

Comments
 (0)