mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
🐛 Fix problem when dropping indices in flipped frames
This commit is contained in:
parent
b203c87dbb
commit
5f0f3abeae
3 changed files with 36 additions and 13 deletions
|
@ -15,7 +15,7 @@
|
|||
(dm/export fbo/layout-content-bounds)
|
||||
(dm/export fbo/child-layout-bound-points)
|
||||
(dm/export fdr/get-drop-index)
|
||||
(dm/export fdr/layout-drop-areas)
|
||||
(dm/export fdr/get-drop-areas)
|
||||
(dm/export fli/calc-layout-data)
|
||||
(dm/export fmo/layout-child-modifiers)
|
||||
|
||||
|
|
|
@ -8,11 +8,14 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes.common :as gco]
|
||||
[app.common.geom.shapes.flex-layout.lines :as fli]
|
||||
[app.common.geom.shapes.points :as gpo]
|
||||
[app.common.geom.shapes.rect :as gsr]
|
||||
[app.common.geom.shapes.transforms :as gtr]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]))
|
||||
|
||||
(defn drop-child-areas
|
||||
|
@ -179,14 +182,36 @@
|
|||
(+ (:y line-area) (:height line-area))
|
||||
(rest lines)))))))
|
||||
|
||||
(defn get-flip-modifiers
|
||||
[{:keys [flip-x flip-y transform transform-inverse] :as shape}]
|
||||
|
||||
(if (or flip-x flip-y)
|
||||
(let [modifiers
|
||||
(-> (ctm/empty)
|
||||
(ctm/resize (gpt/point (if flip-x -1.0 1.0)
|
||||
(if flip-y -1.0 1.0))
|
||||
(gco/center-shape shape)
|
||||
transform
|
||||
transform-inverse))]
|
||||
[(gtr/transform-shape shape modifiers) modifiers])
|
||||
[shape nil]))
|
||||
|
||||
(defn get-drop-areas
|
||||
[frame objects]
|
||||
(let [[frame modifiers] (get-flip-modifiers frame)
|
||||
children (->> (cph/get-immediate-children objects (:id frame))
|
||||
(remove :hidden)
|
||||
(map #(cond-> % (some? modifiers)
|
||||
(gtr/transform-shape modifiers)))
|
||||
(map #(vector (gpo/parent-coords-bounds (:points %) (:points frame)) %)))
|
||||
layout-data (fli/calc-layout-data frame children (:points frame))
|
||||
drop-areas (layout-drop-areas frame layout-data children)]
|
||||
drop-areas))
|
||||
|
||||
(defn get-drop-index
|
||||
[frame-id objects position]
|
||||
(let [frame (get objects frame-id)
|
||||
drop-areas (get-drop-areas frame objects)
|
||||
position (gmt/transform-point-center position (gco/center-shape frame) (:transform-inverse frame))
|
||||
children (->> (cph/get-immediate-children objects frame-id)
|
||||
(remove :hidden)
|
||||
(map #(vector (gpo/parent-coords-bounds (:points %) (:points frame)) %)))
|
||||
layout-data (fli/calc-layout-data frame children (:points frame))
|
||||
drop-areas (layout-drop-areas frame layout-data children)
|
||||
area (d/seek #(gsr/contains-point? % position) drop-areas)]
|
||||
(:index area)))
|
||||
|
|
|
@ -63,7 +63,8 @@
|
|||
col? (ctl/col? shape)
|
||||
|
||||
children (->> (cph/get-immediate-children objects (:id shape))
|
||||
(remove :hidden))
|
||||
(remove :hidden)
|
||||
(map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))
|
||||
layout-data (gsl/calc-layout-data shape children (:points shape))
|
||||
|
||||
layout-bounds (:layout-bounds layout-data)
|
||||
|
@ -85,7 +86,8 @@
|
|||
|
||||
(mf/defc debug-drop-zones
|
||||
"Debug component to show the auto-layout drop areas"
|
||||
{::mf/wrap-props false}
|
||||
{::mf/wrap [#(mf/memo' % (mf/check-props ["objects" "selected-shapes" "hover-top-frame-id"]))]
|
||||
::mf/wrap-props false}
|
||||
[props]
|
||||
|
||||
(let [objects (unchecked-get props "objects")
|
||||
|
@ -100,11 +102,7 @@
|
|||
shape (or selected-frame (get objects hover-top-frame-id))]
|
||||
|
||||
(when (and shape (:layout shape))
|
||||
(let [children (->> (cph/get-immediate-children objects (:id shape))
|
||||
(remove :hidden)
|
||||
(map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))
|
||||
layout-data (gsl/calc-layout-data shape children (:points shape))
|
||||
drop-areas (gsl/layout-drop-areas shape layout-data children)]
|
||||
(let [drop-areas (gsl/get-drop-areas shape objects)]
|
||||
[:g.debug-layout {:pointer-events "none"
|
||||
:transform (gsh/transform-str shape)}
|
||||
(for [[idx drop-area] (d/enumerate drop-areas)]
|
||||
|
|
Loading…
Add table
Reference in a new issue