Skip to content

Commit 888e384

Browse files
committed
refactor(core/mercury): remove unnecessary Child
[no changelog]
1 parent 1212a73 commit 888e384

File tree

10 files changed

+140
-198
lines changed

10 files changed

+140
-198
lines changed

core/embed/rust/src/ui/model_mercury/component/coinjoin_progress.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use crate::{
66
strutil::TString,
77
translations::TR,
88
ui::{
9-
component::{
10-
base::Never, Bar, Child, Component, ComponentExt, Empty, Event, EventCtx, Label, Split,
11-
},
9+
component::{base::Never, Bar, Component, Empty, Event, EventCtx, Label, Split},
1210
display::loader::{loader_circular_uncompress, LoaderDimensions},
1311
geometry::{Insets, Offset, Rect},
1412
model_mercury::constant,
@@ -30,7 +28,7 @@ const LOADER_SPEED: u16 = 5;
3028
pub struct CoinJoinProgress<U> {
3129
value: u16,
3230
indeterminate: bool,
33-
content: Child<Frame<Split<Empty, U>>>,
31+
content: Frame<Split<Empty, U>>,
3432
// Label is not a child since circular loader paints large black rectangle which overlaps it.
3533
// To work around this, draw label every time loader is drawn.
3634
label: Label<'static>,
@@ -65,8 +63,7 @@ where
6563
content: Frame::centered(
6664
TR::coinjoin__title_progress.into(),
6765
Split::bottom(RECTANGLE_HEIGHT, 0, Empty, inner),
68-
)
69-
.into_child(),
66+
),
7067
label: Label::centered(text, theme::TEXT_NORMAL),
7168
})
7269
}

core/embed/rust/src/ui/model_mercury/component/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
strutil::TString,
33
ui::{
4-
component::{Child, Component, Event, EventCtx, Label, Never, Pad},
4+
component::{Component, Event, EventCtx, Label, Never, Pad},
55
constant::screen,
66
geometry::{Alignment2D, Point, Rect},
77
shape,
@@ -26,9 +26,9 @@ const STYLE: &ResultStyle = &super::theme::RESULT_ERROR;
2626

2727
pub struct ErrorScreen<'a> {
2828
bg: Pad,
29-
title: Child<Label<'a>>,
30-
message: Child<Label<'a>>,
31-
footer: Child<ResultFooter<'a>>,
29+
title: Label<'a>,
30+
message: Label<'a>,
31+
footer: ResultFooter<'a>,
3232
}
3333

3434
impl<'a> ErrorScreen<'a> {
@@ -42,9 +42,9 @@ impl<'a> ErrorScreen<'a> {
4242

4343
Self {
4444
bg: Pad::with_background(FATAL_ERROR_COLOR).with_clear(),
45-
title: Child::new(title),
46-
message: Child::new(message),
47-
footer: Child::new(footer),
45+
title,
46+
message,
47+
footer,
4848
}
4949
}
5050
}

core/embed/rust/src/ui/model_mercury/component/fido.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::{
22
strutil::TString,
33
ui::{
4-
component::{
5-
image::Image, Child, Component, Event, EventCtx, Label, Swipe, SwipeDirection,
6-
},
4+
component::{image::Image, Component, Event, EventCtx, Label, Swipe, SwipeDirection},
75
display,
86
geometry::{Insets, Rect},
97
model_mercury::component::{fido_icons::get_fido_icon_data, theme, ScrollBar},
@@ -30,7 +28,7 @@ pub struct FidoConfirm<F: Fn(usize) -> TString<'static>, U> {
3028
page_swipe: Swipe,
3129
app_name: Label<'static>,
3230
account_name: Label<'static>,
33-
icon: Child<Image>,
31+
icon: Image,
3432
/// Function/closure that will return appropriate page on demand.
3533
get_account: F,
3634
scrollbar: ScrollBar,
@@ -79,7 +77,7 @@ where
7977
app_name: Label::centered(app_name, theme::TEXT_DEMIBOLD),
8078
account_name: Label::centered(current_account, theme::TEXT_DEMIBOLD),
8179
page_swipe,
82-
icon: Child::new(Image::new(icon_data)),
80+
icon: Image::new(icon_data),
8381
get_account,
8482
scrollbar,
8583
fade: Cell::new(false),

core/embed/rust/src/ui/model_mercury/component/keyboard/mnemonic.rs

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
strutil::TString,
33
ui::{
44
component::{
5-
maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe, Swipe,
5+
maybe::paint_overlapping, Component, Event, EventCtx, Label, Maybe, Swipe,
66
SwipeDirection,
77
},
88
geometry::{Alignment, Grid, Insets, Rect},
@@ -24,17 +24,17 @@ pub enum MnemonicKeyboardMsg {
2424

2525
pub struct MnemonicKeyboard<T> {
2626
/// Initial prompt, displayed on empty input.
27-
prompt: Child<Maybe<Label<'static>>>,
27+
prompt: Maybe<Label<'static>>,
2828
/// Delete a char button.
29-
erase: Child<Maybe<Button>>,
29+
erase: Maybe<Button>,
3030
/// Go to previous word button
31-
back: Child<Maybe<Button>>,
31+
back: Maybe<Button>,
3232
/// Input area, acting as the auto-complete and confirm button.
33-
input: Child<Maybe<T>>,
33+
input: Maybe<T>,
3434
/// Area with keypads - used for rounded overlay
3535
keypad_area: Rect,
3636
/// Key buttons.
37-
keys: [Child<Button>; MNEMONIC_KEY_COUNT],
37+
keys: [Button; MNEMONIC_KEY_COUNT],
3838
/// Swipe controller - allowing for going to the previous word.
3939
swipe: Swipe,
4040
/// Whether going back is allowed (is not on the very first word).
@@ -56,26 +56,20 @@ where
5656
.styled(theme::button_default())
5757
.with_expanded_touch_area(Insets::right(BACK_BUTTON_RIGHT_EXPAND));
5858
Self {
59-
prompt: Child::new(Maybe::new(
59+
prompt: Maybe::new(
6060
theme::BG,
6161
Label::centered(prompt, theme::TEXT_MAIN_GREY_LIGHT).vertically_centered(),
6262
prompt_visible,
63-
)),
64-
erase: Child::new(Maybe::new(theme::BG, erase_btn, !prompt_visible)),
65-
back: Child::new(Maybe::new(
66-
theme::BG,
67-
back_btn,
68-
prompt_visible && can_go_back,
69-
)),
70-
input: Child::new(Maybe::new(theme::BG, input, !prompt_visible)),
63+
),
64+
erase: Maybe::new(theme::BG, erase_btn, !prompt_visible),
65+
back: Maybe::new(theme::BG, back_btn, prompt_visible && can_go_back),
66+
input: Maybe::new(theme::BG, input, !prompt_visible),
7167
keypad_area: Rect::zero(),
72-
keys: T::keys()
73-
.map(|t| {
74-
Button::with_text(t.into())
75-
.styled(theme::button_keyboard())
76-
.with_text_align(Alignment::Center)
77-
})
78-
.map(Child::new),
68+
keys: T::keys().map(|t| {
69+
Button::with_text(t.into())
70+
.styled(theme::button_keyboard())
71+
.with_text_align(Alignment::Center)
72+
}),
7973
swipe: Swipe::new().right(),
8074
can_go_back,
8175
}
@@ -90,32 +84,23 @@ where
9084
/// completion mask and the pending key.
9185
fn toggle_key_buttons(&mut self, ctx: &mut EventCtx) {
9286
for (key, btn) in self.keys.iter_mut().enumerate() {
93-
let enabled = self
94-
.input
95-
.inner()
96-
.inner()
97-
.can_key_press_lead_to_a_valid_word(key);
98-
btn.mutate(ctx, |ctx, b| b.enable_if(ctx, enabled));
87+
let enabled = self.input.inner().can_key_press_lead_to_a_valid_word(key);
88+
btn.enable_if(ctx, enabled);
9989
}
10090
}
10191

10292
/// After edit operations, we need to either show or hide the prompt, the
10393
/// input, the erase button and the back button.
10494
fn toggle_prompt_or_input(&mut self, ctx: &mut EventCtx) {
105-
let prompt_visible = self.input.inner().inner().is_empty();
106-
self.prompt
107-
.mutate(ctx, |ctx, p| p.show_if(ctx, prompt_visible));
108-
self.input
109-
.mutate(ctx, |ctx, i| i.show_if(ctx, !prompt_visible));
110-
self.erase
111-
.mutate(ctx, |ctx, b| b.show_if(ctx, !prompt_visible));
112-
self.back.mutate(ctx, |ctx, b| {
113-
b.show_if(ctx, prompt_visible && self.can_go_back)
114-
});
95+
let prompt_visible = self.input.inner().is_empty();
96+
self.prompt.show_if(ctx, prompt_visible);
97+
self.input.show_if(ctx, !prompt_visible);
98+
self.erase.show_if(ctx, !prompt_visible);
99+
self.back.show_if(ctx, prompt_visible && self.can_go_back);
115100
}
116101

117102
pub fn mnemonic(&self) -> Option<&'static str> {
118-
self.input.inner().inner().mnemonic()
103+
self.input.inner().mnemonic()
119104
}
120105
}
121106

@@ -181,23 +166,20 @@ where
181166

182167
match self.erase.event(ctx, event) {
183168
Some(ButtonMsg::Clicked) => {
184-
self.input
185-
.mutate(ctx, |ctx, i| i.inner_mut().on_backspace_click(ctx));
169+
self.input.inner_mut().on_backspace_click(ctx);
186170
self.on_input_change(ctx);
187171
return None;
188172
}
189173
Some(ButtonMsg::LongPressed) => {
190-
self.input
191-
.mutate(ctx, |ctx, i| i.inner_mut().on_backspace_long_press(ctx));
174+
self.input.inner_mut().on_backspace_long_press(ctx);
192175
self.on_input_change(ctx);
193176
return None;
194177
}
195178
_ => {}
196179
}
197180
for (key, btn) in self.keys.iter_mut().enumerate() {
198181
if let Some(ButtonMsg::Clicked) = btn.event(ctx, event) {
199-
self.input
200-
.mutate(ctx, |ctx, i| i.inner_mut().on_key_click(ctx, key));
182+
self.input.inner_mut().on_key_click(ctx, key);
201183
self.on_input_change(ctx);
202184
return None;
203185
}
@@ -213,7 +195,7 @@ where
213195
}
214196

215197
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
216-
if self.input.inner().inner().is_empty() {
198+
if self.input.inner().is_empty() {
217199
self.prompt.render(target);
218200
if self.can_go_back {
219201
self.back.render(target);

0 commit comments

Comments
 (0)