1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-09 06:02:40 +00:00

fix(core/ui): make cancel the last menu item

[no changelog]
This commit is contained in:
Ioan Bizău 2024-11-28 17:25:55 +01:00 committed by Vít Obrusník
parent 5c8ee873c6
commit aa58ea7158

View File

@ -1,3 +1,5 @@
use heapless::Vec;
use crate::{ use crate::{
error::{self, Error}, error::{self, Error},
maybe_trace::MaybeTrace, maybe_trace::MaybeTrace,
@ -330,25 +332,26 @@ fn create_menu(
prompt_screen: Option<TString<'static>>, prompt_screen: Option<TString<'static>>,
) -> Result<SwipeFlow, Error> { ) -> Result<SwipeFlow, Error> {
if let ConfirmActionExtra::Menu(menu_strings) = extra { if let ConfirmActionExtra::Menu(menu_strings) = extra {
// NB: The Cancel menu item is always the first, let mut menu = VerticalMenu::empty();
// because of the MENU_ITEM_CANCEL = 0. let mut menu_items = Vec::<usize, 2>::new();
// If we want the cancel item to be somewhere else,
// we would need to account for that and we could not use a constant.
let mut menu_choices =
VerticalMenu::empty().danger(theme::ICON_CANCEL, menu_strings.verb_cancel);
if let Some(verb_info) = menu_strings.verb_info { if let Some(verb_info) = menu_strings.verb_info {
// The Info menu item (if present) has to be the 2nd, menu = menu.item(theme::ICON_CHEVRON_RIGHT, verb_info);
// because of MENU_ITEM_INFO = 1! unwrap!(menu_items.push(MENU_ITEM_INFO));
menu_choices = menu_choices.item(theme::ICON_CHEVRON_RIGHT, verb_info);
} }
let content_menu = Frame::left_aligned("".into(), menu_choices) menu = menu.danger(theme::ICON_CANCEL, menu_strings.verb_cancel);
unwrap!(menu_items.push(MENU_ITEM_CANCEL));
let content_menu = Frame::left_aligned("".into(), menu)
.with_cancel_button() .with_cancel_button()
.with_swipe(Direction::Right, SwipeSettings::immediate()); .with_swipe(Direction::Right, SwipeSettings::immediate());
let content_menu = content_menu.map(move |msg| match msg { let content_menu = content_menu.map(move |msg| match msg {
FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)), FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => {
let selected_item = menu_items[i];
Some(FlowMsg::Choice(selected_item))
}
FrameMsg::Button(_) => Some(FlowMsg::Cancelled), FrameMsg::Button(_) => Some(FlowMsg::Cancelled),
}); });