From 1dd533a91036ae1adf9fb3cc1f9714ba0e7a3373 Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Wed, 31 Jan 2024 09:33:45 +0200 Subject: [PATCH] simplify bounds --- src/renderer/tools/box.cljs | 5 ++--- src/renderer/tools/container.cljs | 5 ----- src/renderer/tools/group.cljs | 5 +++++ src/renderer/tools/page.cljs | 11 ----------- src/renderer/tools/svg.cljs | 14 +------------- 5 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/renderer/tools/box.cljs b/src/renderer/tools/box.cljs index bfa11c4a..7b082dd9 100644 --- a/src/renderer/tools/box.cljs +++ b/src/renderer/tools/box.cljs @@ -58,9 +58,8 @@ {:x (+ x width) :y (+ y height) :key :size}])])) (defmethod tools/bounds ::tools/box - [{:keys [attrs]}] - (let [{:keys [x y width height]} attrs - [x y width height] (mapv units/unit->px [x y width height])] + [{{:keys [x y width height]} :attrs}] + (let [[x y width height] (mapv units/unit->px [x y width height])] [x y (+ x width) (+ y height)])) (defmethod tools/area ::tools/box diff --git a/src/renderer/tools/container.cljs b/src/renderer/tools/container.cljs index ac805248..bcc586e0 100644 --- a/src/renderer/tools/container.cljs +++ b/src/renderer/tools/container.cljs @@ -15,11 +15,6 @@ (derive :switch ::tools/container) (derive :symbol ::tools/container) -(defmethod tools/bounds ::tools/container - [el elements] - (let [children (vals (select-keys elements (:children el)))] - (tools/elements-bounds elements children))) - (defmethod tools/render ::tools/container [{:keys [children tag attrs]}] (let [child-elements @(rf/subscribe [:element/filter-visible children])] diff --git a/src/renderer/tools/group.cljs b/src/renderer/tools/group.cljs index b3de8e3c..015b9053 100644 --- a/src/renderer/tools/group.cljs +++ b/src/renderer/tools/group.cljs @@ -40,3 +40,8 @@ :on-pointer-up pointer-handler :on-pointer-down pointer-handler :on-pointer-move pointer-handler}]])) + +(defmethod tools/bounds :g + [el elements] + (let [children (vals (select-keys elements (:children el)))] + (tools/elements-bounds elements children))) \ No newline at end of file diff --git a/src/renderer/tools/page.cljs b/src/renderer/tools/page.cljs index 9f55385a..3be732cc 100644 --- a/src/renderer/tools/page.cljs +++ b/src/renderer/tools/page.cljs @@ -36,17 +36,6 @@ :name "Page" :attrs attrs}))) -(defmethod tools/bounds :page - [{:keys [attrs]}] - (let [{:keys [x y width height stroke-width stroke]} attrs - [x y width height stroke-width-px] (mapv units/unit->px - [x y width height stroke-width]) - stroke-width-px (if (str/blank? stroke-width) 1 stroke-width-px) - [x y] (mat/sub [x y] (/ (if (str/blank? stroke) 0 stroke-width-px) 2)) - [width height] (mat/add [width height] - (if (str/blank? stroke) 0 stroke-width-px))] - (mapv units/unit->px [x y (+ x width) (+ y height)]))) - (defmethod tools/render :page [{:keys [attrs children type] :as element}] (let [child-elements @(rf/subscribe [:element/filter-visible children]) diff --git a/src/renderer/tools/svg.cljs b/src/renderer/tools/svg.cljs index 10e5aaf2..dd9f2cdb 100644 --- a/src/renderer/tools/svg.cljs +++ b/src/renderer/tools/svg.cljs @@ -27,16 +27,4 @@ :y (min pos-y offset-y) :width (abs (- pos-x offset-x)) :height (abs (- pos-y offset-y))}] - (element.h/set-temp db {:type :element :tag :svg :attrs attrs}))) - -(defmethod tools/bounds :svg - [{:keys [attrs]}] - (let [{:keys [x y width height stroke-width stroke]} attrs - [x y width height stroke-width-px] (mapv units/unit->px - [x y width height stroke-width]) - stroke-width-px (if (str/blank? stroke-width) 1 stroke-width-px) - [x y] (mat/sub [x y] - (/ (if (str/blank? stroke) 0 stroke-width-px) 2)) - [width height] (mat/add [width height] - (if (str/blank? stroke) 0 stroke-width-px))] - (mapv units/unit->px [x y (+ x width) (+ y height)]))) + (element.h/set-temp db {:type :element :tag :svg :attrs attrs}))) \ No newline at end of file