Ad Hoc Stylesheets in Seesaw
Following up on my last post, I decided to try that distributed pi calculation in Clojure. That’s not going so great, mostly due to my own weak sauce. Luckily, it’s not the subject of this post.
While I was doing that, I kind of got sidetracked into making a little UI that shows the estimate for pi over time, using Seesaw of course. As I fiddled with the look (UIs are such a timehole), I realized I already had the building blocks for rudimentary stylesheet support. I wrote a simple function that iterates over a map (the “stylesheet”), looks up widgets with selectors, and then applies styling using the
(defn apply-stylesheet [root stylesheet] (doseq [[sel style] stylesheet] (apply config! (select root sel) (reduce concat style))) root)
Yes, it’s still ugly, but I never claimed to be a designer :)
Here’s the full code which uses Seesaw 1.0.7. Note that I can style classes of widgets (e.g. JButton) as well as individual widgets by id.
If you see no code, look here
Note that I’ve omitted my abomination of a pi calculation. The Clojure mailing list will probably hear from me shortly :)