Add instructions to bezier_tool example

This commit is contained in:
Héctor Ramón Jiménez 2020-01-11 01:10:59 +01:00
parent 351d90c339
commit dba538eb4d

View File

@ -11,8 +11,9 @@ mod bezier {
// if you wish to, by creating your own `Renderer` trait, which could be // if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers. // implemented by `iced_wgpu` and other renderers.
use iced_native::{ use iced_native::{
input, layout, Clipboard, Element, Event, Hasher, Layout, Length, input, layout, Clipboard, Color, Element, Event, Font, Hasher,
MouseCursor, Point, Size, Vector, Widget, HorizontalAlignment, Layout, Length, MouseCursor, Point, Size, Vector,
VerticalAlignment, Widget,
}; };
use iced_wgpu::{ use iced_wgpu::{
triangle::{Mesh2D, Vertex2D}, triangle::{Mesh2D, Vertex2D},
@ -89,7 +90,7 @@ mod bezier {
fn draw( fn draw(
&self, &self,
_renderer: &mut Renderer, _renderer: &mut Renderer,
_defaults: &Defaults, defaults: &Defaults,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
) -> (Primitive, MouseCursor) { ) -> (Primitive, MouseCursor) {
@ -185,14 +186,42 @@ mod bezier {
) )
.unwrap(); .unwrap();
let mesh = Primitive::Mesh2D(Arc::new(Mesh2D {
vertices: buffer.vertices,
indices: buffer.indices,
}));
( (
Primitive::Clip { Primitive::Clip {
bounds, bounds,
offset: Vector::new(0, 0), offset: Vector::new(0, 0),
content: Box::new(Primitive::Mesh2D(Arc::new(Mesh2D { content: Box::new(
vertices: buffer.vertices, if self.curves.is_empty()
indices: buffer.indices, && 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, MouseCursor::OutOfBounds,
) )