changeset 50:409b1b16053d

Code cleanup and docstrings.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 29 Jul 2010 01:28:30 +0400
parents ca728127d605
children a20b1fccc0ef
files src/net/kryshen/indyvon/component.clj src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/layers.clj
diffstat 3 files changed, 23 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/component.clj	Thu Jul 29 01:08:34 2010 +0400
+++ b/src/net/kryshen/indyvon/component.clj	Thu Jul 29 01:28:30 2010 +0400
@@ -5,6 +5,7 @@
 ;;
 
 (ns net.kryshen.indyvon.component
+  "Integrating Indyvon into AWT and Swing components."
   (:use
    net.kryshen.indyvon.core)
   (:import
--- a/src/net/kryshen/indyvon/core.clj	Thu Jul 29 01:08:34 2010 +0400
+++ b/src/net/kryshen/indyvon/core.clj	Thu Jul 29 01:28:30 2010 +0400
@@ -58,19 +58,19 @@
 (extend-protocol Anchored
   net.kryshen.indyvon.core.Layer
   (anchor [this h-align v-align]
-          (if (and (= h-align :left)
-                   (= v-align :top))
-            (Location. 0 0)
-            (let [size (layer-size this)]
-              (Location.
-               (case h-align
-                     :top 0
-                     :center (/ (:width size) 2)
-                     :right (:width size))
-               (case v-align
-                     :left 0
-                     :center (/ (:height size) 2)
-                     :bottom (:height size)))))))
+     (if (and (= h-align :left)
+              (= v-align :top))
+       (Location. 0 0)
+       (let [size (layer-size this)]
+         (Location.
+          (case h-align
+            :top 0
+            :center (/ (:width size) 2)
+            :right (:width size))
+          (case v-align
+            :left 0
+            :center (/ (:height size) 2)
+            :bottom (:height size)))))))
 
 (defn- ^Graphics2D make-graphics [^Graphics2D graphics x y w h]
   (.create graphics x y w h))
@@ -81,6 +81,7 @@
     (.setFont (:font theme))))
 
 (defn intersect
+  "Compute intersection between a pair of rectangles (Bounds)."
   ([b1 b2]
      (let [x1 (:x b1)
            y1 (:y b1)
--- a/src/net/kryshen/indyvon/layers.clj	Thu Jul 29 01:08:34 2010 +0400
+++ b/src/net/kryshen/indyvon/layers.clj	Thu Jul 29 01:28:30 2010 +0400
@@ -5,6 +5,7 @@
 ;;
 
 (ns net.kryshen.indyvon.layers
+  "Implementations of Layer protocol."
   (:use
    net.kryshen.indyvon.core)
   (:import
@@ -28,7 +29,9 @@
 (defmacro align-y [inner outer align]
   `(align-xy ~inner ~outer ~align :top :center :bottom))
 
-(defmacro decorate-layer [layer & render-tail]
+(defmacro decorate-layer
+  "Decorate Layer and Anchored replacing render! implementation."
+  [layer & render-tail]
   `(reify
     Layer
     (render! ~@render-tail)
@@ -37,6 +40,7 @@
     (anchor [t# xa# ya#] (anchor ~layer xa# ya#))))
 
 (defn padding
+  "Decorates layer adding padding."
   ([content pad]
      (padding content pad pad pad pad))
   ([content top left bottom right]
@@ -139,7 +143,7 @@
                  height (text-height layouts)]
              (Size. width height)))))))
 
-(defn- image-observer [update-fn]
+(defn- ^ImageObserver image-observer [update-fn]
   (reify
    ImageObserver
    (imageUpdate [this img infoflags x y width height]
@@ -158,8 +162,7 @@
     (reify
      Layer
      (render! [layer]
-        (.drawImage *graphics* image 0 0
-                    ^ImageObserver (image-observer *update*)))
+        (.drawImage *graphics* image 0 0 (image-observer *update*)))
      (layer-size [layer]
         (let [observer (image-observer *update*)
               width (.getWidth image observer)
@@ -212,6 +215,7 @@
 ;;
 
 (defmacro handler [layer & handlers]
+  "Decorate layer to handle events."
   `(let [layer# ~layer]
      (decorate-layer layer# [t#]
         (with-handlers t#