Implement basic circle stamping (#53)

This commit is contained in:
T0mstone
2021-03-29 01:44:34 +02:00
committed by GitHub
parent c437f1bd22
commit 94f50377a3
10 changed files with 85 additions and 46 deletions

View File

@@ -17,7 +17,9 @@
@mousedown="canvasMouseDown"
@mouseup="canvasMouseUp"
@mousemove="canvasMouseMove"
></LayoutCol>
>
<svg></svg>
</LayoutCol>
</LayoutRow>
</LayoutCol>
</template>
@@ -65,6 +67,11 @@
.canvas {
background: #111;
flex: 1 1 100%;
svg {
width: 100%;
height: 100%;
}
}
}
}

View File

@@ -1,3 +1,3 @@
export function update_canvas() {
console.log("update_canvas")
export function update_canvas(svg) {
document.querySelector(".canvas svg").innerHTML = svg;
}

View File

@@ -9,7 +9,7 @@ use std::cell::RefCell;
use wasm_bindgen::prelude::*;
// the thread_local macro provides a way to initialize static variables with non-constant functions
thread_local! {pub static EDITOR_STATE: RefCell<Editor> = RefCell::new(Editor::new(Box::new(handle_response)))}
thread_local! { pub static EDITOR_STATE: RefCell<Editor> = RefCell::new(Editor::new(Box::new(handle_response))) }
#[wasm_bindgen(start)]
pub fn init() {
@@ -18,13 +18,13 @@ pub fn init() {
fn handle_response(response: Response) {
match response {
Response::UpdateCanvas => update_canvas(),
Response::UpdateCanvas { document } => update_canvas(document),
}
}
#[wasm_bindgen(module = "/../src/wasm-callback-processor.js")]
extern "C" {
fn update_canvas();
fn update_canvas(svg: String);
}
#[wasm_bindgen]

View File

@@ -35,7 +35,7 @@ pub fn on_mouse_down(x: u32, y: u32, mouse_keys: u8) -> Result<(), JsValue> {
#[wasm_bindgen]
pub fn on_mouse_up(x: u32, y: u32, mouse_keys: u8) -> Result<(), JsValue> {
let mouse_keys = events::MouseKeys::from_bits(mouse_keys).expect("invalid modifier keys");
let ev = events::Event::MouseDown(events::MouseState {
let ev = events::Event::MouseUp(events::MouseState {
position: events::CanvasPosition { x, y },
mouse_keys,
});