mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 00:01:51 -05:00
🐛 Fix problem when calculating group bounds
This commit is contained in:
parent
679c630a4d
commit
350c44f56f
1 changed files with 17 additions and 15 deletions
|
@ -25,22 +25,24 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
(defn bounds
|
(defn calc-bounds
|
||||||
[object objects]
|
[object objects]
|
||||||
(if (= :group (:type object))
|
|
||||||
(let [children-bounds
|
|
||||||
(into []
|
|
||||||
(comp (map #(get objects %))
|
|
||||||
(map #(bounds % objects)))
|
|
||||||
(:shapes object))]
|
|
||||||
(gsh/join-rects children-bounds))
|
|
||||||
|
|
||||||
(let [padding (filters/calculate-padding object)]
|
(let [xf-get-bounds (comp (map #(get objects %)) (map #(calc-bounds % objects)))
|
||||||
|
padding (filters/calculate-padding object)
|
||||||
|
obj-bounds
|
||||||
(-> (filters/get-filters-bounds object)
|
(-> (filters/get-filters-bounds object)
|
||||||
(update :x - padding)
|
(update :x - padding)
|
||||||
(update :y - padding)
|
(update :y - padding)
|
||||||
(update :width + (* 2 padding))
|
(update :width + (* 2 padding))
|
||||||
(update :height + (* 2 padding))))))
|
(update :height + (* 2 padding)))]
|
||||||
|
|
||||||
|
(if (= :group (:type object))
|
||||||
|
(->> (:shapes object)
|
||||||
|
(into [obj-bounds] xf-get-bounds)
|
||||||
|
(gsh/join-rects))
|
||||||
|
|
||||||
|
obj-bounds)))
|
||||||
|
|
||||||
(mf/defc object-svg
|
(mf/defc object-svg
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
|
@ -64,7 +66,7 @@
|
||||||
objects (reduce updt-fn objects mod-ids)
|
objects (reduce updt-fn objects mod-ids)
|
||||||
object (get objects object-id)
|
object (get objects object-id)
|
||||||
|
|
||||||
{:keys [x y width height] :as bs} (bounds object objects)
|
{:keys [x y width height] :as bs} (calc-bounds object objects)
|
||||||
[_ _ width height :as coords] (->> [x y width height] (map #(* % zoom)))
|
[_ _ width height :as coords] (->> [x y width height] (map #(* % zoom)))
|
||||||
|
|
||||||
vbox (str/join " " coords)
|
vbox (str/join " " coords)
|
||||||
|
|
Loading…
Add table
Reference in a new issue