1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

fix(core): fix model T new-rendering loader

[no changelog]
This commit is contained in:
tychovrahe 2024-08-26 10:28:31 +02:00 committed by TychoVrahe
parent c6a1eba4b6
commit 23d68eb0bb
6 changed files with 116 additions and 59 deletions

View File

@ -52,6 +52,11 @@ use super::theme::bootloader::BLD_WARN_COLOR;
use intro::Intro;
use menu::Menu;
#[cfg(feature = "new_rendering")]
use super::cshape::{render_loader, LoaderRange};
#[cfg(feature = "new_rendering")]
use crate::ui::display::LOADER_MAX;
pub mod intro;
pub mod menu;
pub mod welcome;
@ -113,25 +118,21 @@ impl ModelTTFeatures {
.render(target);
let center = SCREEN.center() + Offset::y(-20);
let inactive_color = bg_color.blend(fg_color, 85);
let end = 360.0 * progress as f32 / 1000.0;
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(inactive_color)
.render(target);
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(fg_color)
.with_end_angle(360.0 * progress as f32 / 1000.0)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER + 2)
.with_bg(fg_color)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER)
.with_bg(bg_color)
.render(target);
render_loader(
center,
inactive_color,
fg_color,
bg_color,
if progress >= LOADER_MAX {
LoaderRange::Full
} else {
LoaderRange::FromTo(0.0, end)
},
target,
);
if let Some((icon, color)) = icon {
shape::ToifImage::new(center, icon.toif)

View File

@ -1,3 +1,7 @@
use super::{
super::cshape::{render_loader, LoaderRange},
theme,
};
#[cfg(feature = "haptic")]
use crate::trezorhal::haptic::{self, HapticEffect};
use crate::{
@ -5,7 +9,7 @@ use crate::{
ui::{
animation::Animation,
component::{Component, Event, EventCtx, Pad},
display::{self, toif::Icon, Color},
display::{self, toif::Icon, Color, LOADER_MAX},
geometry::{Alignment2D, Offset, Rect},
model_tt::constant,
shape::{self, Renderer},
@ -13,8 +17,6 @@ use crate::{
},
};
use super::theme;
const GROWING_DURATION_MS: u32 = 1000;
const SHRINKING_DURATION_MS: u32 = 500;
@ -232,6 +234,12 @@ impl Component for Loader {
let now = Instant::now();
if let Some(progress) = self.progress(now) {
let progress = if animation_disabled() {
display::LOADER_MIN
} else {
progress
};
let style = if progress < display::LOADER_MAX {
self.styles.normal
} else {
@ -242,24 +250,30 @@ impl Component for Loader {
let center = self.pad.area.center();
let inactive_color = Color::black().blend(style.loader_color, 85);
let active_color = style.loader_color;
let background_color = style.background_color;
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(inactive_color)
.render(target);
let inactive_color = if progress < LOADER_MAX {
background_color.blend(active_color, 85)
} else {
active_color
};
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(style.loader_color)
.with_end_angle(360.0 * progress as f32 / 1000.0)
.render(target);
let end = 360.0 * progress as f32 / 1000.0;
let start = 0.0;
shape::Circle::new(center, constant::LOADER_INNER + 2)
.with_bg(style.loader_color)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER)
.with_bg(style.background_color)
.render(target);
render_loader(
center,
inactive_color,
active_color,
background_color,
if progress >= LOADER_MAX {
LoaderRange::Full
} else {
LoaderRange::FromTo(start, end)
},
target,
);
if let Some((icon, color)) = style.icon {
shape::ToifImage::new(center, icon.toif)

View File

@ -1,5 +1,9 @@
use core::mem;
use super::{
super::cshape::{render_loader, LoaderRange},
theme,
};
use crate::{
strutil::TString,
ui::{
@ -9,17 +13,14 @@ use crate::{
text::paragraphs::{Paragraph, Paragraphs},
Child, Component, Event, EventCtx, Label, Never, Pad,
},
display::{self, Font},
display::{self, Font, LOADER_MAX},
geometry::{Insets, Offset, Rect},
model_tt::constant,
shape,
shape::Renderer,
util::animation_disabled,
},
};
use super::theme;
pub struct Progress {
title: Child<Label<'static>>,
value: u16,
@ -116,34 +117,29 @@ impl Component for Progress {
let background_color = theme::BG;
let inactive_color = background_color.blend(active_color, 85);
let (start, end) = if self.indeterminate {
let range = if self.indeterminate {
let start = (self.value as i16 - 100) % 1000;
let end = (self.value as i16 + 100) % 1000;
let start = 360.0 * start as f32 / 1000.0;
let end = 360.0 * end as f32 / 1000.0;
(start, end)
LoaderRange::FromTo(start, end)
} else {
let end = 360.0 * self.value as f32 / 1000.0;
(0.0, end)
if self.value >= LOADER_MAX {
LoaderRange::Full
} else {
LoaderRange::FromTo(0.0, end)
}
};
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(inactive_color)
.render(target);
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(active_color)
.with_start_angle(start)
.with_end_angle(end)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER + 2)
.with_bg(active_color)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER)
.with_bg(background_color)
.render(target);
render_loader(
center,
inactive_color,
active_color,
background_color,
range,
target,
);
self.description_pad.render(target);
self.description.render(target);

View File

@ -0,0 +1,42 @@
use crate::ui::{constant, display::Color, geometry::Point, shape, shape::Renderer};
pub enum LoaderRange {
Full,
FromTo(f32, f32),
}
pub fn render_loader<'s>(
center: Point,
inactive_color: Color,
active_color: Color,
background_color: Color,
range: LoaderRange,
target: &mut impl Renderer<'s>,
) {
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(inactive_color)
.render(target);
match range {
LoaderRange::Full => {
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(active_color)
.render(target);
}
LoaderRange::FromTo(start, end) => {
shape::Circle::new(center, constant::LOADER_OUTER)
.with_bg(active_color)
.with_start_angle(start)
.with_end_angle(end)
.render(target);
}
}
shape::Circle::new(center, constant::LOADER_INNER + 2)
.with_bg(active_color)
.render(target);
shape::Circle::new(center, constant::LOADER_INNER)
.with_bg(background_color)
.render(target);
}

View File

@ -0,0 +1,3 @@
mod loader;
pub use loader::{render_loader, LoaderRange};

View File

@ -9,6 +9,7 @@ pub mod theme;
#[cfg(feature = "backlight")]
use crate::ui::model_tt::theme::backlight;
pub mod cshape;
#[cfg(feature = "micropython")]
pub mod layout;