Skip to content

Commit 031247b

Browse files
committed
chore(core/eckhart): invert QR screen colors
[no changelog]
1 parent bd31cc4 commit 031247b

File tree

4 files changed

+712
-724
lines changed

4 files changed

+712
-724
lines changed
Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
11
use crate::{
22
strutil::TString,
33
ui::{
4-
component::{swipe_detect::SwipeConfig, Component, Event, EventCtx, Qr},
4+
component::{swipe_detect::SwipeConfig, Component, Event, EventCtx, Label, Pad, Qr},
55
flow::Swipable,
6-
geometry::{Insets, Rect},
7-
shape::{self, Renderer},
6+
geometry::{Alignment, Insets, Rect},
7+
shape::Renderer,
88
util::Pager,
99
},
1010
};
1111

1212
use super::super::{
13+
component::{Button, ButtonMsg},
1314
constant::SCREEN,
14-
firmware::{theme, ActionBar, Header, HeaderMsg},
15+
firmware::{theme, Header},
1516
};
1617

1718
pub enum QrMsg {
1819
Cancelled,
1920
}
2021

2122
pub struct QrScreen {
22-
header: Header,
23+
title: Label<'static>,
24+
close_button: Button,
2325
qr: Qr,
24-
action_bar: Option<ActionBar>,
25-
pad: Rect,
26+
pad: Pad,
2627
}
2728

2829
impl QrScreen {
29-
const QR_PADDING: i16 = 8;
30-
const QR_HEIGHT: i16 = 300;
31-
const QR_PAD_RADIUS: i16 = 12;
32-
33-
pub fn new(qr: Qr) -> Self {
30+
const BUTTON_WIDTH: i16 = 80; // [px]
31+
pub fn new(title: TString<'static>, qr: Qr) -> Self {
3432
Self {
35-
header: Header::new(TString::empty()),
33+
title: Label::new(title, Alignment::Start, theme::TEXT_SMALL_BLACK)
34+
.vertically_centered(),
3635
qr,
37-
action_bar: None,
38-
pad: Rect::zero(),
36+
pad: Pad::with_background(theme::FG),
37+
close_button: Button::with_icon(theme::ICON_CLOSE)
38+
.styled(theme::button_header_inverted()),
3939
}
4040
}
41-
42-
pub fn with_header(mut self, header: Header) -> Self {
43-
self.header = header;
44-
self
45-
}
46-
47-
pub fn with_action_bar(mut self, action_bar: ActionBar) -> Self {
48-
self.action_bar = Some(action_bar);
49-
self
50-
}
5141
}
5242

5343
impl Component for QrScreen {
@@ -58,43 +48,34 @@ impl Component for QrScreen {
5848
debug_assert_eq!(bounds.height(), SCREEN.height());
5949
debug_assert_eq!(bounds.width(), SCREEN.width());
6050

61-
let (header_area, mut rest) = bounds.split_top(Header::HEADER_HEIGHT);
62-
if let Some(action_bar) = &mut self.action_bar {
63-
let action_bar_area;
64-
(rest, action_bar_area) = rest.split_bottom(ActionBar::ACTION_BAR_HEIGHT);
65-
action_bar.place(action_bar_area);
66-
}
67-
let (qr_pad, _) = rest.split_top(Self::QR_HEIGHT + 2 * Self::QR_PADDING);
51+
let (header_area, mut qr_area) = bounds.split_top(Header::HEADER_HEIGHT);
52+
let (mut title_area, button_area) = header_area.split_right(Self::BUTTON_WIDTH);
53+
title_area = title_area.inset(Insets::left(theme::SIDE_INSETS.left));
6854

69-
let side_padding = (SCREEN.width() - Self::QR_HEIGHT - 2 * Self::QR_PADDING) / 2;
70-
let qr_pad = qr_pad.inset(Insets::sides(side_padding));
55+
qr_area = qr_area.inset(theme::SIDE_INSETS);
56+
qr_area = qr_area.with_height(qr_area.width());
7157

72-
self.pad = qr_pad;
73-
74-
self.header.place(header_area);
75-
self.qr.place(qr_pad.shrink(Self::QR_PADDING));
58+
self.pad.place(bounds);
59+
self.title.place(title_area);
60+
self.close_button.place(button_area);
61+
self.qr.place(qr_area);
7662

7763
bounds
7864
}
7965

8066
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
81-
if let Some(HeaderMsg::Cancelled) = self.header.event(ctx, event) {
67+
if let Some(ButtonMsg::Clicked) = self.close_button.event(ctx, event) {
8268
return Some(QrMsg::Cancelled);
8369
}
70+
8471
None
8572
}
8673

8774
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
88-
// Render white QR pad
89-
shape::Bar::new(self.pad)
90-
.with_bg(theme::FG)
91-
.with_fg(theme::FG)
92-
.with_radius(Self::QR_PAD_RADIUS)
93-
.render(target);
94-
95-
self.header.render(target);
75+
self.pad.render(target);
76+
self.title.render(target);
77+
self.close_button.render(target);
9678
self.qr.render(target);
97-
self.action_bar.render(target);
9879
}
9980
}
10081

@@ -115,20 +96,3 @@ impl crate::trace::Trace for QrScreen {
11596
t.component("QrScreen");
11697
}
11798
}
118-
119-
#[cfg(test)]
120-
mod tests {
121-
use super::{super::super::constant::SCREEN, *};
122-
123-
#[test]
124-
fn test_component_heights_fit_screen() {
125-
assert!(
126-
QrScreen::QR_HEIGHT
127-
+ 2 * QrScreen::QR_PADDING
128-
+ Header::HEADER_HEIGHT
129-
+ ActionBar::ACTION_BAR_HEIGHT
130-
<= SCREEN.height(),
131-
"Components overflow the screen height",
132-
);
133-
}
134-
}

core/embed/rust/src/ui/layout_eckhart/flow/receive.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ pub fn new_receive(
170170
});
171171

172172
// QrCode
173-
let content_qr = QrScreen::new(qr.map(|s| Qr::new(s, case_sensitive))?)
174-
.with_header(
175-
Header::new(title_qr.into())
176-
.with_right_button(Button::with_icon(theme::ICON_CROSS), HeaderMsg::Cancelled),
177-
)
173+
let content_qr = QrScreen::new(title_qr.into(), qr.map(|s| Qr::new(s, case_sensitive))?)
178174
.map(|_| Some(FlowMsg::Cancelled));
179175

180176
// AccountInfo

core/embed/rust/src/ui/layout_eckhart/theme/firmware.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub const TEXT_SMALL: TextStyle = TextStyle::new(
6868
GREY_DARK,
6969
)
7070
.with_line_spacing(-4);
71+
pub const TEXT_SMALL_BLACK: TextStyle = TextStyle {
72+
text_color: BG,
73+
..TEXT_SMALL
74+
};
7175
/// Roboto Mono Medium - 38 (Number value)
7276
pub const TEXT_MONO_MEDIUM: TextStyle = TextStyle::new(
7377
fonts::FONT_MONO_MEDIUM_38,
@@ -311,6 +315,30 @@ pub const fn button_header() -> ButtonStyleSheet {
311315
}
312316
}
313317

318+
pub const fn button_header_inverted() -> ButtonStyleSheet {
319+
ButtonStyleSheet {
320+
normal: &ButtonStyle {
321+
font: fonts::FONT_SATOSHI_MEDIUM_26,
322+
text_color: BG,
323+
button_color: FG,
324+
icon_color: BG,
325+
},
326+
active: &ButtonStyle {
327+
font: fonts::FONT_SATOSHI_MEDIUM_26,
328+
text_color: GREY_DARK,
329+
button_color: GREY_LIGHT,
330+
icon_color: GREY_DARK,
331+
},
332+
// unused
333+
disabled: &ButtonStyle {
334+
font: fonts::FONT_SATOSHI_MEDIUM_26,
335+
text_color: GREY_LIGHT,
336+
button_color: GREY_EXTRA_LIGHT,
337+
icon_color: GREY_LIGHT,
338+
},
339+
}
340+
}
341+
314342
// Macro for styles differing only in text color
315343
macro_rules! menu_item_title {
316344
($color:expr) => {

0 commit comments

Comments
 (0)