mirror of
https://github.com/penpot/penpot.git
synced 2025-06-01 06:11:37 +02:00
🐛 Fix relative position application for flex children
This commit is contained in:
parent
451306f719
commit
44ca01aa27
2 changed files with 42 additions and 13 deletions
|
@ -859,12 +859,26 @@
|
|||
(rx/of (reorder-selected-layout-child direction))
|
||||
(rx/of (nudge-selected-shapes direction shift?)))))))
|
||||
|
||||
(defn- get-delta [position bbox]
|
||||
(let [cpos (gpt/point (:x bbox) (:y bbox))
|
||||
pos (gpt/point (or (:x position) (:x bbox))
|
||||
(or (:y position) (:y bbox)))]
|
||||
(gpt/subtract pos cpos)))
|
||||
|
||||
(defn- get-relative-delta [position bbox parent]
|
||||
(let [parent-bbox (-> parent :points grc/points->rect)
|
||||
relative-cpos (gpt/subtract (gpt/point (:x bbox) (:y bbox))
|
||||
(gpt/point (:x parent-bbox) (:y parent-bbox)))
|
||||
cpos (gpt/point (:x relative-cpos) (:y relative-cpos))
|
||||
pos (gpt/point (or (:x position) (:x relative-cpos))
|
||||
(or (:y position) (:y relative-cpos)))]
|
||||
(gpt/subtract pos cpos)))
|
||||
|
||||
(defn update-position
|
||||
"Move shapes to a new position"
|
||||
([id position] (update-position id position nil))
|
||||
([id position options]
|
||||
(dm/assert! (uuid? id))
|
||||
|
||||
(ptk/reify ::update-position
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -874,15 +888,11 @@
|
|||
shape (get objects id)
|
||||
;; FIXME: performance rect
|
||||
bbox (-> shape :points grc/points->rect)
|
||||
|
||||
cpos (gpt/point (:x bbox) (:y bbox))
|
||||
pos (gpt/point (or (:x position) (:x bbox))
|
||||
(or (:y position) (:y bbox)))
|
||||
|
||||
delta (gpt/subtract pos cpos)
|
||||
|
||||
parent (cfh/get-parent objects id)
|
||||
delta (if-not (:relative? options)
|
||||
(get-delta position bbox)
|
||||
(get-relative-delta position bbox parent))
|
||||
modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
|
||||
|
||||
(rx/of (dwm/apply-modifiers {:modifiers modif-tree
|
||||
:page-id page-id
|
||||
:ignore-constraints false
|
||||
|
|
|
@ -290,15 +290,35 @@
|
|||
{:ignore-touched true
|
||||
:page-id page-id}))))))))
|
||||
|
||||
(defn- immediate-flex-absolute-child? [objects id]
|
||||
(let [shape (get objects id)]
|
||||
(boolean
|
||||
(and (:layout-item-absolute shape)
|
||||
(ctsl/flex-layout-immediate-child? objects shape)))))
|
||||
|
||||
(defn update-shape-position
|
||||
([value shape-ids attributes] (update-shape-position value shape-ids attributes nil))
|
||||
([value shape-ids attributes page-id]
|
||||
(ptk/reify ::update-shape-position
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(watch [_ state _]
|
||||
(when (number? value)
|
||||
(rx/concat
|
||||
(map #(dwt/update-position % (zipmap attributes (repeat value)) {:ignore-touched true :page-id page-id}) shape-ids)))))))
|
||||
(let [page-id' (or page-id (get state :current-page-id))
|
||||
objects (dsh/lookup-page-objects state page-id')
|
||||
{canvas-children-ids false
|
||||
flex-children-ids true} (group-by #(immediate-flex-absolute-child? objects %) shape-ids)]
|
||||
(rx/concat
|
||||
(concat
|
||||
(map #(dwt/update-position % (zipmap attributes (repeat value))
|
||||
{:ignore-touched true
|
||||
:page-id page-id'})
|
||||
canvas-children-ids)
|
||||
(map #(dwt/update-position % (zipmap attributes (repeat value))
|
||||
{:ignore-touched true
|
||||
:page-id page-id'
|
||||
:relative? true})
|
||||
flex-children-ids)))))))))
|
||||
|
||||
|
||||
(defn update-layout-sizing-limits
|
||||
([value shape-ids attributes] (update-layout-sizing-limits value shape-ids attributes nil))
|
||||
|
@ -399,4 +419,3 @@
|
|||
|
||||
(defn token-attributes [token-type]
|
||||
(dm/get-in token-properties [token-type :attributes]))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue