Mercurial > hg > indyvon
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 diff
1.1 --- a/src/indyvon/views.clj Tue Nov 07 02:07:11 2017 +0300 1.2 +++ b/src/indyvon/views.clj Mon Nov 20 16:50:00 2017 +0300 1.3 @@ -1,5 +1,5 @@ 1.4 ;; 1.5 -;; Copyright 2010-2015 Mikhail Kryshen <mikhail@kryshen.net> 1.6 +;; Copyright 2010-2017 Mikhail Kryshen <mikhail@kryshen.net> 1.7 ;; 1.8 ;; This file is part of Indyvon. 1.9 ;; 1.10 @@ -190,7 +190,8 @@ 1.11 [& contents] 1.12 (vbox* true contents)) 1.13 1.14 -(defrecord BorderBox [north west south east center] 1.15 +(defrecord BorderBox [north west south east center 1.16 + ^boolean center-anchor?] 1.17 View 1.18 (render! [_] 1.19 (let [w *width* 1.20 @@ -217,10 +218,13 @@ 1.21 l (width wg ch) 1.22 r (width eg ch) 1.23 w (max (+ cw l r) (width ng) (width sg)) 1.24 + cw (- w l r) 1.25 t (height ng w) 1.26 b (height sg w) 1.27 h (+ ch t b)] 1.28 - (->Size w h)))) 1.29 + (if center-anchor? 1.30 + (->NestedGeometry (->Size cw ch) t l b r) 1.31 + (->Size w h))))) 1.32 1.33 (defn border-box 1.34 "reginonviews => region-key view 1.35 @@ -228,12 +232,13 @@ 1.36 regions (:north, :south, :east, :west, and 1.37 :center). Each region may contain no more than one View." 1.38 [& regionviews] 1.39 - (let [regions (apply array-map regionviews)] 1.40 - (->BorderBox (:north regions empty-view) 1.41 - (:west regions empty-view) 1.42 - (:south regions empty-view) 1.43 - (:east regions empty-view) 1.44 - (:center regions empty-view)))) 1.45 + (let [opts (apply array-map regionviews)] 1.46 + (->BorderBox (:north opts empty-view) 1.47 + (:west opts empty-view) 1.48 + (:south opts empty-view) 1.49 + (:east opts empty-view) 1.50 + (:center opts empty-view) 1.51 + (:center-anchor? opts false)))) 1.52 1.53 (defn- re-split [^java.util.regex.Pattern re s] 1.54 (seq (.split re s)))