1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

refactor(core): remove unused ui components

[no changelog]
This commit is contained in:
cepetr 2024-03-11 16:16:35 +01:00 committed by cepetr
parent dff12a32c1
commit 9d6827e2fb
3 changed files with 0 additions and 339 deletions

View File

@ -39,8 +39,6 @@ mod homescreen;
#[cfg(feature = "translations")]
mod page;
mod progress;
mod result_anim;
mod result_popup;
mod scrollbar;
#[cfg(feature = "translations")]
mod share_words;
@ -69,8 +67,6 @@ pub use input_methods::{
#[cfg(feature = "translations")]
pub use page::ButtonPage;
pub use progress::Progress;
pub use result_anim::{ResultAnim, ResultAnimMsg};
pub use result_popup::{ResultPopup, ResultPopupMsg};
pub use scrollbar::ScrollBar;
#[cfg(feature = "translations")]
pub use share_words::ShareWords;

View File

@ -1,152 +0,0 @@
use crate::{
time::{Duration, Instant},
ui::{
animation::Animation,
component::{Component, Event, EventCtx},
display,
display::toif::Icon,
geometry::Rect,
},
};
use super::super::theme;
pub enum ResultAnimMsg {
FullyGrown,
}
enum State {
Initial,
Growing(Animation<u16>),
Grown,
}
pub struct ResultAnim {
area: Rect,
state: State,
growing_duration: Duration,
icon: Icon,
}
impl ResultAnim {
pub fn new(icon: Icon) -> Self {
Self {
area: Rect::zero(),
state: State::Initial,
growing_duration: Duration::from_millis(2000),
icon,
}
}
pub fn start_growing(&mut self, ctx: &mut EventCtx, now: Instant) {
let anim = Animation::new(
display::LOADER_MIN,
display::LOADER_MAX,
self.growing_duration,
now,
);
self.state = State::Growing(anim);
// The animation is starting, request an animation frame event.
ctx.request_anim_frame();
// We don't have to wait for the animation frame event with the first paint,
// let's do that now.
ctx.request_paint();
}
pub fn reset(&mut self) {
self.state = State::Initial;
}
pub fn animation(&self) -> Option<&Animation<u16>> {
match &self.state {
State::Initial => None,
State::Grown => None,
State::Growing(a) => Some(a),
}
}
pub fn progress(&self, now: Instant) -> Option<u16> {
self.animation().map(|a| a.value(now))
}
pub fn is_animating(&self) -> bool {
self.animation().is_some()
}
pub fn is_completely_grown(&self, now: Instant) -> bool {
matches!(self.progress(now), Some(display::LOADER_MAX))
}
pub fn paint_anim(&mut self, done: i16) {
display::rect_rounded2_partial(
self.area,
theme::FG,
theme::BG,
100 * done / 1000,
Some((self.icon, theme::FG)),
);
}
}
impl Component for ResultAnim {
type Msg = ResultAnimMsg;
fn place(&mut self, bounds: Rect) -> Rect {
self.area = bounds;
self.area
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
let now = Instant::now();
if let Event::Timer(EventCtx::ANIM_FRAME_TIMER) = event {
if let State::Growing(_) = self.state {
// We have something to paint, so request to be painted in the next pass.
ctx.request_paint();
if self.is_completely_grown(now) {
self.state = State::Grown;
return Some(ResultAnimMsg::FullyGrown);
} else {
// There is further progress in the animation, request an animation frame event.
ctx.request_anim_frame();
}
}
}
None
}
fn paint(&mut self) {
// TODO: Consider passing the current instant along with the event -- that way,
// we could synchronize painting across the component tree. Also could be useful
// in automated tests.
// In practice, taking the current instant here is more precise in case some
// other component in the tree takes a long time to draw.
let now = Instant::now();
if let State::Initial = self.state {
self.paint_anim(0);
} else if let State::Grown = self.state {
self.paint_anim(display::LOADER_MAX as i16);
} else {
let progress = self.progress(now);
if let Some(done) = progress {
self.paint_anim(done as i16);
} else {
self.paint_anim(0);
}
}
}
}
// DEBUG-ONLY SECTION BELOW
#[cfg(feature = "ui_debug")]
impl crate::trace::Trace for ResultAnim {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ResultAnim");
}
}

View File

@ -1,183 +0,0 @@
use crate::{
strutil::StringType,
time::Instant,
ui::{
component::{
text::paragraphs::{Paragraph, Paragraphs},
Child, Component, ComponentExt, Event, EventCtx, Label, Pad,
},
constant::screen,
display::toif::Icon,
geometry::{Insets, LinearPlacement, Rect},
},
};
use super::{
super::theme, ButtonController, ButtonControllerMsg, ButtonLayout, ButtonPos, ResultAnim,
ResultAnimMsg,
};
pub enum ResultPopupMsg {
Confirmed,
}
pub struct ResultPopup<T>
where
T: StringType,
{
area: Rect,
pad: Pad,
result_anim: Child<ResultAnim>,
headline: Option<Label<&'static str>>,
text: Child<Paragraphs<Paragraph<T>>>,
buttons: Option<Child<ButtonController>>,
autoclose: bool,
}
const ANIM_SIZE: i16 = 18;
const ANIM_SPACE: i16 = 11;
const ANIM_POS: i16 = 32;
const ANIM_POS_ADJ_HEADLINE: i16 = 10;
const ANIM_POS_ADJ_BUTTON: i16 = 6;
impl<T> ResultPopup<T>
where
T: StringType + Clone,
{
pub fn new(
icon: Icon,
text: T,
headline: Option<&'static str>,
button_text: Option<&'static str>,
) -> Self {
let p1 = Paragraphs::new(Paragraph::new(&theme::TEXT_BIG, text))
.with_placement(LinearPlacement::vertical().align_at_center());
let buttons = button_text.map(|text| {
let btn_layout = ButtonLayout::none_none_text(text.into());
Child::new(ButtonController::new(btn_layout))
});
let mut pad = Pad::with_background(theme::BG);
pad.clear();
Self {
area: Rect::zero(),
pad,
result_anim: Child::new(ResultAnim::new(icon)),
headline: headline.map(|a| Label::centered(a, theme::TEXT_BOLD)),
text: Child::new(p1),
buttons,
autoclose: false,
}
}
// autoclose even if button is used
pub fn autoclose(&mut self) {
self.autoclose = true;
}
pub fn start(&mut self, ctx: &mut EventCtx) {
self.text.request_complete_repaint(ctx);
self.headline.request_complete_repaint(ctx);
self.buttons.request_complete_repaint(ctx);
self.result_anim.mutate(ctx, |ctx, c| {
let now = Instant::now();
c.start_growing(ctx, now);
});
ctx.request_paint();
}
}
impl<T> Component for ResultPopup<T>
where
T: StringType + Clone,
{
type Msg = ResultPopupMsg;
fn place(&mut self, bounds: Rect) -> Rect {
self.area = bounds;
let anim_margins = (screen().width() - ANIM_SIZE) / 2;
let mut anim_adjust = 0;
let mut headline_height = 0;
let mut button_height = 0;
if let Some(h) = self.headline.as_mut() {
headline_height = h.max_size().y;
anim_adjust += ANIM_POS_ADJ_HEADLINE;
}
if self.buttons.is_some() {
button_height = theme::BUTTON_HEIGHT;
anim_adjust += ANIM_POS_ADJ_BUTTON;
}
let (_, rest) = bounds.split_top(ANIM_POS - anim_adjust);
let (anim, rest) = rest.split_top(ANIM_SIZE);
let (_, rest) = rest.split_top(ANIM_SPACE);
let (headline, rest) = rest.split_top(headline_height);
let (text, buttons) = rest.split_bottom(button_height);
self.pad.place(bounds);
self.buttons.place(buttons);
self.headline.place(headline);
self.text.place(text);
self.result_anim
.place(anim.inset(Insets::sides(anim_margins)));
self.area
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
let mut button_confirmed = false;
self.text.event(ctx, event);
self.headline.event(ctx, event);
if let Some(ButtonControllerMsg::Triggered(ButtonPos::Right, _)) =
self.buttons.event(ctx, event)
{
button_confirmed = true;
}
if let Some(ResultAnimMsg::FullyGrown) = self.result_anim.event(ctx, event) {
if self.buttons.is_none() || self.autoclose {
return Some(ResultPopupMsg::Confirmed);
}
}
if button_confirmed {
return Some(ResultPopupMsg::Confirmed);
}
None
}
fn paint(&mut self) {
self.pad.paint();
self.text.paint();
self.buttons.paint();
self.headline.paint();
self.result_anim.paint();
}
}
// DEBUG-ONLY SECTION BELOW
#[cfg(feature = "ui_debug")]
impl<T> crate::trace::Trace for ResultPopup<T>
where
T: StringType + Clone,
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("ResultPopup");
t.child("text", &self.text);
if let Some(button) = &self.buttons {
t.child("button", button);
}
if let Some(headline) = &self.headline {
t.child("headline", headline);
}
t.child("result_anim", &self.result_anim);
}
}