diff options
author | 2020-05-19 17:15:44 +0200 | |
---|---|---|
committer | 2020-05-19 17:15:44 +0200 | |
commit | 05af8d00d4c0f7b8e0ece85224fd90a92da86da8 (patch) | |
tree | 98e4774a2c0d4a2a0a01aff1d772f89c4cb0aa5e /graphics/src/widget/canvas/text.rs | |
parent | d4743183d40c6044ce6fa39e2a52919a32912cda (diff) | |
download | iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.tar.gz iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.tar.bz2 iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.zip |
Draft new `iced_graphics` crate :tada:
Diffstat (limited to 'graphics/src/widget/canvas/text.rs')
-rw-r--r-- | graphics/src/widget/canvas/text.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/graphics/src/widget/canvas/text.rs b/graphics/src/widget/canvas/text.rs new file mode 100644 index 00000000..c4cae30e --- /dev/null +++ b/graphics/src/widget/canvas/text.rs @@ -0,0 +1,49 @@ +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 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 + 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, +} + +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, + } + } +} + +impl From<String> for Text { + fn from(content: String) -> Text { + Text { + content, + ..Default::default() + } + } +} + +impl From<&str> for Text { + fn from(content: &str) -> Text { + String::from(content).into() + } +} |