mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 07:21:38 +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 (reorder-selected-layout-child direction))
|
||||||
(rx/of (nudge-selected-shapes direction shift?)))))))
|
(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
|
(defn update-position
|
||||||
"Move shapes to a new position"
|
"Move shapes to a new position"
|
||||||
([id position] (update-position id position nil))
|
([id position] (update-position id position nil))
|
||||||
([id position options]
|
([id position options]
|
||||||
(dm/assert! (uuid? id))
|
(dm/assert! (uuid? id))
|
||||||
|
|
||||||
(ptk/reify ::update-position
|
(ptk/reify ::update-position
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
|
@ -874,15 +888,11 @@
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
;; FIXME: performance rect
|
;; FIXME: performance rect
|
||||||
bbox (-> shape :points grc/points->rect)
|
bbox (-> shape :points grc/points->rect)
|
||||||
|
parent (cfh/get-parent objects id)
|
||||||
cpos (gpt/point (:x bbox) (:y bbox))
|
delta (if-not (:relative? options)
|
||||||
pos (gpt/point (or (:x position) (:x bbox))
|
(get-delta position bbox)
|
||||||
(or (:y position) (:y bbox)))
|
(get-relative-delta position bbox parent))
|
||||||
|
|
||||||
delta (gpt/subtract pos cpos)
|
|
||||||
|
|
||||||
modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
|
modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
|
||||||
|
|
||||||
(rx/of (dwm/apply-modifiers {:modifiers modif-tree
|
(rx/of (dwm/apply-modifiers {:modifiers modif-tree
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:ignore-constraints false
|
:ignore-constraints false
|
||||||
|
|
|
@ -290,15 +290,35 @@
|
||||||
{:ignore-touched true
|
{:ignore-touched true
|
||||||
:page-id page-id}))))))))
|
: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
|
(defn update-shape-position
|
||||||
([value shape-ids attributes] (update-shape-position value shape-ids attributes nil))
|
([value shape-ids attributes] (update-shape-position value shape-ids attributes nil))
|
||||||
([value shape-ids attributes page-id]
|
([value shape-ids attributes page-id]
|
||||||
(ptk/reify ::update-shape-position
|
(ptk/reify ::update-shape-position
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ state _]
|
||||||
(when (number? value)
|
(when (number? value)
|
||||||
(rx/concat
|
(let [page-id' (or page-id (get state :current-page-id))
|
||||||
(map #(dwt/update-position % (zipmap attributes (repeat value)) {:ignore-touched true :page-id page-id}) shape-ids)))))))
|
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
|
(defn update-layout-sizing-limits
|
||||||
([value shape-ids attributes] (update-layout-sizing-limits value shape-ids attributes nil))
|
([value shape-ids attributes] (update-layout-sizing-limits value shape-ids attributes nil))
|
||||||
|
@ -399,4 +419,3 @@
|
||||||
|
|
||||||
(defn token-attributes [token-type]
|
(defn token-attributes [token-type]
|
||||||
(dm/get-in token-properties [token-type :attributes]))
|
(dm/get-in token-properties [token-type :attributes]))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue