changeset 184:292d885a5a7b

BorderBox: added an option to use anchor points of the center view.
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 20 Nov 2017 16:50:00 +0300
parents a43e3c9b007e
children 83241889daac
files src/indyvon/views.clj
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/indyvon/views.clj	Tue Nov 07 02:07:11 2017 +0300
+++ b/src/indyvon/views.clj	Mon Nov 20 16:50:00 2017 +0300
@@ -1,5 +1,5 @@
 ;;
-;; Copyright 2010-2015 Mikhail Kryshen <mikhail@kryshen.net>
+;; Copyright 2010-2017 Mikhail Kryshen <mikhail@kryshen.net>
 ;;
 ;; This file is part of Indyvon.
 ;;
@@ -190,7 +190,8 @@
   [& contents]
   (vbox* true contents))
 
-(defrecord BorderBox [north west south east center]
+(defrecord BorderBox [north west south east center
+                      ^boolean center-anchor?]
   View
   (render! [_]
     (let [w *width*
@@ -217,10 +218,13 @@
           l (width wg ch)
           r (width eg ch)
           w (max (+ cw l r) (width ng) (width sg))
+          cw (- w l r)
           t (height ng w)
           b (height sg w)
           h (+ ch t b)]
-      (->Size w h))))
+      (if center-anchor?
+        (->NestedGeometry (->Size cw ch) t l b r)
+        (->Size w h)))))
 
 (defn border-box
   "reginonviews => region-key view
@@ -228,12 +232,13 @@
   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))))
+  (let [opts (apply array-map regionviews)]
+    (->BorderBox (:north opts empty-view)
+                 (:west opts empty-view)
+                 (:south opts empty-view)
+                 (:east opts empty-view)
+                 (:center opts empty-view)
+                 (:center-anchor? opts false))))
 
 (defn- re-split [^java.util.regex.Pattern re s]
   (seq (.split re s)))