mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
fix(core/rust): make vertical alignment for FormattedText work for paginated content
[no changelog]
This commit is contained in:
parent
ef5469ad90
commit
947e2ee24f
@ -57,10 +57,13 @@ impl<T: StringType + Clone> FormattedText<T> {
|
|||||||
impl<T: StringType + Clone> Paginate for FormattedText<T> {
|
impl<T: StringType + Clone> Paginate for FormattedText<T> {
|
||||||
fn page_count(&mut self) -> usize {
|
fn page_count(&mut self) -> usize {
|
||||||
let mut page_count = 1; // There's always at least one page.
|
let mut page_count = 1; // There's always at least one page.
|
||||||
let mut char_offset = 0;
|
|
||||||
|
|
||||||
// Make sure we're starting from the beginning.
|
// Make sure we're starting page counting from the very beginning
|
||||||
self.char_offset = char_offset;
|
// (but remembering the offsets not to change them).
|
||||||
|
let initial_y_offset = self.y_offset;
|
||||||
|
let initial_char_offset = self.char_offset;
|
||||||
|
self.char_offset = 0;
|
||||||
|
self.y_offset = 0;
|
||||||
|
|
||||||
// Looping through the content and counting pages
|
// Looping through the content and counting pages
|
||||||
// until we finally fit.
|
// until we finally fit.
|
||||||
@ -68,31 +71,30 @@ impl<T: StringType + Clone> Paginate for FormattedText<T> {
|
|||||||
let fit = self.layout_content(&mut TextNoOp);
|
let fit = self.layout_content(&mut TextNoOp);
|
||||||
match fit {
|
match fit {
|
||||||
LayoutFit::Fitting { .. } => {
|
LayoutFit::Fitting { .. } => {
|
||||||
break; // TODO: We should consider if there's more content
|
break;
|
||||||
// to render.
|
|
||||||
}
|
}
|
||||||
LayoutFit::OutOfBounds {
|
LayoutFit::OutOfBounds {
|
||||||
processed_chars, ..
|
processed_chars, ..
|
||||||
} => {
|
} => {
|
||||||
page_count += 1;
|
page_count += 1;
|
||||||
char_offset += processed_chars;
|
self.char_offset += processed_chars;
|
||||||
self.char_offset = char_offset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the char offset back to the beginning.
|
// Setting the offsets back to the initial values.
|
||||||
self.char_offset = 0;
|
self.char_offset = initial_char_offset;
|
||||||
|
self.y_offset = initial_y_offset;
|
||||||
|
|
||||||
page_count
|
page_count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_page(&mut self, to_page: usize) {
|
fn change_page(&mut self, to_page: usize) {
|
||||||
let mut active_page = 0;
|
let mut active_page = 0;
|
||||||
let mut char_offset = 0;
|
|
||||||
|
|
||||||
// Make sure we're starting from the beginning.
|
// Make sure we're starting from the beginning.
|
||||||
self.char_offset = char_offset;
|
self.char_offset = 0;
|
||||||
|
self.y_offset = 0;
|
||||||
|
|
||||||
// Looping through the content until we arrive at
|
// Looping through the content until we arrive at
|
||||||
// the wanted page.
|
// the wanted page.
|
||||||
@ -100,19 +102,18 @@ impl<T: StringType + Clone> Paginate for FormattedText<T> {
|
|||||||
while active_page < to_page {
|
while active_page < to_page {
|
||||||
match fit {
|
match fit {
|
||||||
LayoutFit::Fitting { .. } => {
|
LayoutFit::Fitting { .. } => {
|
||||||
break; // TODO: We should consider if there's more content
|
break;
|
||||||
// to render.
|
|
||||||
}
|
}
|
||||||
LayoutFit::OutOfBounds {
|
LayoutFit::OutOfBounds {
|
||||||
processed_chars, ..
|
processed_chars, ..
|
||||||
} => {
|
} => {
|
||||||
active_page += 1;
|
active_page += 1;
|
||||||
char_offset += processed_chars;
|
self.char_offset += processed_chars;
|
||||||
self.char_offset = char_offset;
|
|
||||||
fit = self.layout_content(&mut TextNoOp);
|
fit = self.layout_content(&mut TextNoOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Setting appropriate self.y_offset
|
||||||
self.align_vertically(fit.height());
|
self.align_vertically(fit.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user