mirror of
https://github.com/penpot/penpot.git
synced 2025-07-18 15:47:14 +02:00
✨ Fix many corner issues related to shape data structure change
This commit is contained in:
parent
4623f36042
commit
96bb282674
9 changed files with 125 additions and 107 deletions
|
@ -15,7 +15,6 @@
|
|||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.record :as cr]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.changes :as dch]
|
||||
|
@ -68,15 +67,15 @@
|
|||
|
||||
calculate-selrect
|
||||
(fn [selrect [delta space?]]
|
||||
(let [selrect (-> (cr/clone selrect)
|
||||
(cr/update! :x2 + (:x delta))
|
||||
(cr/update! :y2 + (:y delta)))
|
||||
(let [selrect (-> selrect
|
||||
(update :x2 + (:x delta))
|
||||
(update :y2 + (:y delta)))
|
||||
selrect (if ^boolean space?
|
||||
(-> (cr/clone selrect)
|
||||
(cr/update! :x1 + (:x delta))
|
||||
(cr/update! :y1 + (:y delta)))
|
||||
(-> selrect
|
||||
(update :x1 + (:x delta))
|
||||
(update :y1 + (:y delta)))
|
||||
selrect)]
|
||||
(grc/update-rect! selrect :corners)))
|
||||
(grc/update-rect selrect :corners)))
|
||||
|
||||
selrect-stream
|
||||
(->> ms/mouse-position
|
||||
|
|
|
@ -6,32 +6,20 @@
|
|||
|
||||
(ns app.main.ui.workspace.shapes.common
|
||||
(:require
|
||||
[app.common.record :as cr]
|
||||
[app.main.ui.shapes.shape :refer [shape-container]]
|
||||
[app.main.ui.workspace.shapes.debug :as wsd]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def ^:private excluded-attrs
|
||||
#{:blocked
|
||||
:hide-fill-on-export
|
||||
:collapsed
|
||||
:remote-synced
|
||||
:exports})
|
||||
|
||||
(defn check-shape
|
||||
[new-shape old-shape]
|
||||
(cr/-equiv-with-exceptions old-shape new-shape excluded-attrs))
|
||||
|
||||
(defn check-shape-props
|
||||
[np op]
|
||||
(check-shape (unchecked-get np "shape")
|
||||
(unchecked-get op "shape")))
|
||||
(= (unchecked-get np "shape")
|
||||
(unchecked-get op "shape")))
|
||||
|
||||
(defn generic-wrapper-factory
|
||||
[component]
|
||||
(mf/fnc generic-wrapper
|
||||
{::mf/wrap [#(mf/memo' % check-shape-props)]
|
||||
::mf/wrap-props false}
|
||||
::mf/props :obj}
|
||||
[props]
|
||||
(let [shape (unchecked-get props "shape")]
|
||||
[:> shape-container {:shape shape}
|
||||
|
|
|
@ -261,7 +261,8 @@
|
|||
(= (:layout selected-frame) :flex)
|
||||
(zero? (:rotation first-shape)))
|
||||
|
||||
selecting-first-level-frame? (and single-select? (cfh/root-frame? first-shape))
|
||||
selecting-first-level-frame?
|
||||
(and single-select? (cfh/root-frame? first-shape))
|
||||
|
||||
offset-x (if selecting-first-level-frame?
|
||||
(:x first-shape)
|
||||
|
@ -276,19 +277,20 @@
|
|||
|
||||
(when ^boolean render.wasm/enabled?
|
||||
(mf/with-effect []
|
||||
(time (when-let [canvas (mf/ref-val canvas-ref)]
|
||||
(->> render.wasm/module
|
||||
(p/fmap (fn [ready?]
|
||||
(when ready?
|
||||
(reset! canvas-init? true)
|
||||
(render.wasm/assign-canvas canvas)))))
|
||||
(fn []
|
||||
(render.wasm/clear-canvas)))))
|
||||
(when-let [canvas (mf/ref-val canvas-ref)]
|
||||
(->> render.wasm/module
|
||||
(p/fmap (fn [ready?]
|
||||
(when ready?
|
||||
(reset! canvas-init? true)
|
||||
(render.wasm/assign-canvas canvas)))))
|
||||
(fn []
|
||||
(render.wasm/clear-canvas))))
|
||||
|
||||
(mf/with-effect [objects-modified canvas-init?]
|
||||
(when @canvas-init?
|
||||
(render.wasm/set-objects objects-modified)
|
||||
(render.wasm/draw-objects zoom vbox)))
|
||||
|
||||
(mf/with-effect [vbox canvas-init?]
|
||||
(let [frame-id (when @canvas-init? (do
|
||||
(render.wasm/draw-objects zoom vbox)))]
|
||||
|
@ -300,6 +302,8 @@
|
|||
(hooks/setup-keyboard alt? mod? space? z? shift?)
|
||||
(hooks/setup-hover-shapes page-id move-stream base-objects transform selected mod? hover measure-hover
|
||||
hover-ids hover-top-frame-id @hover-disabled? focus zoom show-measures?)
|
||||
|
||||
;; FIXME: this should be removed on canvas viewport
|
||||
(hooks/setup-viewport-modifiers modifiers base-objects)
|
||||
(hooks/setup-shortcuts node-editing? drawing-path? text-editing? grid-editing?)
|
||||
(hooks/setup-active-frames base-objects hover-ids selected active-frames zoom transform vbox)
|
||||
|
|
|
@ -9,26 +9,58 @@
|
|||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.types.shape.impl]
|
||||
[app.config :as cf]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def enabled?
|
||||
(contains? cf/flags :render-wasm))
|
||||
|
||||
(defonce ^:dynamic internal-module #js {})
|
||||
(defonce ^:dynamic internal-gpu-state #js {})
|
||||
(set! app.common.types.shape.impl/enabled-wasm-ready-shape enabled?)
|
||||
|
||||
(defn set-objects [objects]
|
||||
(let [shapes-buffer (unchecked-get internal-module "_shapes_buffer")
|
||||
heap (unchecked-get internal-module "HEAPF32")
|
||||
;; size *in bytes* for each shapes::Shape
|
||||
rect-size 16
|
||||
;; TODO: remove the `take` once we have the dynamic data structure in Rust
|
||||
supported-shapes (take 2048 (filter #(not (cfh/root? %)) (vals objects)))
|
||||
mem (js/Float32Array. (.-buffer heap) (shapes-buffer) (* rect-size (count supported-shapes)))]
|
||||
(run! (fn [[shape index]]
|
||||
(.set mem (.-buffer shape) (* index rect-size)))
|
||||
(zipmap supported-shapes (range)))))
|
||||
(defonce internal-module #js {})
|
||||
(defonce internal-gpu-state #js {})
|
||||
|
||||
;; TODO: remove the `take` once we have the dynamic data structure in Rust
|
||||
(def xform
|
||||
(comp
|
||||
(remove cfh/root?)
|
||||
(take 2048)))
|
||||
|
||||
;; Size in number of f32 values that represents the shape selrect (
|
||||
(def rect-size 4)
|
||||
|
||||
(defn set-objects
|
||||
[objects]
|
||||
;; FIXME: maybe change the name of `_shapes_buffer` (?)
|
||||
(let [get-shapes-buffer-ptr
|
||||
(unchecked-get internal-module "_shapes_buffer")
|
||||
|
||||
heap
|
||||
(unchecked-get internal-module "HEAPF32")
|
||||
|
||||
shapes
|
||||
(into [] xform (vals objects))
|
||||
|
||||
total-shapes
|
||||
(count shapes)
|
||||
|
||||
heap-offset
|
||||
(get-shapes-buffer-ptr)
|
||||
|
||||
heap-size
|
||||
(* rect-size total-shapes)
|
||||
|
||||
mem
|
||||
(js/Float32Array. (.-buffer heap)
|
||||
heap-offset
|
||||
heap-size)]
|
||||
|
||||
(loop [index 0]
|
||||
(when (< index total-shapes)
|
||||
(let [shape (nth shapes index)]
|
||||
(.set ^js mem (.-buffer shape) (* index rect-size))
|
||||
(recur (inc index)))))))
|
||||
|
||||
(defn draw-objects
|
||||
[zoom vbox]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue