mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-07 13:12:41 +00:00
perf(core/ui): remove Child from T3T1 Frame
[no changelog]
This commit is contained in:
parent
320fa06122
commit
b64c8ef6a2
@ -2,11 +2,10 @@ use crate::{
|
|||||||
strutil::TString,
|
strutil::TString,
|
||||||
ui::{
|
ui::{
|
||||||
component::{
|
component::{
|
||||||
base::ComponentExt,
|
|
||||||
label::Label,
|
label::Label,
|
||||||
swipe_detect::{SwipeConfig, SwipeSettings},
|
swipe_detect::{SwipeConfig, SwipeSettings},
|
||||||
text::TextStyle,
|
text::TextStyle,
|
||||||
Child, Component, Event,
|
Component, Event,
|
||||||
Event::Swipe,
|
Event::Swipe,
|
||||||
EventCtx, SwipeDetect, SwipeDirection,
|
EventCtx, SwipeDetect, SwipeDirection,
|
||||||
},
|
},
|
||||||
@ -28,11 +27,11 @@ const BUTTON_EXPAND_BORDER: i16 = 32;
|
|||||||
pub struct Frame<T> {
|
pub struct Frame<T> {
|
||||||
border: Insets,
|
border: Insets,
|
||||||
bounds: Rect,
|
bounds: Rect,
|
||||||
title: Child<Label<'static>>,
|
title: Label<'static>,
|
||||||
subtitle: Option<Child<Label<'static>>>,
|
subtitle: Option<Label<'static>>,
|
||||||
button: Option<Child<Button>>,
|
button: Option<Button>,
|
||||||
button_msg: CancelInfoConfirmMsg,
|
button_msg: CancelInfoConfirmMsg,
|
||||||
content: Child<T>,
|
content: T,
|
||||||
footer: Option<Footer<'static>>,
|
footer: Option<Footer<'static>>,
|
||||||
swipe: SwipeConfig,
|
swipe: SwipeConfig,
|
||||||
internal_page_cnt: usize,
|
internal_page_cnt: usize,
|
||||||
@ -51,15 +50,13 @@ where
|
|||||||
{
|
{
|
||||||
pub const fn new(alignment: Alignment, title: TString<'static>, content: T) -> Self {
|
pub const fn new(alignment: Alignment, title: TString<'static>, content: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: Child::new(
|
title: Label::new(title, alignment, theme::label_title_main()).vertically_centered(),
|
||||||
Label::new(title, alignment, theme::label_title_main()).vertically_centered(),
|
|
||||||
),
|
|
||||||
bounds: Rect::zero(),
|
bounds: Rect::zero(),
|
||||||
subtitle: None,
|
subtitle: None,
|
||||||
border: theme::borders(),
|
border: theme::borders(),
|
||||||
button: None,
|
button: None,
|
||||||
button_msg: CancelInfoConfirmMsg::Cancelled,
|
button_msg: CancelInfoConfirmMsg::Cancelled,
|
||||||
content: Child::new(content),
|
content,
|
||||||
footer: None,
|
footer: None,
|
||||||
swipe: SwipeConfig::new(),
|
swipe: SwipeConfig::new(),
|
||||||
internal_page_cnt: 1,
|
internal_page_cnt: 1,
|
||||||
@ -83,36 +80,34 @@ where
|
|||||||
Self::new(Alignment::Center, title, content)
|
Self::new(Alignment::Center, title, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
pub const fn with_border(mut self, border: Insets) -> Self {
|
pub const fn with_border(mut self, border: Insets) -> Self {
|
||||||
self.border = border;
|
self.border = border;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title_styled(mut self, style: TextStyle) -> Self {
|
pub fn title_styled(mut self, style: TextStyle) -> Self {
|
||||||
self.title = Child::new(self.title.into_inner().styled(style));
|
self.title = self.title.styled(style);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
pub fn with_subtitle(mut self, subtitle: TString<'static>) -> Self {
|
pub fn with_subtitle(mut self, subtitle: TString<'static>) -> Self {
|
||||||
let style = theme::TEXT_SUB_GREY;
|
let style = theme::TEXT_SUB_GREY;
|
||||||
self.title = Child::new(self.title.into_inner().top_aligned());
|
self.title = self.title.top_aligned();
|
||||||
self.subtitle = Some(Child::new(Label::new(
|
self.subtitle = Some(Label::new(subtitle, self.title.alignment(), style));
|
||||||
subtitle,
|
|
||||||
self.title.inner().alignment(),
|
|
||||||
style,
|
|
||||||
)));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
fn with_button(mut self, icon: Icon, msg: CancelInfoConfirmMsg, enabled: bool) -> Self {
|
fn with_button(mut self, icon: Icon, msg: CancelInfoConfirmMsg, enabled: bool) -> Self {
|
||||||
let touch_area = Insets::uniform(BUTTON_EXPAND_BORDER);
|
let touch_area = Insets::uniform(BUTTON_EXPAND_BORDER);
|
||||||
self.button = Some(Child::new(
|
self.button = Some(
|
||||||
Button::with_icon(icon)
|
Button::with_icon(icon)
|
||||||
.with_expanded_touch_area(touch_area)
|
.with_expanded_touch_area(touch_area)
|
||||||
.initially_enabled(enabled)
|
.initially_enabled(enabled)
|
||||||
.styled(theme::button_default()),
|
.styled(theme::button_default()),
|
||||||
));
|
);
|
||||||
self.button_msg = msg;
|
self.button_msg = msg;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -132,11 +127,12 @@ where
|
|||||||
|
|
||||||
pub fn button_styled(mut self, style: ButtonStyleSheet) -> Self {
|
pub fn button_styled(mut self, style: ButtonStyleSheet) -> Self {
|
||||||
if self.button.is_some() {
|
if self.button.is_some() {
|
||||||
self.button = Some(Child::new(self.button.unwrap().into_inner().styled(style)));
|
self.button = Some(self.button.unwrap().styled(style));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
pub fn with_footer(
|
pub fn with_footer(
|
||||||
mut self,
|
mut self,
|
||||||
instruction: TString<'static>,
|
instruction: TString<'static>,
|
||||||
@ -156,27 +152,24 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn inner(&self) -> &T {
|
pub fn inner(&self) -> &T {
|
||||||
self.content.inner()
|
&self.content
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_title(&mut self, ctx: &mut EventCtx, new_title: TString<'static>) {
|
pub fn update_title(&mut self, ctx: &mut EventCtx, new_title: TString<'static>) {
|
||||||
self.title.mutate(ctx, |ctx, t| {
|
self.title.set_text(new_title);
|
||||||
t.set_text(new_title);
|
ctx.request_paint();
|
||||||
t.request_complete_repaint(ctx)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_content<F, R>(&mut self, ctx: &mut EventCtx, update_fn: F) -> R
|
pub fn update_content<F, R>(&mut self, ctx: &mut EventCtx, update_fn: F) -> R
|
||||||
where
|
where
|
||||||
F: Fn(&mut EventCtx, &mut T) -> R,
|
F: Fn(&mut EventCtx, &mut T) -> R,
|
||||||
{
|
{
|
||||||
self.content.mutate(ctx, |ctx, c| {
|
let res = update_fn(ctx, &mut self.content);
|
||||||
let res = update_fn(ctx, c);
|
ctx.request_paint();
|
||||||
c.request_complete_repaint(ctx);
|
res
|
||||||
res
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
pub fn with_swipe(mut self, dir: SwipeDirection, settings: SwipeSettings) -> Self {
|
pub fn with_swipe(mut self, dir: SwipeDirection, settings: SwipeSettings) -> Self {
|
||||||
self.footer = self.footer.map(|f| match dir {
|
self.footer = self.footer.map(|f| match dir {
|
||||||
SwipeDirection::Up => f.with_swipe_up(),
|
SwipeDirection::Up => f.with_swipe_up(),
|
||||||
|
Loading…
Reference in New Issue
Block a user