diff options
author | 2019-09-04 11:09:57 +0200 | |
---|---|---|
committer | 2019-09-04 11:09:57 +0200 | |
commit | c583a2174d28878a6b1a31288e80b96fac62e799 (patch) | |
tree | 36c80d9a0565980d6bbee62c548c8db142555ba2 /examples/ggez/renderer/text.rs | |
parent | 2c35103035e47485f2fb049f86b3c00feb4b99d2 (diff) | |
download | iced-c583a2174d28878a6b1a31288e80b96fac62e799.tar.gz iced-c583a2174d28878a6b1a31288e80b96fac62e799.tar.bz2 iced-c583a2174d28878a6b1a31288e80b96fac62e799.zip |
Improve tour example
Diffstat (limited to '')
-rw-r--r-- | examples/ggez/renderer/text.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/examples/ggez/renderer/text.rs b/examples/ggez/renderer/text.rs index a6f782fc..ecf1481e 100644 --- a/examples/ggez/renderer/text.rs +++ b/examples/ggez/renderer/text.rs @@ -6,7 +6,13 @@ use std::cell::RefCell; use std::f32; 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: Option<u16>, + ) -> iced::Node { + let font = self.font; let font_cache = graphics::font_cache(self.context); let content = String::from(content); @@ -17,6 +23,7 @@ impl text::Renderer<Color> for Renderer<'_> { // 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 size = size.map(f32::from).unwrap_or(self.font_size); iced::Node::with_measure(style, move |bounds| { let mut measure = measure.borrow_mut(); @@ -35,6 +42,7 @@ impl text::Renderer<Color> for Renderer<'_> { let mut text = Text::new(TextFragment { text: content.clone(), + font: Some(font), scale: Some(Scale { x: size, y: size }), ..Default::default() }); @@ -71,13 +79,16 @@ impl text::Renderer<Color> for Renderer<'_> { &mut self, bounds: iced::Rectangle, content: &str, - size: f32, + size: Option<u16>, color: Option<Color>, horizontal_alignment: text::HorizontalAlignment, _vertical_alignment: text::VerticalAlignment, ) { + let size = size.map(f32::from).unwrap_or(self.font_size); + let mut text = Text::new(TextFragment { text: String::from(content), + font: Some(self.font), scale: Some(Scale { x: size, y: size }), ..Default::default() }); @@ -101,7 +112,7 @@ impl text::Renderer<Color> for Renderer<'_> { x: bounds.x, y: bounds.y, }, - color, + color.or(Some(graphics::BLACK)), ); } } |