1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 12:32:02 +00:00

WIP - self-code-review ... Rust

This commit is contained in:
grdddj 2024-01-03 11:32:29 +01:00
parent 8eaa86b2e1
commit 2357e9d5e9
4 changed files with 11 additions and 5 deletions

View File

@ -11,7 +11,6 @@ use crate::{
geometry::{Alignment2D, Offset, Point, Rect},
},
};
use core::cmp::max;
#[cfg(feature = "dma2d")]
use crate::{
@ -27,6 +26,8 @@ use crate::ui::display::{get_color_table, pixeldata};
#[cfg(feature = "framebuffer")]
use crate::trezorhal::{buffers::BufferLine4bpp, dma2d::dma2d_setup_4bpp};
#[cfg(feature = "framebuffer")]
use core::cmp::max;
use super::Color;

View File

@ -35,7 +35,7 @@ const CHOICES: [(&str, PinAction, Option<Icon>, bool, bool); CHOICE_LENGTH] = [
"inputs__delete",
PinAction::Delete,
Some(theme::ICON_DELETE),
true,
true, // without_release
true,
),
(

View File

@ -32,7 +32,7 @@ use crate::{
},
Border, Component, Empty, FormattedText, Label, Never, Qr, Timeout,
},
display::{self, tjpgd::jpeg_info},
display::tjpgd::jpeg_info,
geometry,
layout::{
obj::{ComponentMsgObj, LayoutObj},
@ -51,9 +51,9 @@ use super::{
FidoMsg, Frame, FrameMsg, Homescreen, HomescreenMsg, IconDialog, Lockscreen, MnemonicInput,
MnemonicKeyboard, MnemonicKeyboardMsg, NumberInputDialog, NumberInputDialogMsg,
PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress,
SelectWordCount, SelectWordCountMsg, SelectWordMsg, SimplePage, Slip39Input, WelcomeScreen,
SelectWordCount, SelectWordCountMsg, SelectWordMsg, SimplePage, Slip39Input,
},
constant, theme,
theme,
};
impl TryFrom<CancelConfirmMsg> for Obj {

View File

@ -244,6 +244,8 @@ fn are_there_translations() -> bool {
/// Returns the translation at the given index.
fn get_translation_by_index(index: usize) -> Option<&'static str> {
// TODO: do not use unwrap, probably return None in case of Err?
// --- not to introduce panic in case of corrupted data in flash
let header = unwrap!(TranslationsHeader::from_flash());
let translations_table = header.get_translations_table();
@ -319,6 +321,7 @@ pub struct OffsetLen {
/// Information about specific font - where it starts and how long it is
fn get_font_offset_from_id(font_id: u16) -> Option<OffsetLen> {
// TODO: do not use unwrap?
let font_table = unwrap!(TranslationsHeader::from_flash()).get_font_table();
match_first_u16_pair(
font_id,
@ -359,6 +362,7 @@ fn match_first_u16_pair(
// Get information about a given glyph with a given font-offset
fn get_glyph_data(char_code: u16, font_offset: u16, font_len: u16) -> Option<OffsetLen> {
// TODO: do not use unwrap?
let font_data =
unwrap!(TranslationsHeader::from_flash()).get_font_data_offset(font_offset, font_len);
let data_size = font_data.len() as u16;
@ -386,6 +390,7 @@ fn get_glyph_font_data(char_code: u16, font_id: u16) -> Option<OffsetLen> {
if let Some(font_offset) = get_font_offset_from_id(font_id) {
if let Some(glyph_data) = get_glyph_data(char_code, font_offset.offset, font_offset.len) {
// TODO: do not use unwrap?
let font_start_offset = unwrap!(TranslationsHeader::from_flash()).font_start_offset();
let final_offset = font_start_offset + font_offset.offset + glyph_data.offset;
return Some(OffsetLen {