0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 16:48:16 -05:00

Fix wrong order for args for draw_react (rust)

This commit is contained in:
Belén Albeza 2024-10-02 17:04:29 +02:00
parent 305de33200
commit e84622061d
3 changed files with 16 additions and 35 deletions

View file

@ -35,13 +35,6 @@ impl State {
}
}
#[no_mangle]
pub fn add(left: f32, right: f32) -> f32 {
println!("left-> {}", left);
println!("right-> {}", right);
left + right
}
fn init_gl() {
unsafe {
gl::load_with(|addr| {
@ -88,14 +81,12 @@ fn create_surface(gpu_state: &mut GpuState, width: i32, height: i32) -> Surface
.unwrap()
}
fn render_rect(surface: &mut Surface, left: f32, top: f32, right: f32, bottom: f32) {
fn render_rect(surface: &mut Surface, rect: Rect, color: Color) {
let mut paint = Paint::default();
paint.set_style(PaintStyle::Fill);
paint.set_color(Color::BLACK);
paint.set_color(color);
paint.set_anti_alias(true);
surface
.canvas()
.draw_rect(Rect::new(left, top, right, bottom), &paint);
surface.canvas().draw_rect(rect, &paint);
}
/// This is called from JS after the WebGL context has been created.
@ -122,19 +113,14 @@ pub unsafe extern "C" fn resize_surface(state: *mut State, width: i32, height: i
pub unsafe extern "C" fn draw_rect(
state: *mut State,
left: i32,
right: i32,
top: i32,
right: i32,
bottom: i32,
) {
let state = unsafe { state.as_mut() }.expect("got an invalid state pointer");
//state.surface.canvas().clear(Color::WHITE);
render_rect(
&mut state.surface,
left as f32,
right as f32,
top as f32,
bottom as f32,
);
let rect = Rect::new(left as f32, top as f32, right as f32, bottom as f32);
render_rect(&mut state.surface, rect, Color::BLACK);
state
.gpu_state
.context
@ -163,10 +149,4 @@ fn main() {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View file

@ -20,14 +20,16 @@
(let [draw-rect (gobj/get ^js internal-module "_draw_rect")
translate (gobj/get ^js internal-module "_translate")
reset-canvas (gobj/get ^js internal-module "_reset_canvas")
scale (gobj/get ^js internal-module "_scale")]
scale (gobj/get ^js internal-module "_scale")
supported-shapes (filter (fn [shape] (not= (:type shape) :frame)) (vals objects))]
(js/requestAnimationFrame (fn [])
(reset-canvas gpu-state)
(scale gpu-state zoom zoom)
(translate gpu-state (- (:x vbox)) (- (:y vbox)))
(doseq [shape (vals objects)]
(doseq [shape supported-shapes]
(let [sr (:selrect shape)]
;; (js/console.log (clj->js shape))
(draw-rect gpu-state (:x1 sr) (:y1 sr) (:x2 sr) (:y2 sr)))))))
(defn set-canvas

View file

@ -28,7 +28,7 @@ var readyPromise = new Promise((resolve, reject) => {
readyPromiseResolve = resolve;
readyPromiseReject = reject;
});
["_add","_draw_rect","_init","_main","_reset_canvas","_resize_surface","_scale","_translate","getExceptionMessage","incrementExceptionRefcount","decrementExceptionRefcount","_memory","___indirect_function_table","onRuntimeInitialized"].forEach((prop) => {
["_draw_rect","_init","_main","_reset_canvas","_resize_surface","_scale","_translate","getExceptionMessage","incrementExceptionRefcount","decrementExceptionRefcount","_memory","___indirect_function_table","onRuntimeInitialized"].forEach((prop) => {
if (!Object.getOwnPropertyDescriptor(readyPromise, prop)) {
Object.defineProperty(readyPromise, prop, {
get: () => abort('You are getting ' + prop + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js'),
@ -8561,7 +8561,6 @@ var wasmImports = {
};
var wasmExports = createWasm();
var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors', 0);
var _add = Module['_add'] = createExportWrapper('add', 2);
var _init = Module['_init'] = createExportWrapper('init', 2);
var _resize_surface = Module['_resize_surface'] = createExportWrapper('resize_surface', 3);
var _draw_rect = Module['_draw_rect'] = createExportWrapper('draw_rect', 5);
@ -8701,10 +8700,10 @@ function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
}
}
function invoke_viffff(index,a1,a2,a3,a4,a5) {
function invoke_iiiii(index,a1,a2,a3,a4) {
var sp = stackSave();
try {
getWasmTableEntry(index)(a1,a2,a3,a4,a5);
return getWasmTableEntry(index)(a1,a2,a3,a4);
} catch(e) {
stackRestore(sp);
if (!(e instanceof EmscriptenEH)) throw e;
@ -8712,10 +8711,10 @@ function invoke_viffff(index,a1,a2,a3,a4,a5) {
}
}
function invoke_iiiii(index,a1,a2,a3,a4) {
function invoke_viffff(index,a1,a2,a3,a4,a5) {
var sp = stackSave();
try {
return getWasmTableEntry(index)(a1,a2,a3,a4);
getWasmTableEntry(index)(a1,a2,a3,a4,a5);
} catch(e) {
stackRestore(sp);
if (!(e instanceof EmscriptenEH)) throw e;