forked from cljfx/cljfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe26_tooltips.clj
47 lines (42 loc) · 1.71 KB
/
e26_tooltips.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns e26-tooltips
(:require [cljfx.api :as fx]
[cljfx.ext.node :as fx.ext.node])
(:import [javafx.scene.input ScrollEvent]))
;; Hover over circle, observe tooltip indicating radius, scroll to change it
;; Note that this tooltip configuration only needed for non-control tooltips, because
;; controls have `:tooltip` prop which makes it easier to specify tooltips for them
(def *radius
(atom 20))
(defn- circle-view [{:keys [radius]}]
{:fx/type fx.ext.node/with-tooltip-props
:props {:tooltip {:fx/type :tooltip
;; jdk 11 only
;:show-duration [1 :h]
:text (str "My radius is " radius)}}
:desc {:fx/type :circle
:radius radius
:on-scroll {:event/type ::scroll}}})
(def renderer
(fx/create-renderer
:middleware
(fx/wrap-map-desc
(fn [radius]
{:fx/type :stage
:showing true
:width 250
:height 250
:scene {:fx/type :scene
:root {:fx/type :v-box
:alignment :center
:children [{:fx/type circle-view
:radius radius}]}}}))
:opts
{:fx.opt/map-event-handler (fn [{:keys [event/type ^ScrollEvent fx/event]}]
(case type
::scroll
(swap! *radius (fn [radius]
(-> radius
(+ (/ (.getDeltaY event) 10))
(min 100)
(max 10))))))}))
(fx/mount-renderer *radius renderer)