changeset 76:dafd4ff9d313

Added hbox.
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 30 Aug 2010 21:56:14 +0400
parents ddfde9cce39a
children 1ca7872b889b
files src/net/kryshen/indyvon/layers.clj
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/layers.clj	Mon Aug 30 20:44:23 2010 +0400
+++ b/src/net/kryshen/indyvon/layers.clj	Mon Aug 30 21:56:14 2010 +0400
@@ -98,6 +98,23 @@
            (.fillRect *graphics* 0 0 *width* *height*))
          (render! layer)))))
 
+(defn hbox
+  "Creates layer that draws the specified content layers placing them
+   horizontally."
+  [& contents]
+  (reify
+   Layer
+   (render! [_]
+      ;; TODO: distribute space proportionally.
+      (let [w (/ *width* (count contents))]
+        (doseq [[i c] (map-indexed vector contents)]
+          (draw! c (* i w) 0 w *height*))))
+   (layer-size [_]
+      (reduce #(Size. (+ (:width %1) (:width %2))
+                      (max (:height %1) (:height %2)))
+              (Size. 0 0)
+              (map layer-size contents)))))
+
 (defn- re-split [^java.util.regex.Pattern re s]
   (seq (.split re s)))