Revert "WIP - fix buttons from text"

This reverts commit 83abd76d66.
matejcik 4 months ago
parent a8a2de3a05
commit 8a1c0a5dfe

@ -98,16 +98,6 @@ pub enum TString<'a> {
}
impl TString<'_> {
pub fn str_content(&self) -> &str {
match self {
#[cfg(feature = "micropython")]
Self::Allocated(buf) => buf.as_ref(),
#[cfg(feature = "translations")]
Self::Translation(tr) => tr.translate_from_source(),
Self::Str(s) => s,
}
}
pub fn is_empty(&self) -> bool {
self.map(|s| s.is_empty())
}
@ -117,7 +107,13 @@ impl TString<'_> {
F: for<'a> FnOnce(&'a str) -> T,
T: 'static,
{
fun(self.str_content())
match self {
#[cfg(feature = "micropython")]
Self::Allocated(buf) => fun(buf.as_ref()),
#[cfg(feature = "translations")]
Self::Translation(tr) => tr.map_translated(fun),
Self::Str(s) => fun(s),
}
}
}

@ -15,15 +15,11 @@ impl TranslatedString {
F: for<'a> FnOnce(&'a str) -> T,
T: 'static,
{
fun(self.translate_from_source())
}
pub fn translate_from_source<'a>(self) -> &'a str {
// SAFETY: The bound on F _somehow_ ensures that the reference cannot escape
// the closure. (I don't understand how, but it does), see soundness test below.
// For good measure, we limit the return value to 'static.
let translations = unsafe { super::flash::get() };
self.translate(translations)
fun(self.translate(translations))
}
pub const fn as_tstring(self) -> TString<'static> {

@ -371,10 +371,10 @@ impl ButtonDetails {
/// Resolves text and finds possible icon names.
pub fn from_text_possible_icon(text: TString<'static>) -> Self {
match text.str_content() {
"" => Self::cancel_icon(),
"<" => Self::left_arrow_icon(),
"^" => Self::up_arrow_icon(),
match text {
TString::Str("") => Self::cancel_icon(),
TString::Str("<") => Self::left_arrow_icon(),
TString::Str("^") => Self::up_arrow_icon(),
_ => Self::text(text),
}
}

Loading…
Cancel
Save