Make FontSystem global and simplify Paragraph API

This commit is contained in:
Héctor Ramón Jiménez 2023-09-11 02:47:24 +02:00
parent 9245423c5d
commit 346af3f8b0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
15 changed files with 165 additions and 328 deletions

View file

@ -158,41 +158,6 @@ where
self.backend.load_font(bytes);
}
fn create_paragraph(&self, text: Text<'_, Self::Font>) -> text::Paragraph {
text::Paragraph::with_text(text, self.backend.font_system())
}
fn update_paragraph(
&self,
paragraph: &mut Self::Paragraph,
text: Text<'_, Self::Font>,
) {
let font_system = self.backend.font_system();
if paragraph.version() != font_system.version() {
// The font system has changed, paragraph fonts may be outdated
*paragraph = self.create_paragraph(text);
} else {
match core::text::compare(paragraph, text) {
core::text::Difference::None => {}
core::text::Difference::Bounds => {
self.resize_paragraph(paragraph, text.bounds);
}
core::text::Difference::Shape => {
*paragraph = self.create_paragraph(text);
}
}
}
}
fn resize_paragraph(
&self,
paragraph: &mut Self::Paragraph,
new_bounds: Size,
) {
paragraph.resize(new_bounds, self.backend.font_system());
}
fn fill_paragraph(
&mut self,
paragraph: &Self::Paragraph,