summaryrefslogtreecommitdiffstats
path: root/graphics/src/geometry/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-03 04:57:55 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-03 04:57:55 +0100
commit6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f (patch)
tree7a9d57f52e3bee9f4d910c89178dc3e2917957a1 /graphics/src/geometry/text.rs
parentd13d19ba3569560edd67f20b48f37548d10ceee9 (diff)
downloadiced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.tar.gz
iced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.tar.bz2
iced-6cc48b5c62bac287b8f9f1c79c1fb7486c51b18f.zip
Move `Canvas` and `QRCode` to `iced` crate
Rename `canvas` modules to `geometry` in graphics subcrates
Diffstat (limited to 'graphics/src/geometry/text.rs')
-rw-r--r--graphics/src/geometry/text.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/graphics/src/geometry/text.rs b/graphics/src/geometry/text.rs
new file mode 100644
index 00000000..8c0b2dfb
--- /dev/null
+++ b/graphics/src/geometry/text.rs
@@ -0,0 +1,57 @@
+use crate::alignment;
+use crate::{Color, Font, Point};
+
+/// 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 of the text relative to the alignment properties.
+ /// By default, this position will be relative to the top-left corner coordinate meaning that
+ /// if the horizontal and vertical alignments are unchanged, this property will tell where the
+ /// top-left corner of the text should be placed.
+ /// By changing the horizontal_alignment and vertical_alignment properties, you are are able to
+ /// change what part of text is placed at this positions.
+ /// For example, when the horizontal_alignment and vertical_alignment are set to Center, the
+ /// center of the text will be placed at the given position NOT the top-left coordinate.
+ 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: alignment::Horizontal,
+ /// The vertical alignment of the text
+ pub vertical_alignment: alignment::Vertical,
+}
+
+impl Default for Text {
+ fn default() -> Text {
+ Text {
+ content: String::new(),
+ position: Point::ORIGIN,
+ color: Color::BLACK,
+ size: 16.0,
+ font: Font::SansSerif,
+ horizontal_alignment: alignment::Horizontal::Left,
+ vertical_alignment: alignment::Vertical::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()
+ }
+}