@@ -13,17 +13,16 @@ fn convert_error(err: editor::EditorError) -> JsValue {
13
13
Error :: new ( & err. to_string ( ) ) . into ( )
14
14
}
15
15
16
- fn dispatch < T : Into < Message > > ( message : T ) -> Result < ( ) , JsValue > {
16
+ fn dispatch < T : Into < Message > > ( message : T ) {
17
17
let messages = crate :: EDITOR_STATE . with ( |state| state. borrow_mut ( ) . handle_message ( message. into ( ) ) ) ;
18
18
crate :: handle_responses ( messages) ;
19
- Ok ( ( ) ) // TODO
20
19
}
21
20
22
21
/// Modify the currently selected tool in the document state store
23
22
#[ wasm_bindgen]
24
23
pub fn select_tool ( tool : String ) -> Result < ( ) , JsValue > {
25
24
match translate_tool ( & tool) {
26
- Some ( tool) => dispatch ( ToolMessage :: ActivateTool ( tool) ) ,
25
+ Some ( tool) => Ok ( dispatch ( ToolMessage :: ActivateTool ( tool) ) ) ,
27
26
None => Err ( Error :: new ( & format ! ( "Couldn't select {} because it was not recognized as a valid tool" , tool) ) . into ( ) ) ,
28
27
}
29
28
}
@@ -33,7 +32,7 @@ pub fn select_tool(tool: String) -> Result<(), JsValue> {
33
32
pub fn set_tool_options ( tool : String , options : & JsValue ) -> Result < ( ) , JsValue > {
34
33
match options. into_serde :: < ToolOptions > ( ) {
35
34
Ok ( options) => match translate_tool ( & tool) {
36
- Some ( tool) => dispatch ( ToolMessage :: SetToolOptions ( tool, options) ) ,
35
+ Some ( tool) => Ok ( dispatch ( ToolMessage :: SetToolOptions ( tool, options) ) ) ,
37
36
None => Err ( Error :: new ( & format ! ( "Couldn't set options for {} because it was not recognized as a valid tool" , tool) ) . into ( ) ) ,
38
37
} ,
39
38
Err ( err) => Err ( Error :: new ( & format ! ( "Invalid JSON for ToolOptions: {}" , err) ) . into ( ) ) ,
@@ -54,73 +53,73 @@ pub fn send_tool_message(tool: String, message: &JsValue) -> Result<(), JsValue>
54
53
None => Err ( Error :: new ( & format ! ( "Couldn't send message for {} because it was not recognized as a valid tool" , tool) ) . into ( ) ) ,
55
54
} ;
56
55
match tool_message {
57
- Ok ( tool_message) => dispatch ( tool_message) ,
56
+ Ok ( tool_message) => Ok ( dispatch ( tool_message) ) ,
58
57
Err ( err) => Err ( err) ,
59
58
}
60
59
}
61
60
62
61
#[ wasm_bindgen]
63
- pub fn select_document ( document : usize ) -> Result < ( ) , JsValue > {
62
+ pub fn select_document ( document : usize ) {
64
63
dispatch ( DocumentsMessage :: SelectDocument ( document) )
65
64
}
66
65
67
66
#[ wasm_bindgen]
68
- pub fn get_open_documents_list ( ) -> Result < ( ) , JsValue > {
67
+ pub fn get_open_documents_list ( ) {
69
68
dispatch ( DocumentsMessage :: GetOpenDocumentsList )
70
69
}
71
70
72
71
#[ wasm_bindgen]
73
- pub fn new_document ( ) -> Result < ( ) , JsValue > {
72
+ pub fn new_document ( ) {
74
73
dispatch ( DocumentsMessage :: NewDocument )
75
74
}
76
75
77
76
#[ wasm_bindgen]
78
- pub fn open_document ( ) -> Result < ( ) , JsValue > {
77
+ pub fn open_document ( ) {
79
78
dispatch ( DocumentsMessage :: OpenDocument )
80
79
}
81
80
82
81
#[ wasm_bindgen]
83
- pub fn open_document_file ( name : String , content : String ) -> Result < ( ) , JsValue > {
82
+ pub fn open_document_file ( name : String , content : String ) {
84
83
dispatch ( DocumentsMessage :: OpenDocumentFile ( name, content) )
85
84
}
86
85
87
86
#[ wasm_bindgen]
88
- pub fn save_document ( ) -> Result < ( ) , JsValue > {
87
+ pub fn save_document ( ) {
89
88
dispatch ( DocumentMessage :: SaveDocument )
90
89
}
91
90
92
91
#[ wasm_bindgen]
93
- pub fn close_document ( document : usize ) -> Result < ( ) , JsValue > {
92
+ pub fn close_document ( document : usize ) {
94
93
dispatch ( DocumentsMessage :: CloseDocument ( document) )
95
94
}
96
95
97
96
#[ wasm_bindgen]
98
- pub fn close_all_documents ( ) -> Result < ( ) , JsValue > {
97
+ pub fn close_all_documents ( ) {
99
98
dispatch ( DocumentsMessage :: CloseAllDocuments )
100
99
}
101
100
102
101
#[ wasm_bindgen]
103
- pub fn close_active_document_with_confirmation ( ) -> Result < ( ) , JsValue > {
102
+ pub fn close_active_document_with_confirmation ( ) {
104
103
dispatch ( DocumentsMessage :: CloseActiveDocumentWithConfirmation )
105
104
}
106
105
107
106
#[ wasm_bindgen]
108
- pub fn close_all_documents_with_confirmation ( ) -> Result < ( ) , JsValue > {
107
+ pub fn close_all_documents_with_confirmation ( ) {
109
108
dispatch ( DocumentsMessage :: CloseAllDocumentsWithConfirmation )
110
109
}
111
110
112
111
/// Send new bounds when document panel viewports get resized or moved within the editor
113
112
/// [left, top, right, bottom]...
114
113
#[ wasm_bindgen]
115
- pub fn bounds_of_viewports ( bounds_of_viewports : & [ f64 ] ) -> Result < ( ) , JsValue > {
114
+ pub fn bounds_of_viewports ( bounds_of_viewports : & [ f64 ] ) {
116
115
let chunked: Vec < _ > = bounds_of_viewports. chunks ( 4 ) . map ( ViewportBounds :: from_slice) . collect ( ) ;
117
116
let ev = InputPreprocessorMessage :: BoundsOfViewports ( chunked) ;
118
117
dispatch ( ev)
119
118
}
120
119
121
120
/// Mouse movement within the screenspace bounds of the viewport
122
121
#[ wasm_bindgen]
123
- pub fn on_mouse_move ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) -> Result < ( ) , JsValue > {
122
+ pub fn on_mouse_move ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) {
124
123
let editor_mouse_state = EditorMouseState :: from_keys_and_editor_position ( mouse_keys, ( x, y) . into ( ) ) ;
125
124
126
125
let modifier_keys = ModifierKeys :: from_bits ( modifiers) . expect ( "invalid modifier keys" ) ;
@@ -131,7 +130,7 @@ pub fn on_mouse_move(x: f64, y: f64, mouse_keys: u8, modifiers: u8) -> Result<()
131
130
132
131
/// Mouse scrolling within the screenspace bounds of the viewport
133
132
#[ wasm_bindgen]
134
- pub fn on_mouse_scroll ( x : f64 , y : f64 , mouse_keys : u8 , wheel_delta_x : i32 , wheel_delta_y : i32 , wheel_delta_z : i32 , modifiers : u8 ) -> Result < ( ) , JsValue > {
133
+ pub fn on_mouse_scroll ( x : f64 , y : f64 , mouse_keys : u8 , wheel_delta_x : i32 , wheel_delta_y : i32 , wheel_delta_z : i32 , modifiers : u8 ) {
135
134
let mut editor_mouse_state = EditorMouseState :: from_keys_and_editor_position ( mouse_keys, ( x, y) . into ( ) ) ;
136
135
editor_mouse_state. scroll_delta = ScrollDelta :: new ( wheel_delta_x, wheel_delta_y, wheel_delta_z) ;
137
136
@@ -143,7 +142,7 @@ pub fn on_mouse_scroll(x: f64, y: f64, mouse_keys: u8, wheel_delta_x: i32, wheel
143
142
144
143
/// A mouse button depressed within screenspace the bounds of the viewport
145
144
#[ wasm_bindgen]
146
- pub fn on_mouse_down ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) -> Result < ( ) , JsValue > {
145
+ pub fn on_mouse_down ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) {
147
146
let editor_mouse_state = EditorMouseState :: from_keys_and_editor_position ( mouse_keys, ( x, y) . into ( ) ) ;
148
147
149
148
let modifier_keys = ModifierKeys :: from_bits ( modifiers) . expect ( "invalid modifier keys" ) ;
@@ -154,7 +153,7 @@ pub fn on_mouse_down(x: f64, y: f64, mouse_keys: u8, modifiers: u8) -> Result<()
154
153
155
154
/// A mouse button released
156
155
#[ wasm_bindgen]
157
- pub fn on_mouse_up ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) -> Result < ( ) , JsValue > {
156
+ pub fn on_mouse_up ( x : f64 , y : f64 , mouse_keys : u8 , modifiers : u8 ) {
158
157
let editor_mouse_state = EditorMouseState :: from_keys_and_editor_position ( mouse_keys, ( x, y) . into ( ) ) ;
159
158
160
159
let modifier_keys = ModifierKeys :: from_bits ( modifiers) . expect ( "invalid modifier keys" ) ;
@@ -165,7 +164,7 @@ pub fn on_mouse_up(x: f64, y: f64, mouse_keys: u8, modifiers: u8) -> Result<(),
165
164
166
165
/// A keyboard button depressed within screenspace the bounds of the viewport
167
166
#[ wasm_bindgen]
168
- pub fn on_key_down ( name : String , modifiers : u8 ) -> Result < ( ) , JsValue > {
167
+ pub fn on_key_down ( name : String , modifiers : u8 ) {
169
168
let key = translate_key ( & name) ;
170
169
let mods = ModifierKeys :: from_bits ( modifiers) . expect ( "invalid modifier keys" ) ;
171
170
log:: trace!( "Key down {:?}, name: {}, modifiers: {:?}" , key, name, mods) ;
@@ -175,7 +174,7 @@ pub fn on_key_down(name: String, modifiers: u8) -> Result<(), JsValue> {
175
174
176
175
/// A keyboard button released
177
176
#[ wasm_bindgen]
178
- pub fn on_key_up ( name : String , modifiers : u8 ) -> Result < ( ) , JsValue > {
177
+ pub fn on_key_up ( name : String , modifiers : u8 ) {
179
178
let key = translate_key ( & name) ;
180
179
let mods = ModifierKeys :: from_bits ( modifiers) . expect ( "invalid modifier keys" ) ;
181
180
log:: trace!( "Key up {:?}, name: {}, modifiers: {:?}" , key, name, mods) ;
@@ -185,55 +184,55 @@ pub fn on_key_up(name: String, modifiers: u8) -> Result<(), JsValue> {
185
184
186
185
/// Update primary color
187
186
#[ wasm_bindgen]
188
- pub fn update_primary_color ( primary_color : Color ) -> Result < ( ) , JsValue > {
187
+ pub fn update_primary_color ( primary_color : Color ) {
189
188
dispatch ( ToolMessage :: SelectPrimaryColor ( primary_color. inner ( ) ) )
190
189
}
191
190
192
191
/// Update secondary color
193
192
#[ wasm_bindgen]
194
- pub fn update_secondary_color ( secondary_color : Color ) -> Result < ( ) , JsValue > {
193
+ pub fn update_secondary_color ( secondary_color : Color ) {
195
194
dispatch ( ToolMessage :: SelectSecondaryColor ( secondary_color. inner ( ) ) )
196
195
}
197
196
198
197
/// Swap primary and secondary color
199
198
#[ wasm_bindgen]
200
- pub fn swap_colors ( ) -> Result < ( ) , JsValue > {
199
+ pub fn swap_colors ( ) {
201
200
dispatch ( ToolMessage :: SwapColors )
202
201
}
203
202
204
203
/// Reset primary and secondary colors to their defaults
205
204
#[ wasm_bindgen]
206
- pub fn reset_colors ( ) -> Result < ( ) , JsValue > {
205
+ pub fn reset_colors ( ) {
207
206
dispatch ( ToolMessage :: ResetColors )
208
207
}
209
208
210
209
/// Undo history one step
211
210
#[ wasm_bindgen]
212
- pub fn undo ( ) -> Result < ( ) , JsValue > {
211
+ pub fn undo ( ) {
213
212
dispatch ( DocumentMessage :: Undo )
214
213
}
215
214
216
215
/// Redo history one step
217
216
#[ wasm_bindgen]
218
- pub fn redo ( ) -> Result < ( ) , JsValue > {
217
+ pub fn redo ( ) {
219
218
dispatch ( DocumentMessage :: Redo )
220
219
}
221
220
222
221
/// Select all layers
223
222
#[ wasm_bindgen]
224
- pub fn select_all_layers ( ) -> Result < ( ) , JsValue > {
223
+ pub fn select_all_layers ( ) {
225
224
dispatch ( DocumentMessage :: SelectAllLayers )
226
225
}
227
226
228
227
/// Deselect all layers
229
228
#[ wasm_bindgen]
230
- pub fn deselect_all_layers ( ) -> Result < ( ) , JsValue > {
229
+ pub fn deselect_all_layers ( ) {
231
230
dispatch ( DocumentMessage :: DeselectAllLayers )
232
231
}
233
232
234
233
/// Reorder selected layer
235
234
#[ wasm_bindgen]
236
- pub fn reorder_selected_layers ( delta : i32 ) -> Result < ( ) , JsValue > {
235
+ pub fn reorder_selected_layers ( delta : i32 ) {
237
236
dispatch ( DocumentMessage :: ReorderSelectedLayers ( delta) )
238
237
}
239
238
@@ -260,96 +259,96 @@ pub fn set_blend_mode_for_selected_layers(blend_mode_svg_style_name: String) ->
260
259
_ => return Err ( convert_error ( EditorError :: Misc ( "UnknownBlendMode" . to_string ( ) ) ) ) ,
261
260
} ;
262
261
263
- dispatch ( DocumentMessage :: SetBlendModeForSelectedLayers ( blend_mode) )
262
+ Ok ( dispatch ( DocumentMessage :: SetBlendModeForSelectedLayers ( blend_mode) ) )
264
263
}
265
264
266
265
/// Set the opacity for the selected layers
267
266
#[ wasm_bindgen]
268
- pub fn set_opacity_for_selected_layers ( opacity_percent : f64 ) -> Result < ( ) , JsValue > {
267
+ pub fn set_opacity_for_selected_layers ( opacity_percent : f64 ) {
269
268
dispatch ( DocumentMessage :: SetOpacityForSelectedLayers ( opacity_percent / 100. ) )
270
269
}
271
270
272
271
/// Export the document
273
272
#[ wasm_bindgen]
274
- pub fn export_document ( ) -> Result < ( ) , JsValue > {
273
+ pub fn export_document ( ) {
275
274
dispatch ( DocumentMessage :: ExportDocument )
276
275
}
277
276
278
277
/// Sets the zoom to the value
279
278
#[ wasm_bindgen]
280
- pub fn set_canvas_zoom ( new_zoom : f64 ) -> Result < ( ) , JsValue > {
279
+ pub fn set_canvas_zoom ( new_zoom : f64 ) {
281
280
let ev = MovementMessage :: SetCanvasZoom ( new_zoom) ;
282
281
dispatch ( ev)
283
282
}
284
283
285
284
/// Zoom in to the next step
286
285
#[ wasm_bindgen]
287
- pub fn increase_canvas_zoom ( ) -> Result < ( ) , JsValue > {
286
+ pub fn increase_canvas_zoom ( ) {
288
287
let ev = MovementMessage :: IncreaseCanvasZoom ;
289
288
dispatch ( ev)
290
289
}
291
290
292
291
/// Zoom out to the next step
293
292
#[ wasm_bindgen]
294
- pub fn decrease_canvas_zoom ( ) -> Result < ( ) , JsValue > {
293
+ pub fn decrease_canvas_zoom ( ) {
295
294
let ev = MovementMessage :: DecreaseCanvasZoom ;
296
295
dispatch ( ev)
297
296
}
298
297
299
298
/// Sets the rotation to the new value (in radians)
300
299
#[ wasm_bindgen]
301
- pub fn set_rotation ( new_radians : f64 ) -> Result < ( ) , JsValue > {
300
+ pub fn set_rotation ( new_radians : f64 ) {
302
301
let ev = MovementMessage :: SetCanvasRotation ( new_radians) ;
303
302
dispatch ( ev)
304
303
}
305
304
306
305
/// Translates document (in viewport coords)
307
306
#[ wasm_bindgen]
308
- pub fn translate_canvas ( delta_x : f64 , delta_y : f64 ) -> Result < ( ) , JsValue > {
307
+ pub fn translate_canvas ( delta_x : f64 , delta_y : f64 ) {
309
308
let ev = MovementMessage :: TranslateCanvas ( ( delta_x, delta_y) . into ( ) ) ;
310
309
dispatch ( ev)
311
310
}
312
311
313
312
/// Translates document (in viewport coords)
314
313
#[ wasm_bindgen]
315
- pub fn translate_canvas_by_fraction ( delta_x : f64 , delta_y : f64 ) -> Result < ( ) , JsValue > {
314
+ pub fn translate_canvas_by_fraction ( delta_x : f64 , delta_y : f64 ) {
316
315
let ev = MovementMessage :: TranslateCanvasByViewportFraction ( ( delta_x, delta_y) . into ( ) ) ;
317
316
dispatch ( ev)
318
317
}
319
318
320
319
/// Update the list of selected layers. The layer paths have to be stored in one array and are separated by LayerId::MAX
321
320
#[ wasm_bindgen]
322
- pub fn select_layers ( paths : Vec < LayerId > ) -> Result < ( ) , JsValue > {
321
+ pub fn select_layers ( paths : Vec < LayerId > ) {
323
322
let paths = paths. split ( |id| * id == LayerId :: MAX ) . map ( |path| path. to_vec ( ) ) . collect ( ) ;
324
323
dispatch ( DocumentMessage :: SetSelectedLayers ( paths) )
325
324
}
326
325
327
326
/// Toggle visibility of a layer from the layer list
328
327
#[ wasm_bindgen]
329
- pub fn toggle_layer_visibility ( path : Vec < LayerId > ) -> Result < ( ) , JsValue > {
328
+ pub fn toggle_layer_visibility ( path : Vec < LayerId > ) {
330
329
dispatch ( DocumentMessage :: ToggleLayerVisibility ( path) )
331
330
}
332
331
333
332
/// Toggle expansions state of a layer from the layer list
334
333
#[ wasm_bindgen]
335
- pub fn toggle_layer_expansion ( path : Vec < LayerId > ) -> Result < ( ) , JsValue > {
334
+ pub fn toggle_layer_expansion ( path : Vec < LayerId > ) {
336
335
dispatch ( DocumentMessage :: ToggleLayerExpansion ( path) )
337
336
}
338
337
339
338
/// Renames a layer from the layer list
340
339
#[ wasm_bindgen]
341
- pub fn rename_layer ( path : Vec < LayerId > , new_name : String ) -> Result < ( ) , JsValue > {
340
+ pub fn rename_layer ( path : Vec < LayerId > , new_name : String ) {
342
341
dispatch ( DocumentMessage :: RenameLayer ( path, new_name) )
343
342
}
344
343
345
344
/// Deletes a layer from the layer list
346
345
#[ wasm_bindgen]
347
- pub fn delete_layer ( path : Vec < LayerId > ) -> Result < ( ) , JsValue > {
346
+ pub fn delete_layer ( path : Vec < LayerId > ) {
348
347
dispatch ( DocumentMessage :: DeleteLayer ( path) )
349
348
}
350
349
351
350
/// Requests the backend to add a layer to the layer list
352
351
#[ wasm_bindgen]
353
- pub fn add_folder ( path : Vec < LayerId > ) -> Result < ( ) , JsValue > {
352
+ pub fn add_folder ( path : Vec < LayerId > ) {
354
353
dispatch ( DocumentMessage :: CreateFolder ( path) )
355
354
}
0 commit comments