From 16b82c56ba0adb3579a7b9e2c35532e88ab7ec9e Mon Sep 17 00:00:00 2001 From: Alexis Grojean Date: Wed, 15 Nov 2023 16:52:25 +0100 Subject: [PATCH] Format --- ledger_device_ui_sdk/src/ui.rs | 49 +++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/ledger_device_ui_sdk/src/ui.rs b/ledger_device_ui_sdk/src/ui.rs index 4abef82f..8f8b8c5f 100644 --- a/ledger_device_ui_sdk/src/ui.rs +++ b/ledger_device_ui_sdk/src/ui.rs @@ -2,12 +2,15 @@ use core::str::from_utf8; -use ledger_secure_sdk_sys::{seph, buttons::{get_button_event, ButtonEvent, ButtonsState}}; -use ledger_device_sdk::{io, buttons::ButtonEvent::*}; +use ledger_device_sdk::{buttons::ButtonEvent::*, io}; +use ledger_secure_sdk_sys::{ + buttons::{get_button_event, ButtonEvent, ButtonsState}, + seph, +}; use crate::bitmaps::Glyph; -use crate::bagls::*; +use crate::{bagls::*, fonts::OPEN_SANS}; use crate::layout; use crate::layout::{Draw, Location, StringPlace}; @@ -41,7 +44,6 @@ pub fn get_event(buttons: &mut ButtonsState) -> Option { pub fn clear_screen() { #[cfg(not(target_os = "nanos"))] { - #[cfg(not(feature = "speculos"))] unsafe { ledger_secure_sdk_sys::screen_clear(); @@ -415,15 +417,14 @@ impl<'a> Page<'a> { PageStyle::BoldNormal => { let padding = 1; let mut max_text_lines = 3; - if cfg!(target_os = "nanos") - { + if cfg!(target_os = "nanos") { max_text_lines = 1; } - let total_height = (OPEN_SANS[0].height * max_text_lines) as usize + let total_height = (OPEN_SANS[0].height * max_text_lines) as usize + OPEN_SANS[1].height as usize + 2 * padding as usize; let mut cur_y = Location::Middle.get_y(total_height); - + // Display the chunk count and index if needed if self.chunk_count > 1 { let mut label_bytes = [0u8; MAX_CHAR_PER_LINE]; @@ -445,16 +446,18 @@ impl<'a> Page<'a> { ], &mut label_bytes, ); - from_utf8(&mut label_bytes).unwrap().trim_matches(char::from(0)).place(Location::Custom(cur_y), Layout::Centered, true); + from_utf8(&mut label_bytes) + .unwrap() + .trim_matches(char::from(0)) + .place(Location::Custom(cur_y), Layout::Centered, true); } else { self.label[0].place(Location::Custom(cur_y), Layout::Centered, true); } cur_y += OPEN_SANS[0].height as usize + 2 * padding as usize; - + // If the device is a Nano S, display the second label as // a single line of text - if cfg!(target_os = "nanos") - { + if cfg!(target_os = "nanos") { self.label[1].place(Location::Custom(cur_y), Layout::Centered, false); } // Otherwise, display the second label as up to 3 lines of text @@ -468,9 +471,12 @@ impl<'a> Page<'a> { } let end = (start + MAX_CHAR_PER_LINE).min(len); indices[i] = (start, end); - (&self.label[1][start..end]).place(Location::Custom(cur_y), Layout::Centered, false); + (&self.label[1][start..end]).place( + Location::Custom(cur_y), + Layout::Centered, + false, + ); cur_y += OPEN_SANS[0].height as usize + 2 * padding as usize; - } } } @@ -723,7 +729,7 @@ impl<'a> MultiFieldReview<'a> { } } - pub fn show(&self) -> bool { + pub fn show(&self) -> bool { let mut buttons = ButtonsState::new(); let first_page = match self.review_message.len() { @@ -750,7 +756,8 @@ impl<'a> MultiFieldReview<'a> { [self.cancel_message, ""], self.cancel_glyph, ); - let mut review_pages: [Page; MAX_REVIEW_PAGES] = [Page::new(PageStyle::Normal, ["", ""], None); MAX_REVIEW_PAGES]; + let mut review_pages: [Page; MAX_REVIEW_PAGES] = + [Page::new(PageStyle::Normal, ["", ""], None); MAX_REVIEW_PAGES]; let mut total_page_count = 0; let mut max_chars_per_page = MAX_CHAR_PER_LINE * 3; @@ -766,8 +773,9 @@ impl<'a> MultiFieldReview<'a> { let start = i * max_chars_per_page; let end = (start + max_chars_per_page).min(field.value.len()); let chunk = &field.value[start..end]; - - review_pages[total_page_count] = Page::new(PageStyle::BoldNormal, [field.name, chunk], None); + + review_pages[total_page_count] = + Page::new(PageStyle::BoldNormal, [field.name, chunk], None); review_pages[total_page_count].chunk_count = field_page_count as u8; review_pages[total_page_count].chunk_idx = (i + 1) as u8; // Check if we have reached the maximum number of pages @@ -791,7 +799,7 @@ impl<'a> MultiFieldReview<'a> { RIGHT_ARROW.display(); let mut cur_page = 0; - let mut refresh : bool = true; + let mut refresh: bool = true; review_pages[cur_page].place(); loop { @@ -821,8 +829,7 @@ impl<'a> MultiFieldReview<'a> { } _ => refresh = false, } - if refresh - { + if refresh { clear_screen(); review_pages[cur_page].place(); if cur_page > 0 {