1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-24 09:48:45 +00:00

feat(eckhart): extract tile pattern constants

This commit is contained in:
obrusvit 2025-04-23 17:02:05 +02:00
parent 08c9ece0e0
commit b2d334272e
3 changed files with 45 additions and 43 deletions

View File

@ -679,6 +679,10 @@ impl Grid {
let to = self.row_col(cells.to.0, cells.to.1);
from.union(to)
}
pub const fn cell_count(&self) -> usize {
self.rows * self.cols
}
}
#[derive(Copy, Clone)]

View File

@ -6,7 +6,7 @@ use crate::{
ui::{
component::{text::TextStyle, Component, Event, EventCtx, Label, Never},
display::{image::ImageInfo, Color},
geometry::{Alignment2D, Grid, Insets, Offset, Point, Rect},
geometry::{Alignment2D, Insets, Offset, Point, Rect},
layout::util::get_user_custom_image,
lerp::Lerp,
shape::{self, Renderer},
@ -20,7 +20,7 @@ use super::{
fonts,
},
constant::{HEIGHT, SCREEN, WIDTH},
theme::{self, firmware::button_homebar_style, BG, BLACK, GREY_EXTRA_DARK},
theme::{self, firmware::button_homebar_style, TILES_GRID},
ActionBar, ActionBarMsg, Hint, HoldToConfirmAnim,
};
@ -235,10 +235,10 @@ impl HomeLabel {
const LABEL_TEXT_STYLE: TextStyle = theme::firmware::TEXT_BIG;
const LABEL_SHADOW_TEXT_STYLE: TextStyle = TextStyle::new(
fonts::FONT_SATOSHI_EXTRALIGHT_46,
BLACK,
BLACK,
BLACK,
BLACK,
theme::BLACK,
theme::BLACK,
theme::BLACK,
theme::BLACK,
);
fn new(label: TString<'static>) -> Self {
@ -282,26 +282,9 @@ pub fn check_homescreen_format(image: BinaryData) -> bool {
}
fn render_default_hs<'a>(target: &mut impl Renderer<'a>, led_color: Option<Color>) {
const DEFAULT_HS_TILE_ROWS: usize = 4;
const DEFAULT_HS_TILE_COLS: usize = 4;
const DEFAULT_HS_AREA: Rect = SCREEN.inset(Insets::bottom(140));
const DEFAULT_HS_GRID: Grid =
Grid::new(DEFAULT_HS_AREA, DEFAULT_HS_TILE_ROWS, DEFAULT_HS_TILE_COLS);
const DEFAULT_HS_TILES_2: [(usize, usize); 9] = [
(0, 0),
(1, 0),
(1, 3),
(2, 3),
(3, 2),
(3, 3),
(4, 0),
(4, 2),
(4, 3),
];
// Layer 1: Base Solid Colour
shape::Bar::new(SCREEN)
.with_bg(GREY_EXTRA_DARK)
.with_bg(theme::GREY_EXTRA_DARK)
.render(target);
// Layer 2: Base Gradient overlay
@ -309,7 +292,7 @@ fn render_default_hs<'a>(target: &mut impl Renderer<'a>, led_color: Option<Color
let slice = Rect::new(Point::new(SCREEN.x0, y), Point::new(SCREEN.x1, y + 1));
let factor = (y - SCREEN.y0) as f32 / SCREEN.height() as f32;
shape::Bar::new(slice)
.with_bg(BG)
.with_bg(theme::BG)
.with_alpha(u8::lerp(u8::MIN, u8::MAX, factor))
.render(target);
}
@ -321,19 +304,17 @@ fn render_default_hs<'a>(target: &mut impl Renderer<'a>, led_color: Option<Color
// Layer 4: Tile pattern
// TODO: improve frame rate
for row in 0..DEFAULT_HS_TILE_ROWS {
for col in 0..DEFAULT_HS_TILE_COLS {
let tile_area = DEFAULT_HS_GRID.row_col(row, col);
let icon = if DEFAULT_HS_TILES_2.contains(&(row, col)) {
theme::ICON_HS_TILE_2.toif
} else {
theme::ICON_HS_TILE_1.toif
};
shape::ToifImage::new(tile_area.top_left(), icon)
.with_align(Alignment2D::TOP_LEFT)
.with_fg(BLACK)
.render(target);
}
for idx in 0..TILES_GRID.cell_count() {
let tile_area = TILES_GRID.cell(idx);
let icon = if theme::TILES_SLASH_INDICES.contains(&idx) {
theme::ICON_TILE_STRIPES_SLASH.toif
} else {
theme::ICON_TILE_STRIPES_BACKSLASH.toif
};
shape::ToifImage::new(tile_area.top_left(), icon)
.with_align(Alignment2D::TOP_LEFT)
.with_fg(theme::BLACK)
.render(target);
}
}
@ -379,7 +360,7 @@ fn render_led_simulation<'a>(color: Color, target: &mut impl Renderer<'a>) {
// edges)
let dist_from_mid = (x - X_MID).abs() as f32 / X_HALF_WIDTH;
shape::Bar::new(slice)
.with_bg(BG)
.with_bg(theme::BG)
.with_alpha(u8::lerp(u8::MIN, u8::MAX, dist_from_mid))
.render(target);
}

View File

@ -6,7 +6,12 @@ pub mod firmware;
#[cfg(feature = "micropython")]
pub use firmware::*;
use crate::ui::{component::text::TextStyle, display::Color, geometry::Insets, util::include_icon};
use crate::ui::{
component::text::TextStyle,
display::Color,
geometry::{Grid, Insets, Offset, Rect},
util::include_icon,
};
use super::{
component::{ButtonStyle, ButtonStyleSheet},
@ -51,6 +56,18 @@ pub const SIDE_INSETS: Insets = Insets::sides(PADDING);
pub const ACTION_BAR_HEIGHT: i16 = 90; // [px]
pub const TEXT_VERTICAL_SPACING: i16 = 24; // [px]
// Tile pattern grid constants
const TILE_SIZE: i16 = ICON_TILE_STRIPES_BACKSLASH.toif.width();
const TILES_ROWS: i16 = 6;
const TILES_COLS: i16 = 4;
// Slightly larger than SCREEN because the bottom row is not full
const TILES_AREA: Rect =
Rect::from_size(Offset::new(TILES_COLS * TILE_SIZE, TILES_ROWS * TILE_SIZE));
/// Grid for the tiles pattern used in default homescreen and progress screen.
pub const TILES_GRID: Grid = Grid::new(TILES_AREA, TILES_ROWS as usize, TILES_COLS as usize);
/// Indices of the tiles that are slashes ("///") in the default pattern.
pub const TILES_SLASH_INDICES: [usize; 12] = [0, 4, 7, 11, 14, 15, 16, 18, 19, 20, 22, 23];
// UI icons (white color).
include_icon!(ICON_CHEVRON_DOWN, "layout_eckhart/res/chevron_down.toif");
include_icon!(
@ -111,13 +128,13 @@ include_icon!(ICON_BORDER_TR, "layout_eckhart/res/border/TR.toif");
include_icon!(ICON_PLUS, "layout_eckhart/res/plus.toif");
include_icon!(ICON_MINUS, "layout_eckhart/res/minus.toif");
// Icon tiles for default homescreen
// Icon tiles for default pattern
include_icon!(
ICON_HS_TILE_1,
ICON_TILE_STRIPES_BACKSLASH, // for "\\\"
"layout_eckhart/res/defaut_homescreen/hs_tile1.toif"
);
include_icon!(
ICON_HS_TILE_2,
ICON_TILE_STRIPES_SLASH, // for "///"
"layout_eckhart/res/defaut_homescreen/hs_tile2.toif"
);