0
Fork 0
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:
alonso.torres 2021-10-07 17:53:22 +02:00
parent 679c630a4d
commit 350c44f56f

View file

@ -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)))
(-> (filters/get-filters-bounds object) padding (filters/calculate-padding object)
(update :x - padding) obj-bounds
(update :y - padding) (-> (filters/get-filters-bounds object)
(update :width + (* 2 padding)) (update :x - padding)
(update :height + (* 2 padding)))))) (update :y - padding)
(update :width + (* 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)