diff options
author | 2020-03-08 00:06:04 +0100 | |
---|---|---|
committer | 2020-03-08 00:06:04 +0100 | |
commit | e9194cbf4a95ad743e16864f949716701d984a0d (patch) | |
tree | 1da108a2da6d0092c031ffe00388af380d51aabc /wgpu/src/widget | |
parent | 38d967c414af2187b112c654082df7083e0ee7e5 (diff) | |
download | iced-e9194cbf4a95ad743e16864f949716701d984a0d.tar.gz iced-e9194cbf4a95ad743e16864f949716701d984a0d.tar.bz2 iced-e9194cbf4a95ad743e16864f949716701d984a0d.zip |
Transform text position in `Frame::fill_text`
Also add a warning explaining its current limitations.
Diffstat (limited to 'wgpu/src/widget')
-rw-r--r-- | wgpu/src/widget/canvas/frame.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/wgpu/src/widget/canvas/frame.rs b/wgpu/src/widget/canvas/frame.rs index 0bf58320..7d7ce06a 100644 --- a/wgpu/src/widget/canvas/frame.rs +++ b/wgpu/src/widget/canvas/frame.rs @@ -159,18 +159,38 @@ impl Frame { /// Draws the characters of the given [`Text`] on the [`Frame`], filling /// them with the given color. /// + /// __Warning:__ Text currently does not work well with rotations and scale + /// transforms! The position will be correctly transformed, but the + /// resulting glyphs will not be rotated or scaled properly. + /// + /// Additionally, all text will be rendered on top of all the layers of + /// a [`Canvas`]. Therefore, it is currently only meant to be used for + /// overlays, which is the most common use case. + /// + /// Support for vectorial text is planned, and should address all these + /// limitations. + /// /// [`Text`]: struct.Text.html /// [`Frame`]: struct.Frame.html - #[inline] pub fn fill_text(&mut self, text: Text) { use std::f32; + let position = if self.transforms.current.is_identity { + text.position + } else { + let transformed = self.transforms.current.raw.transform_point( + lyon::math::Point::new(text.position.x, text.position.y), + ); + + Point::new(transformed.x, transformed.y) + }; + // TODO: Use vectorial text instead of primitive self.primitives.push(Primitive::Text { content: text.content, bounds: Rectangle { - x: text.position.x, - y: text.position.y, + x: position.x, + y: position.y, width: f32::INFINITY, height: f32::INFINITY, }, |