From 1255c3ae2d2d43ea6edb756d28be16748d0a2ba2 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Tue, 31 Dec 2024 13:18:46 +0100 Subject: [PATCH] WIP: feat(lincoln): header component --- .../src/ui/model_lincoln/component/header.rs | 207 ++++++++++++++++++ .../src/ui/model_lincoln/component/mod.rs | 2 + .../rust/src/ui/model_lincoln/theme/mod.rs | 7 + .../src/ui/model_mercury/component/frame.rs | 4 +- .../src/ui/model_mercury/component/header.rs | 16 +- .../component/hold_to_confirm.rs | 4 +- .../rust/src/ui/model_mercury/theme/mod.rs | 2 +- 7 files changed, 231 insertions(+), 11 deletions(-) create mode 100644 core/embed/rust/src/ui/model_lincoln/component/header.rs diff --git a/core/embed/rust/src/ui/model_lincoln/component/header.rs b/core/embed/rust/src/ui/model_lincoln/component/header.rs new file mode 100644 index 0000000000..6ab05a6fc7 --- /dev/null +++ b/core/embed/rust/src/ui/model_lincoln/component/header.rs @@ -0,0 +1,207 @@ +use crate::{ + strutil::TString, + time::{Duration, Stopwatch}, + ui::{ + component::{text::TextStyle, Component, Event, EventCtx, FlowMsg, Label}, + display::{Color, Icon}, + geometry::{Alignment, Alignment2D, Insets, Offset, Rect}, + lerp::Lerp, + shape::{self, Renderer}, + util::animation_disabled, + }, +}; + +use super::{ + button::{Button, ButtonMsg, ButtonStyleSheet}, + theme, +}; + +const ANIMATION_TIME_MS: u32 = 1000; + +#[derive(Default, Clone)] +struct AttachAnimation { + pub timer: Stopwatch, +} + +impl AttachAnimation { + pub fn is_active(&self) -> bool { + if animation_disabled() { + return false; + } + + self.timer + .is_running_within(Duration::from_millis(ANIMATION_TIME_MS)) + } + + pub fn eval(&self) -> f32 { + if animation_disabled() { + return ANIMATION_TIME_MS as f32 / 1000.0; + } + self.timer.elapsed().to_millis() as f32 / 1000.0 + } + + pub fn get_title_offset(&self, t: f32) -> i16 { + let fnc = pareen::constant(0.0).seq_ease_in_out( + 0.8, + easer::functions::Cubic, + 0.2, + pareen::constant(1.0), + ); + i16::lerp(0, 25, fnc.eval(t)) + } + + pub fn start(&mut self) { + self.timer.start(); + } + + pub fn reset(&mut self) { + self.timer = Stopwatch::new_stopped(); + } +} + +const BUTTON_EXPAND_BORDER: i16 = 32; + +/// Component for the header of a screen. Lincoln UI shows the title (can be two lines), optional +/// icon on the left, and optional button (typically for menu) on the right. Color is shared for +/// title and icon. +pub struct Header { + area: Rect, + title: Label<'static>, + button: Option