cache text buf
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use cosmic_text::{Attrs, Family, FontSystem, Metrics, Shaping};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{prelude::*, util::MutDetect};
|
||||
|
||||
pub struct Text {
|
||||
pub content: String,
|
||||
pub content: MutDetect<String>,
|
||||
pub attrs: TextAttrs,
|
||||
/// inner alignment of text region (within where its drawn)
|
||||
pub align: Align,
|
||||
@@ -32,7 +32,7 @@ impl Text {
|
||||
pub fn new(content: impl Into<String>) -> Self {
|
||||
let attrs = TextAttrs::default();
|
||||
Self {
|
||||
content: content.into(),
|
||||
content: content.into().into(),
|
||||
buf: TextBuffer::new_empty(Metrics::new(attrs.font_size, attrs.line_height)),
|
||||
attrs,
|
||||
align: Align::Center,
|
||||
@@ -49,12 +49,15 @@ impl Text {
|
||||
font_system,
|
||||
Metrics::new(self.attrs.font_size, self.attrs.line_height),
|
||||
);
|
||||
self.buf.set_text(
|
||||
font_system,
|
||||
&self.content,
|
||||
&Attrs::new().family(self.attrs.family),
|
||||
Shaping::Advanced,
|
||||
);
|
||||
if self.content.changed {
|
||||
self.content.changed = false;
|
||||
self.buf.set_text(
|
||||
font_system,
|
||||
&self.content,
|
||||
&Attrs::new().family(self.attrs.family),
|
||||
Shaping::Advanced,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user