Mercurial > hg > indyvon
changeset 163:dc3ed475c6d6
Added views/border-box.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Mon, 24 Nov 2014 02:17:54 +0300 |
parents | 4aa8979938ee |
children | d91a7e0388da |
files | src/indyvon/views.clj |
diffstat | 1 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/indyvon/views.clj Mon Nov 24 02:09:13 2014 +0300 +++ b/src/indyvon/views.clj Mon Nov 24 02:17:54 2014 +0300 @@ -165,6 +165,51 @@ (defn vbox-proportional [& contents] (vbox* true contents)) +(defrecord BorderBox [north west south east center] + View + (render! [_] + (let [w *width* + h *height* + t (height (geometry north) w) + b (height (geometry south) w) + ch (- h t b) + l (width (geometry west) ch) + r (width (geometry east) ch) + cw (- w l r)] + (draw! north 0 0 w t) + (draw! west 0 t l ch) + (draw! south 0 (- h b) w b) + (draw! east (- w r) t r ch) + (draw! center l t cw ch))) + (geometry [_] + (let [ng (geometry north) + wg (geometry west) + sg (geometry south) + eg (geometry east) + cg (geometry center) + cw (width cg) + ch (max (height cg) (height wg) (height eg)) + l (width wg ch) + r (width eg ch) + w (max (+ cw l r) (width ng) (width sg)) + t (height ng w) + b (height sg w) + h (+ ch t b)] + (->Size w h)))) + +(defn border-box + "reginonviews => region-key view + Returns a View that organizes specified Views in five + regions (:north, :south, :east, :west, and + :center). Each region may contain no more than one View." + [& regionviews] + (let [regions (apply array-map regionviews)] + (->BorderBox (:north regions empty-view) + (:west regions empty-view) + (:south regions empty-view) + (:east regions empty-view) + (:center regions empty-view)))) + (defn- re-split [^java.util.regex.Pattern re s] (seq (.split re s)))