Skip to content

Commit 952d59a

Browse files
committed
chore(core/eckhart): invert QR screen colors
1 parent e3fcde1 commit 952d59a

File tree

4 files changed

+58
-71
lines changed

4 files changed

+58
-71
lines changed
Lines changed: 30 additions & 66 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);
68-
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));
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));
7154

72-
self.pad = qr_pad;
55+
qr_area = qr_area.inset(theme::SIDE_INSETS);
56+
qr_area = qr_area.with_height(qr_area.width());
7357

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);
83-
}
69+
};
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ pub const fn button_header() -> ButtonStyleSheet {
311311
}
312312
}
313313

314+
pub const fn button_header_inverted() -> ButtonStyleSheet {
315+
ButtonStyleSheet {
316+
normal: &ButtonStyle {
317+
font: fonts::FONT_SATOSHI_MEDIUM_26,
318+
text_color: BG,
319+
button_color: FG,
320+
icon_color: BG,
321+
},
322+
active: &ButtonStyle {
323+
font: fonts::FONT_SATOSHI_MEDIUM_26,
324+
text_color: BG,
325+
button_color: GREY_LIGHT,
326+
icon_color: BG,
327+
},
328+
disabled: &ButtonStyle {
329+
font: fonts::FONT_SATOSHI_MEDIUM_26,
330+
text_color: BG,
331+
button_color: GREY_LIGHT,
332+
icon_color: BG,
333+
},
334+
}
335+
}
336+
314337
// Macro for styles differing only in text color
315338
macro_rules! menu_item_title {
316339
($color:expr) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ pub const TEXT_SMALL_GREY: TextStyle = TextStyle {
176176
text_color: GREY,
177177
..TEXT_SMALL
178178
};
179+
pub const TEXT_SMALL_BLACK: TextStyle = TextStyle {
180+
text_color: BG,
181+
..TEXT_SMALL
182+
};
179183
pub const TEXT_SMALL_GREY_EXTRA_LIGHT: TextStyle = TextStyle {
180184
text_color: GREY_EXTRA_LIGHT,
181185
..TEXT_SMALL

0 commit comments

Comments
 (0)