summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-11 01:10:59 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-11 01:10:59 +0100
commitdba538eb4d1df62cf9b5a347f04a52e8535917ad (patch)
tree85aaae46546f732f7fbf583259e6ef51da9f6f2b /examples
parent351d90c33999179b03bdb5e9c0575a197e98eff8 (diff)
downloadiced-dba538eb4d1df62cf9b5a347f04a52e8535917ad.tar.gz
iced-dba538eb4d1df62cf9b5a347f04a52e8535917ad.tar.bz2
iced-dba538eb4d1df62cf9b5a347f04a52e8535917ad.zip
Add instructions to `bezier_tool` example
Diffstat (limited to 'examples')
-rw-r--r--examples/bezier_tool.rs43
1 files changed, 36 insertions, 7 deletions
diff --git a/examples/bezier_tool.rs b/examples/bezier_tool.rs
index 4cb6312f..043d265c 100644
--- a/examples/bezier_tool.rs
+++ b/examples/bezier_tool.rs
@@ -11,8 +11,9 @@ mod bezier {
// if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers.
use iced_native::{
- input, layout, Clipboard, Element, Event, Hasher, Layout, Length,
- MouseCursor, Point, Size, Vector, Widget,
+ input, layout, Clipboard, Color, Element, Event, Font, Hasher,
+ HorizontalAlignment, Layout, Length, MouseCursor, Point, Size, Vector,
+ VerticalAlignment, Widget,
};
use iced_wgpu::{
triangle::{Mesh2D, Vertex2D},
@@ -89,7 +90,7 @@ mod bezier {
fn draw(
&self,
_renderer: &mut Renderer,
- _defaults: &Defaults,
+ defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point,
) -> (Primitive, MouseCursor) {
@@ -185,14 +186,42 @@ mod bezier {
)
.unwrap();
+ let mesh = Primitive::Mesh2D(Arc::new(Mesh2D {
+ vertices: buffer.vertices,
+ indices: buffer.indices,
+ }));
+
(
Primitive::Clip {
bounds,
offset: Vector::new(0, 0),
- content: Box::new(Primitive::Mesh2D(Arc::new(Mesh2D {
- vertices: buffer.vertices,
- indices: buffer.indices,
- }))),
+ content: Box::new(
+ if self.curves.is_empty()
+ && self.state.pending.is_none()
+ {
+ let instructions = Primitive::Text {
+ bounds,
+ color: Color {
+ a: defaults.text.color.a * 0.7,
+ ..defaults.text.color
+ },
+ content: String::from(
+ "Click to create bezier curves!",
+ ),
+ font: Font::Default,
+ size: 30.0,
+ horizontal_alignment:
+ HorizontalAlignment::Center,
+ vertical_alignment: VerticalAlignment::Center,
+ };
+
+ Primitive::Group {
+ primitives: vec![mesh, instructions],
+ }
+ } else {
+ mesh
+ },
+ ),
},
MouseCursor::OutOfBounds,
)