Last active
August 29, 2015 14:01
-
-
Save rolandoam/789df44adf67450f8461 to your computer and use it in GitHub Desktop.
text buttons & actions in play-clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defscreen main-screen | |
:on-show | |
(fn [screen entities] | |
(let [ui-skin (skin "uiskin.json") | |
;;; this is the trick, we use a proxy (http://clojure.org/java_interop#toc25) to implement a ClickListener | |
cb (proxy [ClickListener] [] | |
;;; for this object, we only care about 'clicked' | |
(clicked [evt x y] (println "clicked at " x y evt)))] | |
(update! screen :renderer (stage) :camera (orthographic)) | |
;;; add a couple of entities to the screen. We could've used a table here, but | |
;;; for testing purposes, I'm hard coding the positions. | |
;;; as a test, we use the same listener for both buttons | |
[(assoc (text-button "I'm a text button" ui-skin | |
:add-listener ^EventListener cb) | |
:x 5 :y 300) | |
(assoc (text-button "I'm another text button" ui-skin | |
:add-listener ^EventListener cb) | |
:x 5 :y 180) | |
;;; and the clojure logo, of course :) | |
(assoc (texture "clojure.png") | |
:x 50 :y 50 :width 100 :height 100)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! You can also create an
:on-ui-clicked
or:on-ui-changed
function in your defscreen. For example, my ui-gallery example uses the latter. Sorry for not documenting this; I will add all the possible defscreen functions to the docs next release.