mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 05:28:40 +00:00
WIP - show next page arrow instead of ellipsis
This commit is contained in:
parent
87a02ab2d4
commit
dfe337d480
@ -57,6 +57,11 @@ pub struct TextStyle {
|
||||
/// Foreground color used for drawing the ellipsis.
|
||||
pub ellipsis_color: Color,
|
||||
|
||||
/// Optional icon shown as ellipsis.
|
||||
pub ellipsis_icon: Option<&'static [u8]>,
|
||||
/// Optional icon to signal content continues from previous page.
|
||||
pub prev_page_icon: Option<&'static [u8]>,
|
||||
|
||||
/// Specifies which line-breaking strategy to use.
|
||||
pub line_breaking: LineBreaking,
|
||||
/// Specifies what to do at the end of the page.
|
||||
@ -79,8 +84,22 @@ impl TextStyle {
|
||||
ellipsis_color,
|
||||
line_breaking: LineBreaking::BreakAtWhitespace,
|
||||
page_breaking: PageBreaking::CutAndInsertEllipsis,
|
||||
ellipsis_icon: None,
|
||||
prev_page_icon: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Adding optional icon shown instead of "..." ellipsis.
|
||||
pub const fn with_ellipsis_icon(mut self, icon: &'static [u8]) -> Self {
|
||||
self.ellipsis_icon = Some(icon);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adding optional icon signalling content continues from previous page.
|
||||
pub const fn with_prev_page_icon(mut self, icon: &'static [u8]) -> Self {
|
||||
self.prev_page_icon = Some(icon);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayout {
|
||||
@ -362,13 +381,24 @@ impl LayoutSink for TextRenderer {
|
||||
}
|
||||
|
||||
fn ellipsis(&mut self, cursor: Point, layout: &TextLayout) {
|
||||
display::text(
|
||||
cursor,
|
||||
"...",
|
||||
layout.style.text_font,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
if let Some(icon) = layout.style.ellipsis_icon {
|
||||
// Icon should end little below the cursor's baseline
|
||||
let bottom_left = cursor + Offset::y(2);
|
||||
display::icon_bottom_left(
|
||||
bottom_left,
|
||||
icon,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
} else {
|
||||
display::text(
|
||||
cursor,
|
||||
"...",
|
||||
layout.style.text_font,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use super::{icon_rect, toif_info_ensure, Color};
|
||||
/// Storing the icon together with its name
|
||||
/// Needs to be a tuple-struct, so it can be made `const`
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct IconAndName(&'static [u8], &'static str);
|
||||
pub struct IconAndName(pub &'static [u8], pub &'static str);
|
||||
|
||||
impl IconAndName {
|
||||
pub const fn new(icon: &'static [u8], name: &'static str) -> Self {
|
||||
|
@ -91,6 +91,7 @@ pub fn rect_fill_rounded(r: Rect, fg_color: Color, bg_color: Color, radius: u8)
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws icon given its top left corner.
|
||||
/// NOTE: Cannot start at odd x-coordinate. In this case icon is shifted 1px
|
||||
/// left.
|
||||
pub fn icon_top_left(top_left: Point, data: &[u8], fg_color: Color, bg_color: Color) {
|
||||
@ -106,6 +107,20 @@ pub fn icon_top_left(top_left: Point, data: &[u8], fg_color: Color, bg_color: Co
|
||||
);
|
||||
}
|
||||
|
||||
/// Draws icon given its bottom left corner.
|
||||
pub fn icon_bottom_left(bottom_left: Point, data: &[u8], fg_color: Color, bg_color: Color) {
|
||||
let (toif_size, _toif_data) = toif_info_ensure(data, ToifFormat::GrayScaleEH);
|
||||
icon_top_left(
|
||||
Point {
|
||||
x: bottom_left.x,
|
||||
y: bottom_left.y - toif_size.y,
|
||||
},
|
||||
data,
|
||||
fg_color,
|
||||
bg_color,
|
||||
);
|
||||
}
|
||||
|
||||
/// Display icon given a center Point.
|
||||
pub fn icon(center: Point, data: &[u8], fg_color: Color, bg_color: Color) {
|
||||
let (toif_size, toif_data) = toif_info_ensure(data, ToifFormat::GrayScaleEH);
|
||||
|
@ -79,7 +79,8 @@ impl<const M: usize> Page<M> {
|
||||
theme::BG,
|
||||
theme::FG,
|
||||
theme::FG,
|
||||
);
|
||||
)
|
||||
.with_ellipsis_icon(theme::ICON_NEXT_PAGE.0);
|
||||
Self {
|
||||
ops: Vec::new(),
|
||||
layout: TextLayout::new(style),
|
||||
|
@ -104,6 +104,11 @@ pub struct TextStyle {
|
||||
/// Foreground color used for drawing the ellipsis.
|
||||
pub ellipsis_color: Color,
|
||||
|
||||
/// Optional icon shown as ellipsis.
|
||||
pub ellipsis_icon: Option<&'static [u8]>,
|
||||
/// Optional icon to signal content continues from previous page.
|
||||
pub prev_page_icon: Option<&'static [u8]>,
|
||||
|
||||
/// Specifies which line-breaking strategy to use.
|
||||
pub line_breaking: LineBreaking,
|
||||
/// Specifies what to do at the end of the page.
|
||||
@ -130,8 +135,22 @@ impl TextStyle {
|
||||
line_breaking: LineBreaking::BreakAtWhitespace,
|
||||
page_breaking: PageBreaking::CutAndInsertEllipsis,
|
||||
line_alignment: LineAlignment::Left,
|
||||
ellipsis_icon: None,
|
||||
prev_page_icon: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Adding optional icon shown instead of "..." ellipsis.
|
||||
pub const fn with_ellipsis_icon(mut self, icon: &'static [u8]) -> Self {
|
||||
self.ellipsis_icon = Some(icon);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adding optional icon signalling content continues from previous page.
|
||||
pub const fn with_prev_page_icon(mut self, icon: &'static [u8]) -> Self {
|
||||
self.prev_page_icon = Some(icon);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayout {
|
||||
@ -248,7 +267,6 @@ impl TextLayout {
|
||||
let text_len = to_display.length;
|
||||
let start = text.len() - text_len;
|
||||
let to_really_display = &text[start..];
|
||||
// let to_really_display = text.text[text.start..text.end].to_string();
|
||||
self.layout_text(to_really_display, cursor, sink)
|
||||
} else if let Op::Icon(icon) = op {
|
||||
self.layout_icon(icon, cursor, sink)
|
||||
@ -524,13 +542,24 @@ impl LayoutSink for TextRenderer {
|
||||
}
|
||||
|
||||
fn ellipsis(&mut self, cursor: Point, layout: &TextLayout) {
|
||||
display::text(
|
||||
cursor,
|
||||
"...",
|
||||
layout.style.text_font,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
if let Some(icon) = layout.style.ellipsis_icon {
|
||||
// Icon should end little below the cursor's baseline
|
||||
let bottom_left = cursor + Offset::y(2);
|
||||
display::icon_bottom_left(
|
||||
bottom_left,
|
||||
icon,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
} else {
|
||||
display::text(
|
||||
cursor,
|
||||
"...",
|
||||
layout.style.text_font,
|
||||
layout.style.ellipsis_color,
|
||||
layout.style.background_color,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(&mut self, cursor: Point, layout: &TextLayout, icon: Icon) {
|
||||
|
@ -13,10 +13,14 @@ pub const FONT_HEADER: Font = Font::BOLD;
|
||||
pub const FONT_CHOICE_ITEMS: Font = Font::NORMAL;
|
||||
|
||||
// Text constants.
|
||||
pub const TEXT_NORMAL: TextStyle = TextStyle::new(Font::NORMAL, FG, BG, FG, FG);
|
||||
pub const TEXT_DEMIBOLD: TextStyle = TextStyle::new(Font::DEMIBOLD, FG, BG, FG, FG);
|
||||
pub const TEXT_BOLD: TextStyle = TextStyle::new(Font::BOLD, FG, BG, FG, FG);
|
||||
pub const TEXT_MONO: TextStyle = TextStyle::new(Font::MONO, FG, BG, FG, FG);
|
||||
pub const TEXT_NORMAL: TextStyle =
|
||||
TextStyle::new(Font::NORMAL, FG, BG, FG, FG).with_ellipsis_icon(ICON_NEXT_PAGE.0);
|
||||
pub const TEXT_DEMIBOLD: TextStyle =
|
||||
TextStyle::new(Font::DEMIBOLD, FG, BG, FG, FG).with_ellipsis_icon(ICON_NEXT_PAGE.0);
|
||||
pub const TEXT_BOLD: TextStyle =
|
||||
TextStyle::new(Font::BOLD, FG, BG, FG, FG).with_ellipsis_icon(ICON_NEXT_PAGE.0);
|
||||
pub const TEXT_MONO: TextStyle =
|
||||
TextStyle::new(Font::MONO, FG, BG, FG, FG).with_ellipsis_icon(ICON_NEXT_PAGE.0);
|
||||
|
||||
pub const FORMATTED: FormattedFonts = FormattedFonts {
|
||||
normal: Font::NORMAL,
|
||||
|
Loading…
Reference in New Issue
Block a user