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 diff
     1.1 --- a/src/net/kryshen/indyvon/layers.clj	Mon Aug 30 20:44:23 2010 +0400
     1.2 +++ b/src/net/kryshen/indyvon/layers.clj	Mon Aug 30 21:56:14 2010 +0400
     1.3 @@ -98,6 +98,23 @@
     1.4             (.fillRect *graphics* 0 0 *width* *height*))
     1.5           (render! layer)))))
     1.6  
     1.7 +(defn hbox
     1.8 +  "Creates layer that draws the specified content layers placing them
     1.9 +   horizontally."
    1.10 +  [& contents]
    1.11 +  (reify
    1.12 +   Layer
    1.13 +   (render! [_]
    1.14 +      ;; TODO: distribute space proportionally.
    1.15 +      (let [w (/ *width* (count contents))]
    1.16 +        (doseq [[i c] (map-indexed vector contents)]
    1.17 +          (draw! c (* i w) 0 w *height*))))
    1.18 +   (layer-size [_]
    1.19 +      (reduce #(Size. (+ (:width %1) (:width %2))
    1.20 +                      (max (:height %1) (:height %2)))
    1.21 +              (Size. 0 0)
    1.22 +              (map layer-size contents)))))
    1.23 +
    1.24  (defn- re-split [^java.util.regex.Pattern re s]
    1.25    (seq (.split re s)))
    1.26