1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +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 intro::Intro;
use menu::Menu; 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 intro;
pub mod menu; pub mod menu;
pub mod welcome; pub mod welcome;
@ -113,25 +118,21 @@ impl ModelTTFeatures {
.render(target); .render(target);
let center = SCREEN.center() + Offset::y(-20); let center = SCREEN.center() + Offset::y(-20);
let inactive_color = bg_color.blend(fg_color, 85); 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) render_loader(
.with_bg(inactive_color) center,
.render(target); inactive_color,
fg_color,
shape::Circle::new(center, constant::LOADER_OUTER) bg_color,
.with_bg(fg_color) if progress >= LOADER_MAX {
.with_end_angle(360.0 * progress as f32 / 1000.0) LoaderRange::Full
.render(target); } else {
LoaderRange::FromTo(0.0, end)
shape::Circle::new(center, constant::LOADER_INNER + 2) },
.with_bg(fg_color) target,
.render(target); );
shape::Circle::new(center, constant::LOADER_INNER)
.with_bg(bg_color)
.render(target);
if let Some((icon, color)) = icon { if let Some((icon, color)) = icon {
shape::ToifImage::new(center, icon.toif) shape::ToifImage::new(center, icon.toif)

View File

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

View File

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