summaryrefslogtreecommitdiffstats
path: root/native/src/widget/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-09-24 15:39:33 +0200
committerLibravatar GitHub <noreply@github.com>2019-09-24 15:39:33 +0200
commit68c4752e998dca1d618380ce4e7d8ac52b710056 (patch)
tree35e386030b072c189509bb2ed3adeaec5b0fd4d1 /native/src/widget/text.rs
parentbb5cac49d028eb53c259ae58e3a007ebfb736fd4 (diff)
parent05c7c39ecb8910c75b82dc4052a7720fb2d42b4a (diff)
downloadiced-68c4752e998dca1d618380ce4e7d8ac52b710056.tar.gz
iced-68c4752e998dca1d618380ce4e7d8ac52b710056.tar.bz2
iced-68c4752e998dca1d618380ce4e7d8ac52b710056.zip
Merge pull request #17 from hecrj/web
Basic web support (core, native, and web crates)
Diffstat (limited to 'native/src/widget/text.rs')
-rw-r--r--native/src/widget/text.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs
new file mode 100644
index 00000000..5ca6ebf3
--- /dev/null
+++ b/native/src/widget/text.rs
@@ -0,0 +1,79 @@
+//! Write some text for your users to read.
+use crate::{Element, Hasher, Layout, MouseCursor, Node, Point, Widget};
+
+use std::hash::Hash;
+
+pub use iced_core::text::*;
+
+impl<Message, Renderer> Widget<Message, Renderer> for Text
+where
+ Renderer: self::Renderer,
+{
+ fn node(&self, renderer: &mut Renderer) -> Node {
+ renderer.node(&self)
+ }
+
+ fn draw(
+ &self,
+ renderer: &mut Renderer,
+ layout: Layout<'_>,
+ _cursor_position: Point,
+ ) -> MouseCursor {
+ renderer.draw(&self, layout);
+
+ MouseCursor::OutOfBounds
+ }
+
+ fn hash_layout(&self, state: &mut Hasher) {
+ self.content.hash(state);
+ self.size.hash(state);
+ self.width.hash(state);
+ self.height.hash(state);
+ }
+}
+
+/// The renderer of a [`Text`] fragment.
+///
+/// Your [renderer] will need to implement this trait before being
+/// able to use [`Text`] in your [`UserInterface`].
+///
+/// [`Text`]: struct.Text.html
+/// [renderer]: ../../renderer/index.html
+/// [`UserInterface`]: ../../struct.UserInterface.html
+pub trait Renderer {
+ /// Creates a [`Node`] with the given [`Style`] for the provided [`Text`]
+ /// contents and size.
+ ///
+ /// You should probably use [`Node::with_measure`] to allow [`Text`] to
+ /// adapt to the dimensions of its container.
+ ///
+ /// [`Node`]: ../../struct.Node.html
+ /// [`Style`]: ../../struct.Style.html
+ /// [`Text`]: struct.Text.html
+ /// [`Node::with_measure`]: ../../struct.Node.html#method.with_measure
+ fn node(&self, text: &Text) -> Node;
+
+ /// Draws a [`Text`] fragment.
+ ///
+ /// It receives:
+ /// * the bounds of the [`Text`]
+ /// * the contents of the [`Text`]
+ /// * the size of the [`Text`]
+ /// * the color of the [`Text`]
+ /// * the [`HorizontalAlignment`] of the [`Text`]
+ /// * the [`VerticalAlignment`] of the [`Text`]
+ ///
+ /// [`Text`]: struct.Text.html
+ /// [`HorizontalAlignment`]: enum.HorizontalAlignment.html
+ /// [`VerticalAlignment`]: enum.VerticalAlignment.html
+ fn draw(&mut self, text: &Text, layout: Layout<'_>);
+}
+
+impl<'a, Message, Renderer> From<Text> for Element<'a, Message, Renderer>
+where
+ Renderer: self::Renderer,
+{
+ fn from(text: Text) -> Element<'a, Message, Renderer> {
+ Element::new(text)
+ }
+}