Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Nov 15, 2023
1 parent 5d54a2d commit 5e2d480
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions ledger_device_ui_sdk/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

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;

Expand Down Expand Up @@ -41,7 +44,6 @@ pub fn get_event(buttons: &mut ButtonsState) -> Option<ButtonEvent> {
pub fn clear_screen() {
#[cfg(not(target_os = "nanos"))]
{

#[cfg(not(feature = "speculos"))]
unsafe {
ledger_secure_sdk_sys::screen_clear();
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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;

}
}
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5e2d480

Please sign in to comment.