From 1bb85556915bb00057ef2ee66a596592c292b15b Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Thu, 5 Mar 2020 22:05:05 -0700 Subject: implement text support in canvas widget --- wgpu/src/widget/canvas/text.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 wgpu/src/widget/canvas/text.rs (limited to 'wgpu/src/widget/canvas/text.rs') diff --git a/wgpu/src/widget/canvas/text.rs b/wgpu/src/widget/canvas/text.rs new file mode 100644 index 00000000..5f6abe58 --- /dev/null +++ b/wgpu/src/widget/canvas/text.rs @@ -0,0 +1,20 @@ +use iced_native::{Color, Font, HorizontalAlignment, Rectangle, VerticalAlignment}; + +/// A text node to be drawn to a canvas +#[derive(Debug, Clone)] +pub struct TextNode { + /// The contents of the text + pub content: String, + /// The bounds of the text + pub bounds: Rectangle, + /// The color of the text + pub color: Color, + /// The size of the text + pub size: f32, + /// The font of the text + pub font: Font, + /// The horizontal alignment of the text + pub horizontal_alignment: HorizontalAlignment, + /// The vertical alignment of the text + pub vertical_alignment: VerticalAlignment, +} -- cgit From f35c9f25f03976e058e892662454b1143fd172cd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 7 Mar 2020 22:27:02 +0100 Subject: Rename `canvas::TextNode` to `canvas::Text` --- wgpu/src/widget/canvas/text.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'wgpu/src/widget/canvas/text.rs') diff --git a/wgpu/src/widget/canvas/text.rs b/wgpu/src/widget/canvas/text.rs index 5f6abe58..241f8503 100644 --- a/wgpu/src/widget/canvas/text.rs +++ b/wgpu/src/widget/canvas/text.rs @@ -1,8 +1,10 @@ -use iced_native::{Color, Font, HorizontalAlignment, Rectangle, VerticalAlignment}; +use iced_native::{ + Color, Font, HorizontalAlignment, Rectangle, VerticalAlignment, +}; -/// A text node to be drawn to a canvas +/// A bunch of text that can be drawn to a canvas #[derive(Debug, Clone)] -pub struct TextNode { +pub struct Text { /// The contents of the text pub content: String, /// The bounds of the text -- cgit From b74e7e7353d69ffb54cf0c0f0574ea7abf0f3a68 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 7 Mar 2020 23:45:54 +0100 Subject: Implement `Primitive::Cached` --- wgpu/src/widget/canvas/text.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'wgpu/src/widget/canvas/text.rs') diff --git a/wgpu/src/widget/canvas/text.rs b/wgpu/src/widget/canvas/text.rs index 241f8503..1f9bdc19 100644 --- a/wgpu/src/widget/canvas/text.rs +++ b/wgpu/src/widget/canvas/text.rs @@ -1,14 +1,12 @@ -use iced_native::{ - Color, Font, HorizontalAlignment, Rectangle, VerticalAlignment, -}; +use iced_native::{Color, Font, HorizontalAlignment, Point, VerticalAlignment}; /// A bunch of text that can be drawn to a canvas #[derive(Debug, Clone)] pub struct Text { /// The contents of the text pub content: String, - /// The bounds of the text - pub bounds: Rectangle, + /// The position where to begin drawing the text (top-left corner coordinates) + pub position: Point, /// The color of the text pub color: Color, /// The size of the text -- cgit From b4f970ee7317297615848cd12f422c0cd2889f60 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 8 Mar 2020 00:06:48 +0100 Subject: Implement `Default` for `canvas::Text` --- wgpu/src/widget/canvas/text.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'wgpu/src/widget/canvas/text.rs') diff --git a/wgpu/src/widget/canvas/text.rs b/wgpu/src/widget/canvas/text.rs index 1f9bdc19..d1cf1a0f 100644 --- a/wgpu/src/widget/canvas/text.rs +++ b/wgpu/src/widget/canvas/text.rs @@ -18,3 +18,17 @@ pub struct Text { /// The vertical alignment of the text pub vertical_alignment: VerticalAlignment, } + +impl Default for Text { + fn default() -> Text { + Text { + content: String::new(), + position: Point::ORIGIN, + color: Color::BLACK, + size: 16.0, + font: Font::Default, + horizontal_alignment: HorizontalAlignment::Left, + vertical_alignment: VerticalAlignment::Top, + } + } +} -- cgit