Update `ggez` example to `FontCache` changes
This commit is contained in:
parent
c7956cf526
commit
e1ff3f8a97
|
@ -19,4 +19,4 @@ twox-hash = "1.5"
|
||||||
winit = { version = "0.20.0-alpha3", optional = true }
|
winit = { version = "0.20.0-alpha3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ggez = { version = "0.5", git = "https://github.com/hecrj/ggez" }
|
ggez = { version = "0.5", git = "https://github.com/hecrj/ggez.git", branch = "font-cache" }
|
||||||
|
|
|
@ -9,16 +9,16 @@ impl text::Renderer<Color> for Renderer<'_> {
|
||||||
fn node(&self, style: iced::Style, content: &str, size: f32) -> iced::Node {
|
fn node(&self, style: iced::Style, content: &str, size: f32) -> iced::Node {
|
||||||
let font_cache = graphics::font_cache(self.context);
|
let font_cache = graphics::font_cache(self.context);
|
||||||
let content = String::from(content);
|
let content = String::from(content);
|
||||||
|
|
||||||
|
// TODO: Investigate why stretch tries to measure this MANY times
|
||||||
|
// with every ancestor's bounds.
|
||||||
|
// Bug? Using the library wrong? I should probably open an issue on
|
||||||
|
// the stretch repository.
|
||||||
|
// I noticed that the first measure is the one that matters in
|
||||||
|
// practice. Here, we use a RefCell to store the cached measurement.
|
||||||
let measure = RefCell::new(None);
|
let measure = RefCell::new(None);
|
||||||
|
|
||||||
iced::Node::with_measure(style, move |bounds| {
|
iced::Node::with_measure(style, move |bounds| {
|
||||||
// TODO: Investigate why stretch tries to measure this MANY times
|
|
||||||
// with every ancestor's bounds.
|
|
||||||
// Bug? Using the library wrong? I should probably open an issue on
|
|
||||||
// the stretch repository.
|
|
||||||
// I noticed that the first measure is the one that matters in
|
|
||||||
// practice. Here, we use a RefCell to store the cached
|
|
||||||
// measurement.
|
|
||||||
let mut measure = measure.borrow_mut();
|
let mut measure = measure.borrow_mut();
|
||||||
|
|
||||||
if measure.is_none() {
|
if measure.is_none() {
|
||||||
|
@ -47,7 +47,7 @@ impl text::Renderer<Color> for Renderer<'_> {
|
||||||
Align::Left,
|
Align::Left,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (width, height) = text.dimensions(&font_cache);
|
let (width, height) = font_cache.dimensions(&text);
|
||||||
|
|
||||||
let size = iced::Size {
|
let size = iced::Size {
|
||||||
width: width as f32,
|
width: width as f32,
|
||||||
|
|
Loading…
Reference in New Issue