mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
feat(core/rust): introduce small indeterminate loader
[no changelog]
This commit is contained in:
parent
b96b9d43bb
commit
a318706145
@ -1,5 +1,6 @@
|
|||||||
mod circular;
|
mod circular;
|
||||||
mod rectangular;
|
mod rectangular;
|
||||||
|
mod small;
|
||||||
mod starry;
|
mod starry;
|
||||||
|
|
||||||
use crate::ui::display::{Color, Icon};
|
use crate::ui::display::{Color, Icon};
|
||||||
@ -16,6 +17,8 @@ use crate::ui::display::loader::rectangular::loader_rectangular as determinate;
|
|||||||
#[cfg(not(feature = "model_tt"))]
|
#[cfg(not(feature = "model_tt"))]
|
||||||
use crate::ui::display::loader::starry::loader_starry_indeterminate as indeterminate;
|
use crate::ui::display::loader::starry::loader_starry_indeterminate as indeterminate;
|
||||||
|
|
||||||
|
pub use small::loader_small_indeterminate;
|
||||||
|
|
||||||
pub const LOADER_MIN: u16 = 0;
|
pub const LOADER_MIN: u16 = 0;
|
||||||
pub const LOADER_MAX: u16 = 1000;
|
pub const LOADER_MAX: u16 = 1000;
|
||||||
|
|
||||||
|
53
core/embed/rust/src/ui/display/loader/small.rs
Normal file
53
core/embed/rust/src/ui/display/loader/small.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
use crate::ui::{
|
||||||
|
constant::screen,
|
||||||
|
display::{rect_fill, Color},
|
||||||
|
geometry::{Offset, Point, Rect},
|
||||||
|
};
|
||||||
|
use core::f32::consts::SQRT_2;
|
||||||
|
|
||||||
|
const STAR_COUNT: usize = 8;
|
||||||
|
const RADIUS: i16 = 3;
|
||||||
|
const DIAGONAL: i16 = ((RADIUS as f32 * SQRT_2) / 2_f32) as i16;
|
||||||
|
const LOADER_SIZE: Offset = Offset::uniform(2 * RADIUS + 3);
|
||||||
|
|
||||||
|
fn fill_point(point: Point, color: Color) {
|
||||||
|
let area = Rect::from_center_and_size(point, Offset::uniform(1));
|
||||||
|
rect_fill(area, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn loader_small_indeterminate(progress: u16, y_offset: i16, fg_color: Color, bg_color: Color) {
|
||||||
|
let area =
|
||||||
|
Rect::from_center_and_size(screen().center(), LOADER_SIZE).translate(Offset::y(y_offset));
|
||||||
|
|
||||||
|
rect_fill(area, bg_color);
|
||||||
|
|
||||||
|
// Offset of the normal point and then the extra offset for the main point
|
||||||
|
let offsets: [(Offset, Offset); STAR_COUNT] = [
|
||||||
|
(Offset::y(-RADIUS), Offset::y(-1)),
|
||||||
|
(Offset::new(DIAGONAL, -DIAGONAL), Offset::new(1, -1)),
|
||||||
|
(Offset::x(RADIUS), Offset::x(1)),
|
||||||
|
(Offset::new(DIAGONAL, DIAGONAL), Offset::new(1, 1)),
|
||||||
|
(Offset::y(RADIUS), Offset::y(1)),
|
||||||
|
(Offset::new(-DIAGONAL, DIAGONAL), Offset::new(-1, 1)),
|
||||||
|
(Offset::x(-RADIUS), Offset::x(-1)),
|
||||||
|
(Offset::new(-DIAGONAL, -DIAGONAL), Offset::new(-1, -1)),
|
||||||
|
];
|
||||||
|
|
||||||
|
let main_idx = (STAR_COUNT * progress as usize / 1000) % STAR_COUNT;
|
||||||
|
|
||||||
|
for (i, (point_offset, main_offset)) in offsets.iter().enumerate() {
|
||||||
|
// Skip it when it is behind the main one (clockwise)
|
||||||
|
if (main_idx + 1) % STAR_COUNT == i {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the normal point
|
||||||
|
let point = area.center() + *point_offset;
|
||||||
|
fill_point(point, fg_color);
|
||||||
|
|
||||||
|
// Draw the main point
|
||||||
|
if main_idx == i {
|
||||||
|
fill_point(point + *main_offset, fg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,9 @@ use crate::{
|
|||||||
pub use crate::ui::display::toif::Icon;
|
pub use crate::ui::display::toif::Icon;
|
||||||
pub use color::Color;
|
pub use color::Color;
|
||||||
pub use font::{Font, Glyph, GlyphMetrics};
|
pub use font::{Font, Glyph, GlyphMetrics};
|
||||||
pub use loader::{loader, loader_indeterminate, LOADER_MAX, LOADER_MIN};
|
pub use loader::{
|
||||||
|
loader, loader_indeterminate, loader_small_indeterminate, LOADER_MAX, LOADER_MIN,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn backlight() -> u16 {
|
pub fn backlight() -> u16 {
|
||||||
display::backlight(-1) as u16
|
display::backlight(-1) as u16
|
||||||
|
Loading…
Reference in New Issue
Block a user