Skip to content

Commit

Permalink
simplify bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Jan 31, 2024
1 parent 614fc3a commit 1dd533a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/renderer/tools/box.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/tools/container.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/tools/group.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
11 changes: 0 additions & 11 deletions src/renderer/tools/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 1 addition & 13 deletions src/renderer/tools/svg.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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})))

0 comments on commit 1dd533a

Please sign in to comment.