From 60273fc6652ae4d33804308c6f9bea0d9f82dc86 Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Mon, 19 Jan 2015 14:19:19 +0000 Subject: [PATCH] 0.0.30-SNAPSHOT --- README.md | 12 ++++++++---- src/clojurefx/clojurefx.clj | 2 ++ src/clojurefx/factory.clj | 2 ++ src/clojurefx/protocols.clj | 1 + test/clojurefx/clojurefx_test.clj | 9 +++++---- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c492e7f..512acaf 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ [![License](//img.shields.io/badge/license-LGPL-blue.svg?style=flat)](https://www.gnu.org/licenses/lgpl-3.0.en.html#content) -[![Clojars](//img.shields.io/badge/clojars-0.0.21--SNAPSHOT-blue.svg?style=flat)](https://clojars.org/clojurefx/versions/0.0.21-SNAPSHOT) +[![Clojars](//img.shields.io/badge/clojars-0.0.30--SNAPSHOT-blue.svg?style=flat)](https://clojars.org/clojurefx/versions/0.0.30-SNAPSHOT) [![Gratipay](//img.shields.io/gratipay/zilti.svg?style=flat)](//gratipay.com/zilti) [![Flattr this](//api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=zilti&url=https%3A%2F%2Fbitbucket.org%2Fzilti%2Fclojurefx) # ClojureFX ```clojure -[clojurefx "0.0.21-SNAPSHOT"] +[clojurefx "0.0.30-SNAPSHOT"] ``` **Note: This is a complete rewrite, no code has been taken over from the old version on GitHub, and I'm taking a radically different approach.** @@ -24,9 +24,13 @@ This is in a very early state, so there isn't much yet. Take a look at the [Cloj ### Declarative UI programming ```clojure +(def superbutton (compile [Button {:text "Close" + :action #'close-handler}])) + (compile [VBox {:id "TopLevelVBox" :children [Label {:text "Hi!"} Label {:text "I'm ClojureFX!"} HBox {:id "HorizontalBox" - :children [Button {:text "Alright."}]}]}]) -``` \ No newline at end of file + :children [Button {:text "OK"} + superbutton]}]}]) +``` diff --git a/src/clojurefx/clojurefx.clj b/src/clojurefx/clojurefx.clj index a2e6e94..6757bea 100644 --- a/src/clojurefx/clojurefx.clj +++ b/src/clojurefx/clojurefx.clj @@ -190,9 +190,11 @@ nil) (tc-ignore (extend-protocol p/FXOnAction ButtonBase + (get-action [this] (.getOnAction ^ButtonBase this)) (set-action! [this action] (.setOnAction ^ButtonBase this (bind-event action)) this) (fire! [this] (.fire this)) MenuItem + (get-action [this] (.getOnAction ^MenuItem this)) (set-action! [this action] (.setOnAction ^ButtonBase this (bind-event action)) this) (fire! [this] (.fire this)))) diff --git a/src/clojurefx/factory.clj b/src/clojurefx/factory.clj index ecc7555..d1da330 100644 --- a/src/clojurefx/factory.clj +++ b/src/clojurefx/factory.clj @@ -37,6 +37,8 @@ :children (with-meta [#'get-subnodes #'set-subnodes!] {:argument java.util.List :parent FXParent}) ;;; FXStyleSetter / FXStyleable :style (with-meta [#'get-style #'set-style!] {:argument String :parent FXStyleable}) + ;;; FXOnAction + :action (with-meta [#'get-action #'set-action!] {:argument clojure.lang.IFn :parent FXOnAction}) ;;; FXStage :title (with-meta [#'get-title #'set-title!] {:argument String :parent FXStage}) :scene (with-meta [#'get-scene #'set-scene!] {:argument Scene :parent FXStage}) diff --git a/src/clojurefx/protocols.clj b/src/clojurefx/protocols.clj index 9ba0fc0..1ae67e3 100644 --- a/src/clojurefx/protocols.clj +++ b/src/clojurefx/protocols.clj @@ -65,6 +65,7 @@ (defprotocol [[A :variance :covariant]] FXOnAction + (get-action [this :- A] :- [javafx.event.EventHandler -> Any]) (set-action! [this :- A action :- [javafx.event.EventHandler -> Any]] :- A) (fire! [this :- A] :- nil)) diff --git a/test/clojurefx/clojurefx_test.clj b/test/clojurefx/clojurefx_test.clj index a3d62de..cce9269 100644 --- a/test/clojurefx/clojurefx_test.clj +++ b/test/clojurefx/clojurefx_test.clj @@ -11,13 +11,14 @@ ;;## Element testing ;;## Event testing -(def button (new Button)) +;;(def button (new Button)) +(def button (atom nil)) (def fired? (atom false)) (facts "Events" - (fact "Adding an event handler" - (set-action! button (fn [event] (reset! fired? true))) => button) + (fact "Creating button with event handler" + (class (reset! button (factory/compile [Button {:action (fn [_] (reset! fired? true))}]))) => javafx.scene.control.Button) (fact "Firing the event and checking the result" - (do (fire! button) + (do (fire! @button) @fired?) => true)) ;;## IdMapper