From b3207b574662309c038d5a6ecf9a6ccae3ae59d6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 28 Sep 2016 22:13:19 +0200 Subject: [PATCH] Add `resize-dim` function to geom helpers. A helper for resize by width and height with initial support for rect, icon and circle. --- src/uxbox/main/geom.cljs | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/uxbox/main/geom.cljs b/src/uxbox/main/geom.cljs index aa241eb2eb..66af294ad5 100644 --- a/src/uxbox/main/geom.cljs +++ b/src/uxbox/main/geom.cljs @@ -277,6 +277,52 @@ (let [{:keys [width height]} (size shape)] (assoc shape :proportion (/ width height)))) +;; --- Resize (Dimentsions) + +(declare resize-dim-rect) +(declare resize-dim-circle) + +(defn resize-dim + "Resize using calculated dimensions (eg, `width` and `height`) + instead of absolute positions." + [shape opts] + (case (:type shape) + :rect (resize-dim-rect shape opts) + :icon (resize-dim-rect shape opts) + :circle (resize-dim-circle shape opts))) + +(defn- resize-dim-rect + [{:keys [proportion proportion-lock x1 y1] :as shape} + {:keys [width height]}] + {:pre [(not (and width height))]} + (if-not proportion-lock + (if width + (assoc shape :x2 (+ x1 width)) + (assoc shape :y2 (+ y1 height))) + (if width + (-> shape + (assoc :x2 (+ x1 width)) + (assoc :y2 (+ y1 (/ width proportion)))) + (-> shape + (assoc :y2 (+ y1 height)) + (assoc :x2 (+ x1 (* height proportion))))))) + +(defn- resize-dim-circle + [{:keys [proportion proportion-lock] :as shape} + {:keys [rx ry]}] + {:pre [(not (and rx ry))]} + (if-not proportion-lock + (if rx + (assoc shape :rx rx) + (assoc shape :ry ry)) + (if rx + (-> shape + (assoc :rx rx) + (assoc :ry (/ rx proportion))) + (-> shape + (assoc :ry ry) + (assoc :rx (* ry proportion)))))) + ;; --- Resize (Absolute) (declare resize-rect)