feat(core): set maximum number of chunkified lines to 4

[no changelog]
mmilata/tt-ui-properties-same-screen
grdddj 7 months ago committed by Jiří Musil
parent d472c1306f
commit 4b87bc56d8

@ -59,6 +59,8 @@ pub struct Chunks {
pub chunk_size: usize, pub chunk_size: usize,
/// How big will be the space between chunks (in pixels). /// How big will be the space between chunks (in pixels).
pub x_offset: i16, pub x_offset: i16,
/// Maximum amount of rows on one page, if any.
pub max_rows: Option<usize>,
} }
impl Chunks { impl Chunks {
@ -66,8 +68,14 @@ impl Chunks {
Chunks { Chunks {
chunk_size, chunk_size,
x_offset, x_offset,
max_rows: None,
} }
} }
pub const fn with_max_rows(mut self, max_rows: usize) -> Self {
self.max_rows = Some(max_rows);
self
}
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -238,6 +246,7 @@ impl TextLayout {
) -> LayoutFit { ) -> LayoutFit {
let init_cursor = *cursor; let init_cursor = *cursor;
let mut remaining_text = text; let mut remaining_text = text;
let mut num_lines = 1;
// Check if bounding box is high enough for at least one line. // Check if bounding box is high enough for at least one line.
if cursor.y > self.bottom_y() { if cursor.y > self.bottom_y() {
@ -273,6 +282,15 @@ impl TextLayout {
while !remaining_text.is_empty() { while !remaining_text.is_empty() {
let is_last_line = cursor.y + self.style.text_font.line_height() > self.bottom_y(); let is_last_line = cursor.y + self.style.text_font.line_height() > self.bottom_y();
let mut force_next_page = false;
// Check if we have not reached the maximum number of lines we want to draw.
if let Some(max_rows) = self.style.chunks.and_then(|c| c.max_rows) {
if num_lines >= max_rows {
force_next_page = true;
}
}
let line_ending_space = if is_last_line { let line_ending_space = if is_last_line {
self.style.ellipsis_width() self.style.ellipsis_width()
} else { } else {
@ -325,6 +343,7 @@ impl TextLayout {
if span.advance.y > 0 { if span.advance.y > 0 {
// We're advancing to the next line. // We're advancing to the next line.
num_lines += 1;
// Possibly making a bigger/smaller vertical jump // Possibly making a bigger/smaller vertical jump
span.advance.y += self.style.line_spacing; span.advance.y += self.style.line_spacing;
@ -333,8 +352,9 @@ impl TextLayout {
if span.insert_hyphen_before_line_break { if span.insert_hyphen_before_line_break {
sink.hyphen(*cursor, self); sink.hyphen(*cursor, self);
} }
// Check the amount of vertical space we have left. // Check the amount of vertical space we have left --- or manually force the
if cursor.y + span.advance.y > self.bottom_y() { // next page.
if force_next_page || cursor.y + span.advance.y > self.bottom_y() {
// Not enough space on this page. // Not enough space on this page.
if !remaining_text.is_empty() { if !remaining_text.is_empty() {
// Append ellipsis to indicate more content is available, but only if we // Append ellipsis to indicate more content is available, but only if we

@ -590,9 +590,9 @@ pub const TEXT_MONO_ADDRESS_CHUNKS: TextStyle = TEXT_MONO
.with_line_spacing(5); .with_line_spacing(5);
/// Smaller horizontal chunk offset, used e.g. for long Cardano addresses. /// Smaller horizontal chunk offset, used e.g. for long Cardano addresses.
/// Also moving the next page ellipsis to the left (as there is a space on the /// Also moving the next page ellipsis to the left (as there is a space on the
/// left). /// left). Last but not least, maximum number of rows is 4 in this case.
pub const TEXT_MONO_ADDRESS_CHUNKS_SMALLER_X_OFFSET: TextStyle = TEXT_MONO pub const TEXT_MONO_ADDRESS_CHUNKS_SMALLER_X_OFFSET: TextStyle = TEXT_MONO
.with_chunks(Chunks::new(4, 7)) .with_chunks(Chunks::new(4, 7).with_max_rows(4))
.with_line_spacing(5) .with_line_spacing(5)
.with_ellipsis_icon(ICON_PAGE_NEXT, -12); .with_ellipsis_icon(ICON_PAGE_NEXT, -12);

Loading…
Cancel
Save