mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-26 18:02:35 +00:00
feat(eckhart): fix hint padding
This commit is contained in:
parent
994b61e38b
commit
c48e8f8a90
@ -40,7 +40,7 @@ impl<'a> Hint<'a> {
|
|||||||
/// height of the multi line component [px]
|
/// height of the multi line component [px]
|
||||||
pub const HEIGHT_MAXIMAL: i16 = 66;
|
pub const HEIGHT_MAXIMAL: i16 = 66;
|
||||||
/// margins from the edges of the screen [px]
|
/// margins from the edges of the screen [px]
|
||||||
const HINT_INSETS: Insets = Insets::sides(24);
|
const HINT_INSETS: Insets = Insets::new(16, 24, 24, 24);
|
||||||
|
|
||||||
fn from_content(content: HintContent<'a>) -> Self {
|
fn from_content(content: HintContent<'a>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -115,10 +115,10 @@ impl<'a> Hint<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the height of the component. In case of the instruction, the
|
/// Returns the height of the content including padding. In case of the
|
||||||
/// height is calculated based on the text length.
|
/// instruction, the height is calculated based on the text length.
|
||||||
pub fn height(&self) -> i16 {
|
pub fn height(&self) -> i16 {
|
||||||
self.content.height()
|
self.content.height() + Self::HINT_INSETS.top + Self::HINT_INSETS.bottom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +127,9 @@ impl<'a> Component for Hint<'a> {
|
|||||||
|
|
||||||
fn place(&mut self, bounds: Rect) -> Rect {
|
fn place(&mut self, bounds: Rect) -> Rect {
|
||||||
debug_assert!(bounds.width() == screen().width());
|
debug_assert!(bounds.width() == screen().width());
|
||||||
debug_assert!(bounds.height() == self.content.height());
|
debug_assert!(bounds.height() == self.height());
|
||||||
let bounds = bounds.inset(Self::HINT_INSETS);
|
let bounds = bounds.inset(Self::HINT_INSETS);
|
||||||
|
|
||||||
if let HintContent::Instruction(instruction) = &mut self.content {
|
if let HintContent::Instruction(instruction) = &mut self.content {
|
||||||
let text_area = match instruction.icon {
|
let text_area = match instruction.icon {
|
||||||
Some(_) => bounds.split_left(instruction.icon_width()).1,
|
Some(_) => bounds.split_left(instruction.icon_width()).1,
|
||||||
@ -313,22 +314,29 @@ mod tests {
|
|||||||
// FIXME: this test is fine but the `screen()` is not returning the right value
|
// FIXME: this test is fine but the `screen()` is not returning the right value
|
||||||
// for eckhart println!("screen size: {:?}", screen().width());
|
// for eckhart println!("screen size: {:?}", screen().width());
|
||||||
|
|
||||||
|
let with_padding = |h: i16| h + Hint::HINT_INSETS.top + Hint::HINT_INSETS.bottom;
|
||||||
let hint_1line = Hint::new_instruction("Test", None);
|
let hint_1line = Hint::new_instruction("Test", None);
|
||||||
assert_eq!(hint_1line.height(), Hint::HEIGHT_MINIMAL);
|
assert_eq!(hint_1line.content.height(), Hint::HEIGHT_MINIMAL);
|
||||||
|
assert_eq!(hint_1line.height(), with_padding(Hint::HEIGHT_MINIMAL));
|
||||||
|
|
||||||
let hint_2lines = Hint::new_instruction(
|
let hint_2lines = Hint::new_instruction(
|
||||||
"The word appears multiple times in the backup.",
|
"The word appears multiple times in the backup.",
|
||||||
Some(theme::ICON_INFO),
|
Some(theme::ICON_INFO),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
hint_2lines.height(),
|
hint_2lines.content.height(),
|
||||||
Instruction::STYLE_INSTRUCTION.text_font.text_height() * 2
|
Instruction::STYLE_INSTRUCTION.text_font.text_height() * 2
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
hint_2lines.height(),
|
||||||
|
with_padding(Instruction::STYLE_INSTRUCTION.text_font.text_height() * 2)
|
||||||
|
);
|
||||||
|
|
||||||
let hint_3lines = Hint::new_instruction(
|
let hint_3lines = Hint::new_instruction(
|
||||||
"This is very long instruction which will span across at least three lines of the Hint component.",
|
"This is very long instruction which will span across at least three lines of the Hint component.",
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
assert_eq!(hint_3lines.height(), Hint::HEIGHT_MAXIMAL,);
|
assert_eq!(hint_3lines.content.height(), Hint::HEIGHT_MAXIMAL);
|
||||||
|
assert_eq!(hint_3lines.height(), with_padding(Hint::HEIGHT_MAXIMAL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user