WIP - use render_text instead of layout_ops

tychovrahe/trbootloader/main_before
grdddj 1 year ago
parent 14976d8a96
commit f742318a08

@ -175,8 +175,8 @@ impl TextLayout {
}
/// Draw as much text as possible on the current screen.
pub fn render_text(&self, text: &str) {
self.layout_text(text, &mut self.initial_cursor(), &mut TextRenderer);
pub fn render_text(&self, text: &str) -> LayoutFit {
self.layout_text(text, &mut self.initial_cursor(), &mut TextRenderer)
}
pub fn layout_ops(

@ -5,8 +5,6 @@ pub mod loader;
pub mod tjpgd;
pub mod toif;
use heapless::Vec;
use super::{
constant,
geometry::{Alignment, Offset, Point, Rect},
@ -30,7 +28,7 @@ use crate::{
trezorhal::{buffers, display, time, uzlib::UzlibContext},
ui::{
component::text::{
layout::{Op, TextLayout, TextRenderer},
layout::{LayoutFit, TextLayout},
TextStyle,
},
lerp::Lerp,
@ -871,15 +869,10 @@ pub fn text_multiline_split_words(
let text_layout = TextLayout::new(text_style)
.with_bounds(area)
.with_align(alignment);
let mut cursor = area.top_left() + Offset::y(font.line_height());
let mut ops: Vec<Op, 1> = Vec::new();
unwrap!(ops.push(Op::Text(text)));
text_layout.layout_ops(&mut ops.into_iter(), &mut cursor, &mut TextRenderer);
let drawn_height = cursor.y - area.top_left().y;
if drawn_height >= area.height() {
None
} else {
Some(area.split_top(drawn_height).1)
let layout_fit = text_layout.render_text(text);
match layout_fit {
LayoutFit::Fitting { height, .. } => Some(area.split_top(height).1),
LayoutFit::OutOfBounds { .. } => None,
}
}

Loading…
Cancel
Save