Skip to content

Commit e0d9d46

Browse files
committed
Change stroke weight from ints to floats (#601)
Also rename stroke "width" to "weight" in some places. Closes #587 * Change stroke weight from ints to floats * "miter_limit" -> "line_join_miter_limit" * Bump file format version
1 parent afa1d72 commit e0d9d46

File tree

10 files changed

+74
-74
lines changed

10 files changed

+74
-74
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"graphene_document":{"font_cache": {"data":{},"default":null}, "root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":919378319526168453,"layer_ids":[919378319526168452],"layers":[{"visible":true,"name":null,"data":{"Shape":{"path":[{"MoveTo":{"x":0.0,"y":0.0}},{"LineTo":{"x":1.0,"y":0.0}},{"LineTo":{"x":1.0,"y":1.0}},{"LineTo":{"x":0.0,"y":1.0}},"ClosePath"],"style":{"stroke":null,"fill":{"Solid":{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0}}},"render_index":1,"closed":true}},"transform":{"matrix2":[303.890625,0.0,-0.0,362.10546875],"translation":[-148.83984375,-235.8828125]},"blend_mode":"Normal","opacity":1.0}]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"saved_document_identifier":0,"name":"Untitled Document","layer_metadata":[[[919378319526168452],{"selected":true,"expanded":false}],[[],{"selected":false,"expanded":true}]],"layer_range_selection_reference":[919378319526168452],"movement_handler":{"pan":[-118.8,-45.60000000000001],"panning":false,"snap_tilt":false,"snap_tilt_released":false,"tilt":0.0,"tilting":false,"zoom":1.0,"zooming":false,"snap_zoom":false,"mouse_position":[0.0,0.0]},"artboard_message_handler":{"artboards_graphene_document":{"font_cache": {"data": {}}, "root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":0,"layer_ids":[],"layers":[]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"artboard_ids":[]},"properties_panel_message_handler":{"active_selection":[[919378319526168452],"Artwork"]},"overlays_visible":true,"snapping_enabled":true,"view_mode":"Normal","version":"0.0.6"}
1+
{"graphene_document":{"font_cache": {"data":{},"default":null}, "root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":919378319526168453,"layer_ids":[919378319526168452],"layers":[{"visible":true,"name":null,"data":{"Shape":{"path":[{"MoveTo":{"x":0.0,"y":0.0}},{"LineTo":{"x":1.0,"y":0.0}},{"LineTo":{"x":1.0,"y":1.0}},{"LineTo":{"x":0.0,"y":1.0}},"ClosePath"],"style":{"stroke":null,"fill":{"Solid":{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0}}},"render_index":1,"closed":true}},"transform":{"matrix2":[303.890625,0.0,-0.0,362.10546875],"translation":[-148.83984375,-235.8828125]},"blend_mode":"Normal","opacity":1.0}]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"saved_document_identifier":0,"name":"Untitled Document","layer_metadata":[[[919378319526168452],{"selected":true,"expanded":false}],[[],{"selected":false,"expanded":true}]],"layer_range_selection_reference":[919378319526168452],"movement_handler":{"pan":[-118.8,-45.60000000000001],"panning":false,"snap_tilt":false,"snap_tilt_released":false,"tilt":0.0,"tilting":false,"zoom":1.0,"zooming":false,"snap_zoom":false,"mouse_position":[0.0,0.0]},"artboard_message_handler":{"artboards_graphene_document":{"font_cache": {"data": {}}, "root":{"visible":true,"name":null,"data":{"Folder":{"next_assignment_id":0,"layer_ids":[],"layers":[]}},"transform":{"matrix2":[1.0,0.0,0.0,1.0],"translation":[259.88359375,366.9]},"blend_mode":"Normal","opacity":1.0}},"artboard_ids":[]},"properties_panel_message_handler":{"active_selection":[[919378319526168452],"Artwork"]},"overlays_visible":true,"snapping_enabled":true,"view_mode":"Normal","version":"0.0.7"}

editor/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ pub const FILE_EXPORT_SUFFIX: &str = ".svg";
5757
pub const COLOR_ACCENT: Color = Color::from_unsafe(0x00 as f32 / 255., 0xA8 as f32 / 255., 0xFF as f32 / 255.);
5858

5959
// Document
60-
pub const GRAPHITE_DOCUMENT_VERSION: &str = "0.0.6";
60+
pub const GRAPHITE_DOCUMENT_VERSION: &str = "0.0.7";
6161
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f32 = 1.05;

editor/src/document/properties_panel_message_handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,13 @@ fn node_section_stroke(stroke: &Stroke) -> LayoutRow {
952952
direction: SeparatorDirection::Horizontal,
953953
})),
954954
WidgetHolder::new(Widget::NumberInput(NumberInput {
955-
value: stroke.width() as f64,
956-
is_integer: true,
955+
value: stroke.weight() as f64,
956+
is_integer: false,
957957
min: Some(0.),
958958
unit: " px".into(),
959959
on_update: WidgetCallback::new(move |number_input: &NumberInput| {
960960
PropertiesPanelMessage::ModifyStroke {
961-
stroke: internal_stroke2.clone().with_width(number_input.value as f32),
961+
stroke: internal_stroke2.clone().with_weight(number_input.value),
962962
}
963963
.into()
964964
}),
@@ -1004,7 +1004,7 @@ fn node_section_stroke(stroke: &Stroke) -> LayoutRow {
10041004
unit: " px".into(),
10051005
on_update: WidgetCallback::new(move |number_input: &NumberInput| {
10061006
PropertiesPanelMessage::ModifyStroke {
1007-
stroke: internal_stroke4.clone().with_dash_offset(number_input.value as f32),
1007+
stroke: internal_stroke4.clone().with_dash_offset(number_input.value),
10081008
}
10091009
.into()
10101010
}),
@@ -1118,13 +1118,13 @@ fn node_section_stroke(stroke: &Stroke) -> LayoutRow {
11181118
direction: SeparatorDirection::Horizontal,
11191119
})),
11201120
WidgetHolder::new(Widget::NumberInput(NumberInput {
1121-
value: stroke.miter_limit() as f64,
1121+
value: stroke.line_join_miter_limit() as f64,
11221122
is_integer: true,
11231123
min: Some(0.),
11241124
unit: "".into(),
11251125
on_update: WidgetCallback::new(move |number_input: &NumberInput| {
11261126
PropertiesPanelMessage::ModifyStroke {
1127-
stroke: internal_stroke5.clone().with_miter_limit(number_input.value as f32),
1127+
stroke: internal_stroke5.clone().with_line_join_miter_limit(number_input.value),
11281128
}
11291129
.into()
11301130
}),

editor/src/viewport_tools/tools/freehand_tool.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ pub struct FreehandTool {
2121
}
2222

2323
pub struct FreehandOptions {
24-
line_weight: u32,
24+
line_weight: f64,
2525
}
2626

2727
impl Default for FreehandOptions {
2828
fn default() -> Self {
29-
Self { line_weight: 5 }
29+
Self { line_weight: 5. }
3030
}
3131
}
3232

3333
#[remain::sorted]
3434
#[impl_message(Message, ToolMessage, Freehand)]
35-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
35+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
3636
pub enum FreehandToolMessage {
3737
// Standard messages
3838
#[remain::unsorted]
@@ -46,9 +46,9 @@ pub enum FreehandToolMessage {
4646
}
4747

4848
#[remain::sorted]
49-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
49+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
5050
pub enum FreehandToolMessageOptionsUpdate {
51-
LineWeight(u32),
51+
LineWeight(f64),
5252
}
5353

5454
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -64,9 +64,9 @@ impl PropertyHolder for FreehandTool {
6464
unit: " px".into(),
6565
label: "Weight".into(),
6666
value: self.options.line_weight as f64,
67-
is_integer: true,
67+
is_integer: false,
6868
min: Some(1.),
69-
on_update: WidgetCallback::new(|number_input: &NumberInput| FreehandToolMessage::UpdateOptions(FreehandToolMessageOptionsUpdate::LineWeight(number_input.value as u32)).into()),
69+
on_update: WidgetCallback::new(|number_input: &NumberInput| FreehandToolMessage::UpdateOptions(FreehandToolMessageOptionsUpdate::LineWeight(number_input.value)).into()),
7070
..NumberInput::default()
7171
}))],
7272
}])
@@ -119,7 +119,7 @@ impl Default for FreehandToolFsmState {
119119
#[derive(Clone, Debug, Default)]
120120
struct FreehandToolData {
121121
points: Vec<DVec2>,
122-
weight: u32,
122+
weight: f64,
123123
path: Option<Vec<LayerId>>,
124124
}
125125

@@ -224,7 +224,7 @@ fn add_polyline(data: &FreehandToolData, tool_data: &DocumentToolData) -> Messag
224224
insert_index: -1,
225225
transform: DAffine2::IDENTITY.to_cols_array(),
226226
points,
227-
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), style::Fill::None),
227+
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight)), style::Fill::None),
228228
}
229229
.into()
230230
}

editor/src/viewport_tools/tools/line_tool.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ pub struct LineTool {
2424
}
2525

2626
pub struct LineOptions {
27-
line_weight: u32,
27+
line_weight: f64,
2828
}
2929

3030
impl Default for LineOptions {
3131
fn default() -> Self {
32-
Self { line_weight: 5 }
32+
Self { line_weight: 5. }
3333
}
3434
}
3535

3636
#[remain::sorted]
3737
#[impl_message(Message, ToolMessage, Line)]
38-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
38+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
3939
pub enum LineToolMessage {
4040
// Standard messages
4141
#[remain::unsorted]
@@ -53,9 +53,9 @@ pub enum LineToolMessage {
5353
}
5454

5555
#[remain::sorted]
56-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
56+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
5757
pub enum LineOptionsUpdate {
58-
LineWeight(u32),
58+
LineWeight(f64),
5959
}
6060

6161
impl PropertyHolder for LineTool {
@@ -65,9 +65,9 @@ impl PropertyHolder for LineTool {
6565
unit: " px".into(),
6666
label: "Weight".into(),
6767
value: self.options.line_weight as f64,
68-
is_integer: true,
68+
is_integer: false,
6969
min: Some(0.),
70-
on_update: WidgetCallback::new(|number_input: &NumberInput| LineToolMessage::UpdateOptions(LineOptionsUpdate::LineWeight(number_input.value as u32)).into()),
70+
on_update: WidgetCallback::new(|number_input: &NumberInput| LineToolMessage::UpdateOptions(LineOptionsUpdate::LineWeight(number_input.value)).into()),
7171
..NumberInput::default()
7272
}))],
7373
}])
@@ -129,7 +129,7 @@ struct LineToolData {
129129
drag_start: ViewportPosition,
130130
drag_current: ViewportPosition,
131131
angle: f64,
132-
weight: u32,
132+
weight: f64,
133133
path: Option<Vec<LayerId>>,
134134
snap_handler: SnapHandler,
135135
}
@@ -168,7 +168,7 @@ impl Fsm for LineToolFsmState {
168168
path: data.path.clone().unwrap(),
169169
insert_index: -1,
170170
transform: DAffine2::ZERO.to_cols_array(),
171-
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), style::Fill::None),
171+
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight)), style::Fill::None),
172172
}
173173
.into(),
174174
);

editor/src/viewport_tools/tools/pen_tool.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ pub struct PenTool {
2727
}
2828

2929
pub struct PenOptions {
30-
line_weight: u32,
30+
line_weight: f64,
3131
}
3232

3333
impl Default for PenOptions {
3434
fn default() -> Self {
35-
Self { line_weight: 5 }
35+
Self { line_weight: 5. }
3636
}
3737
}
3838

3939
#[remain::sorted]
4040
#[impl_message(Message, ToolMessage, Pen)]
41-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
41+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
4242
pub enum PenToolMessage {
4343
// Standard messages
4444
#[remain::unsorted]
@@ -62,9 +62,9 @@ enum PenToolFsmState {
6262
}
6363

6464
#[remain::sorted]
65-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
65+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
6666
pub enum PenOptionsUpdate {
67-
LineWeight(u32),
67+
LineWeight(f64),
6868
}
6969

7070
impl PropertyHolder for PenTool {
@@ -73,10 +73,10 @@ impl PropertyHolder for PenTool {
7373
widgets: vec![WidgetHolder::new(Widget::NumberInput(NumberInput {
7474
unit: " px".into(),
7575
label: "Weight".into(),
76-
value: self.options.line_weight as f64,
77-
is_integer: true,
76+
value: self.options.line_weight,
77+
is_integer: false,
7878
min: Some(0.),
79-
on_update: WidgetCallback::new(|number_input: &NumberInput| PenToolMessage::UpdateOptions(PenOptionsUpdate::LineWeight(number_input.value as u32)).into()),
79+
on_update: WidgetCallback::new(|number_input: &NumberInput| PenToolMessage::UpdateOptions(PenOptionsUpdate::LineWeight(number_input.value)).into()),
8080
..NumberInput::default()
8181
}))],
8282
}])
@@ -128,7 +128,7 @@ impl Default for PenToolFsmState {
128128
}
129129
#[derive(Clone, Debug, Default)]
130130
struct PenToolData {
131-
weight: u32,
131+
weight: f64,
132132
path: Option<Vec<LayerId>>,
133133
curve_shape: VectorShape,
134134
bez_path: Vec<PathEl>,
@@ -184,7 +184,7 @@ impl Fsm for PenToolFsmState {
184184
transform: transform.to_cols_array(),
185185
insert_index: -1,
186186
bez_path: data.bez_path.clone().into_iter().collect(),
187-
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), style::Fill::None),
187+
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight)), style::Fill::None),
188188
closed: false,
189189
}
190190
.into(),

editor/src/viewport_tools/tools/spline_tool.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ pub struct SplineTool {
2323
}
2424

2525
pub struct SplineOptions {
26-
line_weight: u32,
26+
line_weight: f64,
2727
}
2828

2929
impl Default for SplineOptions {
3030
fn default() -> Self {
31-
Self { line_weight: 5 }
31+
Self { line_weight: 5. }
3232
}
3333
}
3434

3535
#[remain::sorted]
3636
#[impl_message(Message, ToolMessage, Spline)]
37-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
37+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
3838
pub enum SplineToolMessage {
3939
// Standard messages
4040
#[remain::unsorted]
@@ -56,9 +56,9 @@ enum SplineToolFsmState {
5656
}
5757

5858
#[remain::sorted]
59-
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
59+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
6060
pub enum SplineOptionsUpdate {
61-
LineWeight(u32),
61+
LineWeight(f64),
6262
}
6363

6464
impl PropertyHolder for SplineTool {
@@ -67,10 +67,10 @@ impl PropertyHolder for SplineTool {
6767
widgets: vec![WidgetHolder::new(Widget::NumberInput(NumberInput {
6868
unit: " px".into(),
6969
label: "Weight".into(),
70-
value: self.options.line_weight as f64,
71-
is_integer: true,
70+
value: self.options.line_weight,
71+
is_integer: false,
7272
min: Some(0.),
73-
on_update: WidgetCallback::new(|number_input: &NumberInput| SplineToolMessage::UpdateOptions(SplineOptionsUpdate::LineWeight(number_input.value as u32)).into()),
73+
on_update: WidgetCallback::new(|number_input: &NumberInput| SplineToolMessage::UpdateOptions(SplineOptionsUpdate::LineWeight(number_input.value)).into()),
7474
..NumberInput::default()
7575
}))],
7676
}])
@@ -124,7 +124,7 @@ impl Default for SplineToolFsmState {
124124
struct SplineToolData {
125125
points: Vec<DVec2>,
126126
next_point: DVec2,
127-
weight: u32,
127+
weight: f64,
128128
path: Option<Vec<LayerId>>,
129129
snap_handler: SnapHandler,
130130
}
@@ -265,7 +265,7 @@ fn add_spline(data: &SplineToolData, tool_data: &DocumentToolData, show_preview:
265265
insert_index: -1,
266266
transform: DAffine2::IDENTITY.to_cols_array(),
267267
points,
268-
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight as f32)), style::Fill::None),
268+
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, data.weight)), style::Fill::None),
269269
}
270270
.into()
271271
}

editor/src/viewport_tools/vector_editor/vector_control_point.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ impl Default for VectorControlPoint {
4343
}
4444
}
4545

46-
const POINT_STROKE_WIDTH: f32 = 2.0;
46+
const POINT_STROKE_WEIGHT: f64 = 2.;
4747

4848
impl VectorControlPoint {
4949
/// Sets if this point is selected and updates the overlay to represent that
5050
pub fn set_selected(&mut self, selected: bool, responses: &mut VecDeque<Message>) {
5151
if selected {
52-
self.set_overlay_style(POINT_STROKE_WIDTH + 1.0, COLOR_ACCENT, COLOR_ACCENT, responses);
52+
self.set_overlay_style(POINT_STROKE_WEIGHT + 1., COLOR_ACCENT, COLOR_ACCENT, responses);
5353
} else {
54-
self.set_overlay_style(POINT_STROKE_WIDTH, COLOR_ACCENT, Color::WHITE, responses);
54+
self.set_overlay_style(POINT_STROKE_WEIGHT, COLOR_ACCENT, Color::WHITE, responses);
5555
}
5656
self.is_selected = selected;
5757
}
5858

5959
/// Sets the overlay style for this point
60-
pub fn set_overlay_style(&self, stroke_width: f32, stroke_color: Color, fill_color: Color, responses: &mut VecDeque<Message>) {
60+
pub fn set_overlay_style(&self, stroke_weight: f64, stroke_color: Color, fill_color: Color, responses: &mut VecDeque<Message>) {
6161
if let Some(overlay_path) = &self.overlay_path {
6262
responses.push_back(
6363
DocumentMessage::Overlays(
6464
Operation::SetLayerStyle {
6565
path: overlay_path.clone(),
66-
style: PathStyle::new(Some(Stroke::new(stroke_color, stroke_width)), Fill::solid(fill_color)),
66+
style: PathStyle::new(Some(Stroke::new(stroke_color, stroke_weight)), Fill::solid(fill_color)),
6767
}
6868
.into(),
6969
)

graphene/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::color::Color;
22

33
// RENDERING
44
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
5-
pub const LAYER_OUTLINE_STROKE_WIDTH: f32 = 1.;
5+
pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 1.;
66

77
// BOOLEAN OPERATIONS
88

0 commit comments

Comments
 (0)