mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
chore(core/ui): crash on button text too long
[no changelog]
This commit is contained in:
parent
69100c0755
commit
9b8f18577f
@ -136,14 +136,21 @@ pub fn char_to_string(ch: char) -> ShortString {
|
|||||||
/// while the 2nd line contains the rest of the text.
|
/// while the 2nd line contains the rest of the text.
|
||||||
pub fn split_two_lines(text: &str, text_font: Font, available_width: i16) -> (&str, &str) {
|
pub fn split_two_lines(text: &str, text_font: Font, available_width: i16) -> (&str, &str) {
|
||||||
let p = text_font.longest_prefix(available_width, text);
|
let p = text_font.longest_prefix(available_width, text);
|
||||||
if p.is_empty() {
|
let (first_line, second_line) = if p.is_empty() {
|
||||||
// If we cannot find a space to split on, we won't split at all.
|
// If we cannot find a space to split on, we won't split at all.
|
||||||
// It is the caller's responsibility to deal with the extra long 2nd line.
|
// It is the caller's responsibility to deal with the extra long 2nd line.
|
||||||
// (Remember, 2nd line can always be longer than the width, anyway!)
|
// (Remember, 2nd line can always be longer than the width, anyway!)
|
||||||
("", text)
|
("", text)
|
||||||
} else {
|
} else {
|
||||||
(p, text[p.len()..].trim())
|
(p, text[p.len()..].trim())
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "ui_debug")]
|
||||||
|
if text_font.text_width(second_line) > available_width {
|
||||||
|
fatal_error!(&uformat!("Text too long: {}...!", &text[..15]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(first_line, second_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns text to be fit on one line of a given length.
|
/// Returns text to be fit on one line of a given length.
|
||||||
|
Loading…
Reference in New Issue
Block a user