0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-26 16:56:11 -05:00

Fix group shape rerender when a transformation is applied to its children shapes.

This commit is contained in:
Andrey Antukh 2016-08-24 16:45:11 +03:00
parent 3d18f2d95e
commit 62eb224ac0
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 35 additions and 63 deletions

View file

@ -5,27 +5,7 @@
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.ui.shapes
(:require [lentes.core :as l]
[rum.core :as rum]
[uxbox.main.state :as st]
[uxbox.util.mixins :as mx]
[uxbox.main.ui.shapes.group :as group]))
(:require [uxbox.main.ui.shapes.group :as group]))
(def render-component group/render-component)
(defn- focus-shape
[id]
(-> (l/in [:shapes-by-id id])
(l/derive st/state)))
(defn- shape-render
[own id]
(let [shape (mx/react (focus-shape id))]
(when-not (:hidden shape)
(render-component shape))))
(def shape
(mx/component
{:render shape-render
:name "shape"
:mixins [mx/static mx/reactive]}))
(def shape group/component-container)

View file

@ -5,11 +5,9 @@
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.ui.shapes.group
(:require [sablono.core :refer-macros [html]]
[rum.core :as rum]
[lentes.core :as l]
(:require [lentes.core :as l]
[uxbox.main.state :as st]
[uxbox.util.mixins :as mx]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.main.ui.shapes.icon :as icon]
@ -23,10 +21,14 @@
(declare group-component)
(defn- focus-shape
[id]
(-> (l/in [:shapes-by-id id])
(l/derive st/state)))
(defn render-component
[{:keys [type] :as shape}]
;; (println "render-component" (pr-str shape))
(case type
[shape]
(case (:type shape)
:group (group-component shape)
:text (text/text-component shape)
:icon (icon/icon-component shape)
@ -34,50 +36,40 @@
:path (path/path-component shape)
:circle (circle/circle-component shape)))
(mx/defc component-container
{:mixins [mx/reactive mx/static]}
[id]
(let [shape (mx/react (focus-shape id))]
(when-not (:hidden shape)
(render-component shape))))
;; --- Group Component
(declare group-shape)
(defn- group-component-render
[own shape]
(let [{:keys [id x y width height group]} shape
selected (mx/react common/selected-ref)
(mx/defc group-component
{:mixins [mx/static mx/reactive]}
[{:keys [id x y width height group] :as shape}]
(let [selected (mx/react common/selected-ref)
selected? (contains? selected id)
on-mouse-down #(common/on-mouse-down % shape selected)]
(html
[:g.shape.group-shape
{:class (when selected? "selected")
:on-mouse-down on-mouse-down}
(group-shape shape render-component)])))
(def group-component
(mx/component
{:render group-component-render
:name "group-component"
:mixins [mx/static mx/reactive]}))
(group-shape shape component-container)]))
;; --- Group Shape
(defn- group-shape-render
[own {:keys [items id dx dy rotation] :as shape} factory]
(mx/defc group-shape
{:mixins [mx/static mx/reactive]}
[{:keys [items id dx dy rotation] :as shape} factory]
(let [key (str "shape-" id)
rfm (geom/transformation-matrix shape)
attrs (merge {:id key :key key :transform (str rfm)}
(attrs/extract-style-attrs shape)
(attrs/make-debug-attrs shape))
shapes-by-id (get @st/state :shapes-by-id)
xf (comp
(map #(get shapes-by-id %))
(remove :hidden))]
(html
(attrs/make-debug-attrs shape))]
[:g attrs
(for [item (reverse (into [] xf items))
:let [key (str (:id item))]]
(for [item items :let [key (str item)]]
(-> (factory item)
(rum/with-key key)))])))
(mx/with-key key)))]))
(def group-shape
(mx/component
{:render group-shape-render
:name "group-shape"
:mixins [mx/static]}))

View file

@ -37,7 +37,7 @@
;; --- Rect Shape
(mx/defc rect-shape
[{:keys [id x1 y1 x2 y2] :as shape}]
[{:keys [id x1 y1] :as shape}]
(let [key (str "shape-" id)
rfm (geom/transformation-matrix shape)
size (geom/size shape)