From a994dba165f80f7ebc354eafafca77f574c25b93 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 29 Sep 2016 07:10:42 +0200 Subject: [PATCH] Add proportions related events to shapes events ns. --- src/uxbox/main/data/shapes.cljs | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/uxbox/main/data/shapes.cljs b/src/uxbox/main/data/shapes.cljs index 7165c5752..45a1bb5c2 100644 --- a/src/uxbox/main/data/shapes.cljs +++ b/src/uxbox/main/data/shapes.cljs @@ -166,6 +166,47 @@ (when color {:fill color}) (when opacity {:fill-opacity opacity}))))) +(defn lock-proportions + "Mark proportions of the shape locked and save the current + proportion as additional precalculated property." + [sid] + {:pre [(uuid? sid)]} + (reify + udp/IPageUpdate + rs/UpdateEvent + (-apply-update [_ state] + (let [[width height] (-> (get-in state [:shapes-by-id sid]) + (geom/size) + (keep [:width :height])) + proportion (/ width height)] + (update-in state [:shapes-by-id sid] assoc + :proportion proportion + :proportion-lock true))))) + +(defn unlock-proportions + [sid] + {:pre [(uuid? sid)]} + (reify + udp/IPageUpdate + rs/UpdateEvent + (-apply-update [_ state] + (update-in state [:shapes-by-id sid] assoc + :proportion-lock false)))) + +(defn setup-proportions + [sid] + {:pre [(uuid? sid)]} + (reify + udp/IPageUpdate + rs/UpdateEvent + (-apply-update [_ state] + (let [[width height] (-> (get-in state [:shapes-by-id sid]) + (geom/size) + (keep [:width :height])) + proportion (/ width height)] + (update-in state [:shapes-by-id sid] assoc + :proportion proportion))))) + (defn update-font-attrs [sid {:keys [family style weight size align letter-spacing line-height] :as opts}]