diff --git a/CHANGES.md b/CHANGES.md index bfb0cff51..338296b4f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,12 @@ ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) + +## 1.13.5-beta + +### :bug: Bugs fixed +- Fix orientation artboard preset not working with differently sized artboards [Taiga #3548](https://tree.taiga.io/project/penpot/issue/3548) + ## 1.13.4-beta ### :bug: Bugs fixed diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index c9b919ba2..ed5c52aa9 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -166,6 +166,7 @@ (dm/export gtr/update-group-selrect) (dm/export gtr/update-mask-selrect) (dm/export gtr/resize-modifiers) +(dm/export gtr/change-orientation-modifiers) (dm/export gtr/rotation-modifiers) (dm/export gtr/merge-modifiers) (dm/export gtr/transform-shape) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index cd0a707b6..6fd41c01a 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -426,6 +426,31 @@ :resize-transform shape-transform :resize-transform-inverse shape-transform-inv})) +(defn change-orientation-modifiers + [shape orientation] + (us/assert map? shape) + (us/verify #{:horiz :vert} orientation) + (let [width (:width shape) + height (:height shape) + new-width (if (= orientation :horiz) (max width height) (min width height)) + new-height (if (= orientation :horiz) (min width height) (max width height)) + + shape-transform (:transform shape) + shape-transform-inv (:transform-inverse shape) + shape-center (gco/center-shape shape) + {sr-width :width sr-height :height} (:selrect shape) + + origin (cond-> (gpt/point (:selrect shape)) + (some? shape-transform) + (transform-point-center shape-center shape-transform)) + + scalev (gpt/divide (gpt/point new-width new-height) + (gpt/point sr-width sr-height))] + {:resize-vector scalev + :resize-origin origin + :resize-transform shape-transform + :resize-transform-inverse shape-transform-inv})) + (defn rotation-modifiers [shape center angle] (let [displacement (let [shape-center (gco/center-shape shape)] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 951f5dae9..6ada6cc96 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1698,6 +1698,7 @@ (dm/export dwt/start-resize) (dm/export dwt/update-dimensions) +(dm/export dwt/change-orientation) (dm/export dwt/start-rotate) (dm/export dwt/increase-rotation) (dm/export dwt/start-move-selected) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index c73384c54..0ae4229f9 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -556,6 +556,32 @@ (watch [_ _ _] (rx/of (apply-modifiers ids))))) +(defn change-orientation + "Change orientation of shapes, from the sidebar options form. + Will ignore pixel snap used in the options side panel" + [ids orientation] + (us/verify (s/coll-of ::us/uuid) ids) + (us/verify #{:horiz :vert} orientation) + (ptk/reify ::change-orientation + ptk/UpdateEvent + (update [_ state] + (let [objects (wsh/lookup-page-objects state) + layout (get state :workspace-layout) + snap-pixel? (contains? layout :snap-pixel-grid) + + update-modifiers + (fn [state id] + (let [shape (get objects id) + modifiers (gsh/change-orientation-modifiers shape orientation)] + (-> state + (update :workspace-modifiers + #(set-objects-modifiers % objects shape modifiers false snap-pixel?)))))] + (reduce update-modifiers state ids))) + + ptk/WatchEvent + (watch [_ _ _] + (rx/of (apply-modifiers ids))))) + ;; -- Rotate -------------------------------------------------------- (defn start-rotate @@ -786,7 +812,7 @@ (rx/of (apply-modifiers selected) (finish-transform)))) - (rx/empty)))))) + (rx/empty)))))) (s/def ::x number?) (s/def ::y number?) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index 58d4bc2d4..0977b1a63 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -110,12 +110,7 @@ on-orientation-clicked (fn [orientation] - (let [width (:width values) - height (:height values) - new-width (if (= orientation :horiz) (max width height) (min width height)) - new-height (if (= orientation :horiz) (min width height) (max width height))] - (st/emit! (udw/update-dimensions ids :width new-width) - (udw/update-dimensions ids :height new-height)))) + (st/emit! (udw/change-orientation ids orientation))) on-size-change (mf/use-callback