summaryrefslogtreecommitdiffstats
path: root/graphics/src/text/paragraph.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-09-09 11:21:32 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-09-09 11:21:32 +0200
commit3450987355be7fe029db112474d06613929b54c7 (patch)
tree1d2186d822add1becdd5c942cc6a6c67e5437b57 /graphics/src/text/paragraph.rs
parent837529bc995a728300c61fc102474cc31f7a6500 (diff)
downloadiced-3450987355be7fe029db112474d06613929b54c7.tar.gz
iced-3450987355be7fe029db112474d06613929b54c7.tar.bz2
iced-3450987355be7fe029db112474d06613929b54c7.zip
Invalidate existing paragraphs when new fonts are loaded
Diffstat (limited to 'graphics/src/text/paragraph.rs')
-rw-r--r--graphics/src/text/paragraph.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/graphics/src/text/paragraph.rs b/graphics/src/text/paragraph.rs
index ee7c04c8..cd12bc8f 100644
--- a/graphics/src/text/paragraph.rs
+++ b/graphics/src/text/paragraph.rs
@@ -19,6 +19,7 @@ struct Internal {
vertical_alignment: alignment::Vertical,
bounds: Size,
min_bounds: Size,
+ version: text::Version,
}
impl Paragraph {
@@ -27,9 +28,9 @@ impl Paragraph {
}
pub fn with_text(text: Text<'_, Font>, font_system: &FontSystem) -> Self {
- log::trace!("\nAllocating paragraph: {}", text.content);
+ log::trace!("Allocating paragraph: {}", text.content);
- let mut font_system = font_system.write();
+ let (mut font_system, version) = font_system.write();
let mut buffer = cosmic_text::Buffer::new(
&mut font_system,
@@ -63,6 +64,7 @@ impl Paragraph {
shaping: text.shaping,
bounds: text.bounds,
min_bounds,
+ version,
})))
}
@@ -70,6 +72,10 @@ impl Paragraph {
&self.internal().buffer
}
+ pub fn version(&self) -> text::Version {
+ self.internal().version
+ }
+
pub fn downgrade(&self) -> Weak {
let paragraph = self.internal();
@@ -89,8 +95,10 @@ impl Paragraph {
match Arc::try_unwrap(paragraph) {
Ok(mut internal) => {
+ let (mut font_system, _) = font_system.write();
+
internal.buffer.set_size(
- &mut font_system.write(),
+ &mut font_system,
new_bounds.width,
new_bounds.height,
);
@@ -246,6 +254,7 @@ impl Default for Internal {
vertical_alignment: alignment::Vertical::Top,
bounds: Size::ZERO,
min_bounds: Size::ZERO,
+ version: text::Version::default(),
}
}
}