From 0c8d8d92bab538262b4837c57652dfd7ed7eefc8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 29 Mar 2023 16:50:21 +0200 Subject: [PATCH 1/3] :bug: Fix precision for wrap in flex --- CHANGES.md | 1 + common/src/app/common/geom/shapes/flex_layout/lines.cljc | 6 ++++-- common/src/app/common/math.cljc | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a1033b537e..2b9527806b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -73,6 +73,7 @@ - Fix last update project timer update after creating new file [Taiga #5096](https://tree.taiga.io/project/penpot/issue/5096) - Fix dashboard scrolling using 'Page Up' and 'Page Down' [Taiga #5081](https://tree.taiga.io/project/penpot/issue/5081) - Fix view mode header buttons overlapping in small resolutions [Taiga #5058](https://tree.taiga.io/project/penpot/issue/5058) +- Fix precision for wrap in flex [Taiga #5072](https://tree.taiga.io/project/penpot/issue/5072) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/common/src/app/common/geom/shapes/flex_layout/lines.cljc b/common/src/app/common/geom/shapes/flex_layout/lines.cljc index b5d89c3785..3692e9fb43 100644 --- a/common/src/app/common/geom/shapes/flex_layout/lines.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/lines.cljc @@ -104,8 +104,10 @@ (if (and (some? line-data) (or (not wrap?) - (and row? (<= next-line-min-width layout-width)) - (and col? (<= next-line-min-height layout-height)))) + (and row? (or (< next-line-min-width layout-width) + (mth/close? next-line-min-width layout-width 0.5))) + (and col? (or (< next-line-min-height layout-height) + (mth/close? next-line-min-height layout-height 0.5))))) (recur {:line-min-width (if row? (+ line-min-width next-min-width) (max line-min-width next-min-width)) :line-max-width (if row? (+ line-max-width next-max-width) (max line-max-width next-max-width)) diff --git a/common/src/app/common/math.cljc b/common/src/app/common/math.cljc index d3f724ee9a..0adc340beb 100644 --- a/common/src/app/common/math.cljc +++ b/common/src/app/common/math.cljc @@ -185,8 +185,10 @@ (defn close? "Equality for float numbers. Check if the difference is within a range" - [num1 num2] - (<= (abs (- num1 num2)) float-equal-precision)) + ([num1 num2] + (close? num1 num2 float-equal-precision)) + ([num1 num2 precision] + (<= (abs (- num1 num2)) precision))) (defn lerp "Calculates a the linear interpolation between two values and a given percent" From 532caea169b7d8988564774153babc9635d21db5 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 30 Mar 2023 15:51:01 +0200 Subject: [PATCH 2/3] :bug: Fix relative position overlay positioning --- CHANGES.md | 1 + frontend/src/app/main/ui/viewer/shapes.cljs | 135 +++++++++++--------- 2 files changed, 73 insertions(+), 63 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2b9527806b..4a05df7f62 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -74,6 +74,7 @@ - Fix dashboard scrolling using 'Page Up' and 'Page Down' [Taiga #5081](https://tree.taiga.io/project/penpot/issue/5081) - Fix view mode header buttons overlapping in small resolutions [Taiga #5058](https://tree.taiga.io/project/penpot/issue/5058) - Fix precision for wrap in flex [Taiga #5072](https://tree.taiga.io/project/penpot/issue/5072) +- Fix relative position overlay positioning [Taiga #5092](https://tree.taiga.io/project/penpot/issue/5092) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index ffc33bfbed..99c59c22c6 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.viewer.shapes "The main container for a frame in viewer mode" (:require + [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.pages.helpers :as cph] [app.common.types.shape.interactions :as ctsi] @@ -46,80 +47,88 @@ (defn- activate-interaction [interaction shape base-frame frame-offset objects overlays] - (case (:action-type interaction) - :navigate - (when-let [frame-id (:destination interaction)] - (let [viewer-section (dom/get-element "viewer-section") - scroll (if (:preserve-scroll interaction) - (dom/get-scroll-pos viewer-section) - 0)] - (st/emit! (dv/set-nav-scroll scroll) - (dv/go-to-frame frame-id (:animation interaction))))) - :open-overlay - (let [dest-frame-id (:destination interaction) - viewer-objects (deref (refs/get-viewer-objects)) - dest-frame (get viewer-objects dest-frame-id) - relative-to-id (if (= :manual (:overlay-pos-type interaction)) - (:id shape) ;; manual interactions are allways from "self" - (:position-relative-to interaction)) - relative-to-shape (or (get objects relative-to-id) base-frame) - close-click-outside (:close-click-outside interaction) - background-overlay (:background-overlay interaction) - overlays-ids (set (map :id overlays)) - relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame) - position (ctsi/calc-overlay-position interaction - viewer-objects - relative-to-shape - relative-to-base-frame - dest-frame - frame-offset)] - (when dest-frame-id - (st/emit! (dv/open-overlay dest-frame-id - position - close-click-outside - background-overlay - (:animation interaction))))) + (let [;; When the interactive item is inside a nested frame we need to add to the offset the position + ;; of the parent-frame otherwise the position won't match + shape-frame (cph/get-frame objects shape) - :toggle-overlay - (let [frame-id (:destination interaction) - dest-frame (get objects frame-id) - relative-to-id (if (= :manual (:overlay-pos-type interaction)) - (:id shape) ;; manual interactions are allways from "self" - (:position-relative-to interaction)) - relative-to-shape (or (get objects relative-to-id) base-frame) - overlays-ids (set (map :id overlays)) - relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame) - position (ctsi/calc-overlay-position interaction - objects - relative-to-shape - relative-to-base-frame - dest-frame - frame-offset) + frame-offset (if (or (cph/root-frame? shape-frame) (cph/root? shape-frame)) + frame-offset + (gpt/add frame-offset (gpt/point shape-frame)))] + (case (:action-type interaction) + :navigate + (when-let [frame-id (:destination interaction)] + (let [viewer-section (dom/get-element "viewer-section") + scroll (if (:preserve-scroll interaction) + (dom/get-scroll-pos viewer-section) + 0)] + (st/emit! (dv/set-nav-scroll scroll) + (dv/go-to-frame frame-id (:animation interaction))))) - close-click-outside (:close-click-outside interaction) - background-overlay (:background-overlay interaction)] - (when frame-id - (st/emit! (dv/toggle-overlay frame-id + :open-overlay + (let [dest-frame-id (:destination interaction) + viewer-objects (deref (refs/get-viewer-objects)) + dest-frame (get viewer-objects dest-frame-id) + relative-to-id (if (= :manual (:overlay-pos-type interaction)) + (:id shape) ;; manual interactions are allways from "self" + (:position-relative-to interaction)) + relative-to-shape (or (get objects relative-to-id) base-frame) + close-click-outside (:close-click-outside interaction) + background-overlay (:background-overlay interaction) + overlays-ids (set (map :id overlays)) + relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame) + position (ctsi/calc-overlay-position interaction + viewer-objects + relative-to-shape + relative-to-base-frame + dest-frame + frame-offset)] + (when dest-frame-id + (st/emit! (dv/open-overlay dest-frame-id position close-click-outside background-overlay (:animation interaction))))) - :close-overlay - (let [frame-id (or (:destination interaction) - (if (= (:type shape) :frame) - (:id shape) - (:frame-id shape)))] - (st/emit! (dv/close-overlay frame-id (:animation interaction)))) + :toggle-overlay + (let [frame-id (:destination interaction) + dest-frame (get objects frame-id) + relative-to-id (if (= :manual (:overlay-pos-type interaction)) + (:id shape) ;; manual interactions are allways from "self" + (:position-relative-to interaction)) + relative-to-shape (or (get objects relative-to-id) base-frame) + overlays-ids (set (map :id overlays)) + relative-to-base-frame (find-relative-to-base-frame relative-to-shape objects overlays-ids base-frame) + position (ctsi/calc-overlay-position interaction + objects + relative-to-shape + relative-to-base-frame + dest-frame + frame-offset) - :prev-screen - (st/emit! (rt/nav-back-local)) + close-click-outside (:close-click-outside interaction) + background-overlay (:background-overlay interaction)] + (when frame-id + (st/emit! (dv/toggle-overlay frame-id + position + close-click-outside + background-overlay + (:animation interaction))))) - :open-url - (st/emit! (dom/open-new-window (:url interaction))) + :close-overlay + (let [frame-id (or (:destination interaction) + (if (= (:type shape) :frame) + (:id shape) + (:frame-id shape)))] + (st/emit! (dv/close-overlay frame-id (:animation interaction)))) - nil)) + :prev-screen + (st/emit! (rt/nav-back-local)) + + :open-url + (st/emit! (dom/open-new-window (:url interaction))) + + nil))) ;; Perform the opposite action of an interaction, if possible (defn- deactivate-interaction From 64c027355458b07cf72d400c9a6cfe06e5f13b62 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 30 Mar 2023 16:15:19 +0200 Subject: [PATCH 3/3] :bug: Fix problem when reorder layers removes show in viewer --- frontend/src/app/main/data/workspace.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index ec0f3db00a..1121279d73 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -664,7 +664,8 @@ (pcb/update-shapes ordered-indexes ctl/remove-layout-item-data)) ;; Remove the hide in viewer flag - (pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true))) + (cond-> (and (not= uuid/zero parent-id) (cph/frame-shape? objects parent-id)) + (pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))) ;; Move the shapes (pcb/change-parent parent-id