mirror of
https://github.com/penpot/penpot.git
synced 2025-05-08 00:15:54 +02:00
✨ Add cursor tooltips.
This commit is contained in:
parent
6988f0a35e
commit
a0a76f6b65
5 changed files with 48 additions and 24 deletions
|
@ -721,6 +721,12 @@
|
||||||
"fr" : "Mettre à jour les paramètres"
|
"fr" : "Mettre à jour les paramètres"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"workspace.viewport.click-to-close-path": {
|
||||||
|
"translations": {
|
||||||
|
"en": "Click to close the path"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"workspace.header.canvas" : {
|
"workspace.header.canvas" : {
|
||||||
"used-in" : [ "src/uxbox/main/ui/workspace/header.cljs:95" ],
|
"used-in" : [ "src/uxbox/main/ui/workspace/header.cljs:95" ],
|
||||||
"translations" : {
|
"translations" : {
|
||||||
|
|
|
@ -734,9 +734,16 @@
|
||||||
(rx/of (deactivate-flag flag))
|
(rx/of (deactivate-flag flag))
|
||||||
(rx/of (activate-flag flag)))))))
|
(rx/of (activate-flag flag)))))))
|
||||||
|
|
||||||
(defn set-tooltip
|
;; --- Tooltip
|
||||||
[txt]
|
|
||||||
::todo)
|
(defn assign-cursor-tooltip
|
||||||
|
[content]
|
||||||
|
(ptk/reify ::assign-cursor-tooltip
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(if (string? content)
|
||||||
|
(assoc-in state [:workspace-local :tooltip] content)
|
||||||
|
(assoc-in state [:workspace-local :tooltip] nil)))))
|
||||||
|
|
||||||
;; --- Workspace Ruler
|
;; --- Workspace Ruler
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
[uxbox.util.geom.matrix :as gmt]
|
[uxbox.util.geom.matrix :as gmt]
|
||||||
[uxbox.util.geom.path :as path]
|
[uxbox.util.geom.path :as path]
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
|
[uxbox.util.i18n :as i18n :refer [t]]
|
||||||
[uxbox.util.uuid :as uuid]))
|
[uxbox.util.uuid :as uuid]))
|
||||||
|
|
||||||
;; --- Events
|
;; --- Events
|
||||||
|
@ -319,16 +320,23 @@
|
||||||
|
|
||||||
(mf/defc path-draw-area
|
(mf/defc path-draw-area
|
||||||
[{:keys [shape] :as props}]
|
[{:keys [shape] :as props}]
|
||||||
(letfn [(on-click [event]
|
(let [locale (i18n/use-locale)
|
||||||
(dom/stop-propagation event)
|
|
||||||
(st/emit! (dw/set-tooltip nil)
|
|
||||||
close-drawing-path
|
|
||||||
::end-path-drawing))
|
|
||||||
|
|
||||||
(on-mouse-enter [event]
|
on-click
|
||||||
(st/emit! (dw/set-tooltip "Click to close the path")))
|
(fn [event]
|
||||||
(on-mouse-leave [event]
|
(dom/stop-propagation event)
|
||||||
(st/emit! (dw/set-tooltip nil)))]
|
(st/emit! (dw/assign-cursor-tooltip nil)
|
||||||
|
close-drawing-path
|
||||||
|
::end-path-drawing))
|
||||||
|
|
||||||
|
on-mouse-enter
|
||||||
|
(fn [event]
|
||||||
|
(let [msg (t locale "workspace.viewport.click-to-close-path")]
|
||||||
|
(st/emit! (dw/assign-cursor-tooltip msg))))
|
||||||
|
|
||||||
|
on-mouse-leave
|
||||||
|
(fn [event]
|
||||||
|
(st/emit! (dw/assign-cursor-tooltip nil)))]
|
||||||
(when-let [{:keys [x y] :as segment} (first (:segments shape))]
|
(when-let [{:keys [x y] :as segment} (first (:segments shape))]
|
||||||
[:g
|
[:g
|
||||||
[:& shapes/shape-wrapper {:shape shape}]
|
[:& shapes/shape-wrapper {:shape shape}]
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
(letfn [(on-mouse-down [event]
|
(letfn [(on-mouse-down [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(st/emit! :interrupt
|
(st/emit! :interrupt
|
||||||
(udw/set-tooltip nil)
|
(udw/assign-cursor-tooltip nil)
|
||||||
(udw/start-ruler)))
|
(udw/start-ruler)))
|
||||||
(on-mouse-up [event]
|
(on-mouse-up [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
|
|
|
@ -46,6 +46,16 @@
|
||||||
[:span {:alt "y"}
|
[:span {:alt "y"}
|
||||||
(str "Y: " (:y coords "-"))]]))
|
(str "Y: " (:y coords "-"))]]))
|
||||||
|
|
||||||
|
(mf/defc cursor-tooltip
|
||||||
|
[{:keys [zoom tooltip] :as props}]
|
||||||
|
(let [coords (some-> (use-rxsub ms/mouse-position)
|
||||||
|
(gpt/divide (gpt/point zoom zoom)))
|
||||||
|
pos-x (- (:x coords) 100)
|
||||||
|
pos-y (+ (:y coords) 30)]
|
||||||
|
[:g {:transform (str "translate(" pos-x "," pos-y ")")}
|
||||||
|
[:foreignObject {:width 200 :height 100 :style {:text-align "center"}}
|
||||||
|
[:span tooltip]]]))
|
||||||
|
|
||||||
;; --- Cursor tooltip
|
;; --- Cursor tooltip
|
||||||
|
|
||||||
(defn- get-shape-tooltip
|
(defn- get-shape-tooltip
|
||||||
|
@ -60,17 +70,6 @@
|
||||||
:circle "Drag to draw a Circle"
|
:circle "Drag to draw a Circle"
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
;; (mf/defc cursor-tooltip
|
|
||||||
;; {:wrap [mf/wrap-memo]}
|
|
||||||
;; [{:keys [tooltip]}]
|
|
||||||
;; (let [coords (mf/deref refs/window-mouse-position)]
|
|
||||||
;; [:span.cursor-tooltip
|
|
||||||
;; {:style
|
|
||||||
;; {:position "fixed"
|
|
||||||
;; :left (str (+ (:x coords) 5) "px")
|
|
||||||
;; :top (str (- (:y coords) 25) "px")}}
|
|
||||||
;; tooltip]))
|
|
||||||
|
|
||||||
;; --- Selection Rect
|
;; --- Selection Rect
|
||||||
|
|
||||||
(defn- selection->rect
|
(defn- selection->rect
|
||||||
|
@ -166,6 +165,7 @@
|
||||||
zoom
|
zoom
|
||||||
flags
|
flags
|
||||||
edition
|
edition
|
||||||
|
tooltip
|
||||||
selected]
|
selected]
|
||||||
:as local} (mf/deref refs/workspace-local)
|
:as local} (mf/deref refs/workspace-local)
|
||||||
viewport-ref (mf/use-ref nil)
|
viewport-ref (mf/use-ref nil)
|
||||||
|
@ -291,6 +291,9 @@
|
||||||
(if (contains? flags :grid)
|
(if (contains? flags :grid)
|
||||||
[:& grid])]
|
[:& grid])]
|
||||||
|
|
||||||
|
(when tooltip
|
||||||
|
[:& cursor-tooltip {:zoom zoom :tooltip tooltip}])
|
||||||
|
|
||||||
(when (contains? flags :ruler)
|
(when (contains? flags :ruler)
|
||||||
[:& ruler {:zoom zoom :ruler (:ruler local)}])
|
[:& ruler {:zoom zoom :ruler (:ruler local)}])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue