mirror of
https://github.com/penpot/penpot.git
synced 2025-06-21 10:16:58 +02:00
🐛 Fix some problems with modifiers
This commit is contained in:
parent
1a705cee24
commit
a85a42d367
10 changed files with 138 additions and 99 deletions
|
@ -486,11 +486,16 @@
|
|||
[]
|
||||
(keep
|
||||
(fn [[id data]]
|
||||
(if (ctm/has-geometry? (:modifiers data))
|
||||
(cond
|
||||
(= id uuid/zero)
|
||||
nil
|
||||
|
||||
(ctm/has-geometry? (:modifiers data))
|
||||
{:id id
|
||||
:transform (ctm/modifiers->transform (:modifiers data))}
|
||||
|
||||
;; Unit matrix is used for reflowing
|
||||
:else
|
||||
{:id id
|
||||
:transform (gmt/matrix)})))
|
||||
modif-tree))
|
||||
|
@ -511,6 +516,13 @@
|
|||
(update [_ state]
|
||||
(assoc state :workspace-selrect selrect))))
|
||||
|
||||
(defn set-temporary-modifiers
|
||||
[modifiers]
|
||||
(ptk/reify ::set-temporary-modifiers
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(assoc state :workspace-wasm-modifiers modifiers))))
|
||||
|
||||
#_:clj-kondo/ignore
|
||||
(defn set-wasm-modifiers
|
||||
[modif-tree & {:keys [ignore-constraints ignore-snap-pixel]
|
||||
|
@ -521,7 +533,6 @@
|
|||
(update [_ state]
|
||||
(let [property-changes
|
||||
(extract-property-changes modif-tree)]
|
||||
|
||||
(-> state
|
||||
(assoc :prev-wasm-props (:wasm-props state))
|
||||
(assoc :wasm-props property-changes))))
|
||||
|
@ -537,8 +548,11 @@
|
|||
(let [structure-entries (parse-structure-modifiers modif-tree)]
|
||||
(wasm.api/set-structure-modifiers structure-entries)
|
||||
(let [geometry-entries (parse-geometry-modifiers modif-tree)
|
||||
selrect (wasm.api/propagate-apply geometry-entries pixel-precision)]
|
||||
(rx/of (set-temporary-selrect selrect))))))))
|
||||
modifiers (wasm.api/propagate-modifiers geometry-entries pixel-precision)]
|
||||
(wasm.api/set-modifiers modifiers)
|
||||
(let [selrect (wasm.api/get-selection-rect (->> geometry-entries (map :id)))]
|
||||
(rx/of (set-temporary-selrect selrect)
|
||||
(set-temporary-modifiers modifiers)))))))))
|
||||
|
||||
#_:clj-kondo/ignore
|
||||
(defn apply-wasm-modifiers
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
(update [_ state]
|
||||
(-> state
|
||||
(update :workspace-local dissoc :transform :duplicate-move-started?)
|
||||
(dissoc :workspace-selrect)))))
|
||||
(dissoc :workspace-selrect :workspace-wasm-modifiers)))))
|
||||
|
||||
;; -- Resize --------------------------------------------------------
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctt]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.data.workspace.modifiers :as dwm]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.features :as features]
|
||||
[app.main.refs :as refs]
|
||||
|
@ -54,27 +53,23 @@
|
|||
[app.util.debug :as dbg]
|
||||
[app.util.text-editor :as ted]
|
||||
[beicon.v2.core :as rx]
|
||||
[okulary.core :as l]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
;; --- Viewport
|
||||
|
||||
(def workspace-wasm-modifiers
|
||||
(l/derived :workspace-wasm-modifiers st/state))
|
||||
|
||||
(defn apply-modifiers-to-selected
|
||||
[selected objects text-modifiers modifiers]
|
||||
(reduce
|
||||
(fn [objects id]
|
||||
(update
|
||||
objects id
|
||||
(fn [shape]
|
||||
(cond-> shape
|
||||
(and (cfh/text-shape? shape) (contains? text-modifiers id))
|
||||
(dwm/apply-text-modifier (get text-modifiers id))
|
||||
|
||||
(contains? modifiers id)
|
||||
(gsh/transform-shape (dm/get-in modifiers [id :modifiers]))))))
|
||||
|
||||
objects
|
||||
selected))
|
||||
[selected objects modifiers]
|
||||
(->> modifiers
|
||||
(filter #(contains? selected (:id %)))
|
||||
(reduce
|
||||
(fn [objects {:keys [id transform]}]
|
||||
(update objects id gsh/apply-transform transform))
|
||||
objects)))
|
||||
|
||||
(mf/defc viewport*
|
||||
[{:keys [selected wglobal wlocal layout file page palete-size]}]
|
||||
|
@ -113,12 +108,13 @@
|
|||
|
||||
base-objects (ui-hooks/with-focus-objects objects focus)
|
||||
|
||||
modifiers (mf/deref refs/workspace-modifiers)
|
||||
text-modifiers (mf/deref refs/workspace-text-modifier)
|
||||
wasm-modifiers (mf/deref workspace-wasm-modifiers)
|
||||
|
||||
objects-modified (mf/with-memo [base-objects text-modifiers modifiers]
|
||||
(binding [cts/*wasm-sync* false]
|
||||
(apply-modifiers-to-selected selected base-objects text-modifiers modifiers)))
|
||||
objects-modified
|
||||
(mf/with-memo
|
||||
[base-objects wasm-modifiers]
|
||||
(binding [cts/*wasm-sync* false]
|
||||
(apply-modifiers-to-selected selected base-objects wasm-modifiers)))
|
||||
|
||||
selected-shapes (->> selected
|
||||
(into [] (keep (d/getf objects-modified)))
|
||||
|
@ -409,11 +405,9 @@
|
|||
(when show-text-editor?
|
||||
(if (features/active-feature? @st/state "text-editor/v2")
|
||||
[:& editor-v2/text-editor {:shape editing-shape
|
||||
:ref text-editor-ref
|
||||
:modifiers modifiers}]
|
||||
:ref text-editor-ref}]
|
||||
[:& editor-v1/text-editor-svg {:shape editing-shape
|
||||
:ref text-editor-ref
|
||||
:modifiers modifiers}]))
|
||||
:ref text-editor-ref}]))
|
||||
|
||||
(when show-frame-outline?
|
||||
(let [outlined-frame-id
|
||||
|
@ -426,8 +420,7 @@
|
|||
[:& outline/shape-outlines
|
||||
{:objects base-objects
|
||||
:hover #{outlined-frame-id}
|
||||
:zoom zoom
|
||||
:modifiers modifiers}]
|
||||
:zoom zoom}]
|
||||
|
||||
(when (ctl/any-layout? outlined-frame)
|
||||
[:g.ghost-outline
|
||||
|
@ -443,8 +436,7 @@
|
|||
:hover #{(:id @hover) @frame-hover}
|
||||
:highlighted highlighted
|
||||
:edition edition
|
||||
:zoom zoom
|
||||
:modifiers modifiers}])
|
||||
:zoom zoom}])
|
||||
|
||||
(when (and show-selection-handlers?
|
||||
selected-shapes)
|
||||
|
@ -459,8 +451,7 @@
|
|||
(when show-text-editor?
|
||||
[:& text-edition-outline
|
||||
{:shape (get base-objects edition)
|
||||
:zoom zoom
|
||||
:modifiers modifiers}])
|
||||
:zoom zoom}])
|
||||
|
||||
(when show-measures?
|
||||
[:& msr/measurement
|
||||
|
@ -586,8 +577,7 @@
|
|||
:vbox vbox
|
||||
:guides (:guides page)
|
||||
:hover-frame guide-frame
|
||||
:disabled-guides disabled-guides?
|
||||
:modifiers modifiers}])
|
||||
:disabled-guides disabled-guides?}])
|
||||
|
||||
;; DEBUG LAYOUT DROP-ZONES
|
||||
(when (dbg/enabled? :layout-drop-zones)
|
||||
|
@ -651,8 +641,7 @@
|
|||
(when (or show-grid-editor? hover-grid?)
|
||||
[:& grid-layout/editor
|
||||
{:zoom zoom
|
||||
:objects base-objects
|
||||
:modifiers modifiers
|
||||
:objects objects-modified
|
||||
:shape (or (get base-objects edition)
|
||||
(get base-objects @hover-top-frame-id))
|
||||
:view-only (not show-grid-editor?)}])
|
||||
|
@ -665,8 +654,7 @@
|
|||
[:& grid-layout/editor
|
||||
{:zoom zoom
|
||||
:key (dm/str (:id frame))
|
||||
:objects base-objects
|
||||
:modifiers modifiers
|
||||
:objects objects-modified
|
||||
:shape frame
|
||||
:view-only true}]))]
|
||||
[:g.scrollbar-wrapper {:clipPath "url(#clip-handlers)"}
|
||||
|
|
|
@ -870,6 +870,38 @@
|
|||
:center (gpt/point cx cy)
|
||||
:transform transform}))))
|
||||
|
||||
(defn get-selection-rect
|
||||
[entries]
|
||||
(when (d/not-empty? entries)
|
||||
(let [offset (mem/alloc-bytes-32 (* (count entries) 16))
|
||||
heapu32 (mem/get-heap-u32)]
|
||||
|
||||
(loop [entries (seq entries)
|
||||
current-offset offset]
|
||||
(when-not (empty? entries)
|
||||
(let [id (first entries)]
|
||||
(sr/heapu32-set-uuid id heapu32 current-offset)
|
||||
(recur (rest entries) (+ current-offset (mem/ptr8->ptr32 16))))))
|
||||
|
||||
(let [offset (h/call wasm/internal-module "_get_selection_rect")
|
||||
heapf32 (mem/get-heap-f32)
|
||||
width (aget heapf32 (mem/ptr8->ptr32 (+ offset 0)))
|
||||
height (aget heapf32 (mem/ptr8->ptr32 (+ offset 4)))
|
||||
cx (aget heapf32 (mem/ptr8->ptr32 (+ offset 8)))
|
||||
cy (aget heapf32 (mem/ptr8->ptr32 (+ offset 12)))
|
||||
a (aget heapf32 (mem/ptr8->ptr32 (+ offset 16)))
|
||||
b (aget heapf32 (mem/ptr8->ptr32 (+ offset 20)))
|
||||
c (aget heapf32 (mem/ptr8->ptr32 (+ offset 24)))
|
||||
d (aget heapf32 (mem/ptr8->ptr32 (+ offset 28)))
|
||||
e (aget heapf32 (mem/ptr8->ptr32 (+ offset 32)))
|
||||
f (aget heapf32 (mem/ptr8->ptr32 (+ offset 36)))
|
||||
transform (gmt/matrix a b c d e f)]
|
||||
(h/call wasm/internal-module "_free_bytes")
|
||||
{:width width
|
||||
:height height
|
||||
:center (gpt/point cx cy)
|
||||
:transform transform}))))
|
||||
|
||||
(defn set-canvas-background
|
||||
[background]
|
||||
(let [rgba (sr-clr/hex->u32argb background 1)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue