Fix druid dependency

This commit is contained in:
Enrico Lumetti 2020-11-08 21:39:33 +01:00
parent 0f8c318bb6
commit 9f1db67d23
4 changed files with 334 additions and 443 deletions

731
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,24 +4,25 @@ version = "0.1.0"
authors = ["Enrico Lumetti <enrico.lumetti@gmail.com>"] authors = ["Enrico Lumetti <enrico.lumetti@gmail.com>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
udev = "0.2" udev = "0.2"
libc = "0.2" libc = "0.2"
errno = "0.2" errno = "0.2"
csv = "1.1" csv = "1.1"
druid = { git = "https://github.com/doppioandante/druid", branch = "stylus_events", features = ["im"] } druid = { version = "0.6.0", features = ["im"] }
im = { version = "*" } im = { version = "*" }
[patch.crates-io]
druid = { git = "https://github.com/doppioandante/druid", branch = "stylus_events_0.6.0", features = ["im"] }
[dependencies.gtk] [dependencies.gtk]
version = "0.9.2" version = "0.8.1"
features = ["v3_22"] features = ["v3_22"]
[dependencies.gio] [dependencies.gio]
version = "" version = "0.8.1"
features = ["v2_56"] features = ["v2_56"]
[dependencies.gdk] [dependencies.gdk]
version = "" version = "0.12.1"
features = ["v3_22"] features = ["v3_22"]

View File

@ -5,24 +5,23 @@ pub struct Path {
#[derive(Clone, druid::Data)] #[derive(Clone, druid::Data)]
pub enum CanvasElement { pub enum CanvasElement {
Freehand { Freehand { path: Path, thickness: f64 },
path: Path,
thickness: f64,
}
} }
impl CanvasElement { impl CanvasElement {
pub fn bounding_box(&self) -> druid::Rect { pub fn bounding_box(&self) -> druid::Rect {
match self { match self {
CanvasElement::Freehand{ path, thickness } => { CanvasElement::Freehand { path, thickness } => {
use druid::kurbo::Shape; use druid::kurbo::Shape;
path.kurbo_path.bounding_box().inflate(*thickness, *thickness) path.kurbo_path
.bounding_box()
.inflate(*thickness, *thickness)
} }
} }
} }
pub fn draw(&self, ctx: &mut druid::PaintCtx) { pub fn draw(&self, ctx: &mut druid::PaintCtx) {
match self { match self {
CanvasElement::Freehand{ path, thickness } => { CanvasElement::Freehand { path, thickness } => {
use druid::RenderContext; use druid::RenderContext;
let stroke_color = druid::Color::rgb8(0, 128, 0); let stroke_color = druid::Color::rgb8(0, 128, 0);
ctx.stroke(&path.kurbo_path, &stroke_color, *thickness); ctx.stroke(&path.kurbo_path, &stroke_color, *thickness);
@ -32,7 +31,9 @@ impl CanvasElement {
pub fn get_path_mut(&mut self) -> Option<&mut Path> { pub fn get_path_mut(&mut self) -> Option<&mut Path> {
match self { match self {
CanvasElement::Freehand{ path, .. } => Some(path), CanvasElement::Freehand { path, .. } => Some(path),
} }
} }
} }

View File

@ -41,7 +41,7 @@ impl Widget<CanvasData> for CanvasWidget {
Event::MouseDown(mouse_event) => { Event::MouseDown(mouse_event) => {
let mut kurbo_path = BezPath::new(); let mut kurbo_path = BezPath::new();
kurbo_path.move_to((mouse_event.pos.x, mouse_event.pos.y)); kurbo_path.move_to((mouse_event.pos.x, mouse_event.pos.y));
data.current_element = Some(CanvasElement::Freehand{ data.current_element = Some(CanvasElement::Freehand {
path: stiletto::Path { kurbo_path }, path: stiletto::Path { kurbo_path },
thickness: 2.0, thickness: 2.0,
}); });
@ -117,15 +117,13 @@ impl Widget<CanvasData> for CanvasWidget {
// It goes event -> update -> layout -> paint, and each method can influence the next. // It goes event -> update -> layout -> paint, and each method can influence the next.
// Basically, anything that changes the appearance of a widget causes a paint. // Basically, anything that changes the appearance of a widget causes a paint.
fn paint(&mut self, ctx: &mut PaintCtx, data: &CanvasData, _env: &Env) { fn paint(&mut self, ctx: &mut PaintCtx, data: &CanvasData, _env: &Env) {
// Let's draw a picture with Piet!
// Clear the whole widget with the color of your choice
// (ctx.size() returns the size of the layout rect we're painting in) // (ctx.size() returns the size of the layout rect we're painting in)
let size = ctx.size(); let size = ctx.size();
let rect = size.to_rect(); let rect = size.to_rect();
ctx.fill(rect, &Color::WHITE);
// Note: ctx also has a `clear` method, but that clears the whole context, // Note: ctx also has a `clear` method, but that clears the whole context,
// and we only want to clear this widget's area. // and we only want to clear this widget's area.
ctx.fill(rect, &Color::WHITE);
for element in &data.elements { for element in &data.elements {
element.draw(ctx); element.draw(ctx);
} }
@ -136,14 +134,12 @@ impl Widget<CanvasData> for CanvasWidget {
} }
fn build_ui() -> impl Widget<CanvasData> { fn build_ui() -> impl Widget<CanvasData> {
use druid::widget::{Align, Button, Flex, CrossAxisAlignment, SizedBox}; use druid::widget::{Align, Button, CrossAxisAlignment, Flex, SizedBox};
let toolbar = Flex::row() let toolbar = Flex::row()
.cross_axis_alignment(CrossAxisAlignment::Center) .cross_axis_alignment(CrossAxisAlignment::Center)
.with_spacer(30.0) .with_spacer(30.0)
.with_child( .with_child(Button::new("Undo"))
Button::new("Undo")) .with_child(Button::new("Redo"));
.with_child(
Button::new("Redo"));
Flex::column() Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Center) .cross_axis_alignment(CrossAxisAlignment::Center)