From 44f244fb5f961ae960e67f02dcbe506868fefb39 Mon Sep 17 00:00:00 2001 From: Henry Sloan Date: Mon, 23 Aug 2021 21:55:59 -0400 Subject: [PATCH] Add a stroke width option to the Line Tool (#355) * Add a stroke width option to the Line Tool * Fix title case for line options * Add px unit to line stroke width * Add stroke width to pen tool * Rename stroke width to weight * Change number input width to min-width * Remove the word "stroke" from "stroke weight" --- editor/src/tool/tool_options.rs | 2 ++ editor/src/tool/tools/line.rs | 10 ++++++++-- editor/src/tool/tools/pen.rs | 10 ++++++++-- .../src/components/widgets/inputs/NumberInput.vue | 5 +++-- .../src/components/widgets/options/ToolOptions.vue | 14 ++++++++++++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/editor/src/tool/tool_options.rs b/editor/src/tool/tool_options.rs index 7fbc5e76..03da9a0d 100644 --- a/editor/src/tool/tool_options.rs +++ b/editor/src/tool/tool_options.rs @@ -5,6 +5,8 @@ pub enum ToolOptions { Select { append_mode: SelectAppendMode }, Ellipse, Shape { shape_type: ShapeType }, + Line { weight: u32 }, + Pen { weight: u32 }, } #[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash)] diff --git a/editor/src/tool/tools/line.rs b/editor/src/tool/tools/line.rs index 00a3785f..6cc6224f 100644 --- a/editor/src/tool/tools/line.rs +++ b/editor/src/tool/tools/line.rs @@ -1,7 +1,7 @@ use crate::consts::LINE_ROTATE_SNAP_ANGLE; use crate::input::keyboard::Key; use crate::input::{mouse::ViewportPosition, InputPreprocessor}; -use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData}; +use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData, ToolOptions, ToolType}; use crate::{document::DocumentMessageHandler, message_prelude::*}; use glam::{DAffine2, DVec2}; use graphene::{layers::style, Operation}; @@ -50,6 +50,7 @@ struct LineToolData { drag_start: ViewportPosition, drag_current: ViewportPosition, angle: f64, + weight: u32, path: Option>, } @@ -75,12 +76,17 @@ impl Fsm for LineToolFsmState { data.path = Some(vec![generate_uuid()]); responses.push_back(DocumentMessage::DeselectAllLayers.into()); + data.weight = match tool_data.tool_options.get(&ToolType::Line) { + Some(&ToolOptions::Line { weight }) => weight, + _ => 5, + }; + responses.push_back( Operation::AddLine { path: data.path.clone().unwrap(), insert_index: -1, transform: DAffine2::ZERO.to_cols_array(), - style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), None), + style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), None), } .into(), ); diff --git a/editor/src/tool/tools/pen.rs b/editor/src/tool/tools/pen.rs index 991c36e7..ffd64417 100644 --- a/editor/src/tool/tools/pen.rs +++ b/editor/src/tool/tools/pen.rs @@ -1,5 +1,5 @@ use crate::input::InputPreprocessor; -use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData}; +use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData, ToolOptions, ToolType}; use crate::{document::DocumentMessageHandler, message_prelude::*}; use glam::DAffine2; use graphene::{layers::style, Operation}; @@ -49,6 +49,7 @@ impl Default for PenToolFsmState { struct PenToolData { points: Vec, next_point: DAffine2, + weight: u32, path: Option>, } @@ -79,6 +80,11 @@ impl Fsm for PenToolFsmState { data.points.push(pos); data.next_point = pos; + data.weight = match tool_data.tool_options.get(&ToolType::Pen) { + Some(&ToolOptions::Pen { weight }) => weight, + _ => 5, + }; + Dragging } (Dragging, DragStop) => { @@ -140,7 +146,7 @@ fn make_operation(data: &PenToolData, tool_data: &DocumentToolData, show_preview insert_index: -1, transform: DAffine2::IDENTITY.to_cols_array(), points, - style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), Some(style::Fill::none())), + style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), Some(style::Fill::none())), } .into(), ] diff --git a/frontend/src/components/widgets/inputs/NumberInput.vue b/frontend/src/components/widgets/inputs/NumberInput.vue index e708bd05..15ace8a0 100644 --- a/frontend/src/components/widgets/inputs/NumberInput.vue +++ b/frontend/src/components/widgets/inputs/NumberInput.vue @@ -19,7 +19,7 @@