MrHus / Cloui

A clojure ui framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is Cloui

Cloui is a simple Swing wrapper for Clojure. The goal of the project is to make creating small Swing apps more Clojure like. That means less syntax and a more declarative style.

Sample

Here's a simple celsius -> kelvin converter in Clojure using Cloui:

(ns converter
(:use :reload-all cloui.core)
(:use :reload-all cloui.listeners))

(defn fahrenheit-to-celcius
  [v]
  (/ (- v 32) 1.8))

(defn celcius-to-fahrenheit
  [v]
  (+ (* 1.8 v) 32))

(defn parse [s]
  (try (Double/parseDouble (.trim s))
    (catch NumberFormatException e nil)))

(defn convert
  "Call the convert based on the source of the event"
  [event txtf txtc]
  (if (= (.getSource event) txtf)
    (.setText txtc (str (fahrenheit-to-celcius (parse (.getText txtf)))))
    (.setText txtf (str (celcius-to-fahrenheit (parse (.getText txtc)))))))

(def lblf (label :text "Fahrenheit: "))
(def txtf (textfield :columns 20))

(def lblc (label :text "Celcius: "))
(def txtc (textfield :columns 20))

(def lst (key-listener :released  (convert event txtf txtc)))  

(listen [txtf txtc] lst)

(def pnl (panel :components [lblf txtf lblc txtc]))

(defn gui
  []
  (frame :panel pnl, :onclose :exit, :size [300 500], :center true, :title "Cloverter"))    

(defn -main 
  "Launch the converter gui"
  [& args]
  (gui))  

Install guide

Via leiningen add [cloui "1.0"] to your dependencies.

Roadmap

  • Manage Layouts
  • JRadioButton
  • JComboBox
  • JDialog
  • JPasswordField
  • JProgressBar
  • JTextArea
  • JTip

About

A clojure ui framework

License:Other


Languages

Language:Clojure 100.0%