Mercurial > hg > indyvon
changeset 166:c5b37c658161
Added ref-view argument to specify a function for converting ref value to View.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Fri, 28 Nov 2014 23:16:23 +0300 |
parents | 421dba17b7ed |
children | a51fcaf00264 |
files | src/indyvon/views.clj |
diffstat | 1 files changed, 15 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/indyvon/views.clj Wed Nov 26 19:22:52 2014 +0300 +++ b/src/indyvon/views.clj Fri Nov 28 23:16:23 2014 +0300 @@ -296,19 +296,21 @@ (def ^:dynamic *miniature-thread-priority* 2) (defn ref-view - [view-ref] - (let [l (reify - View - (render! [l] - (repaint-on-update l) - (if-let [view @view-ref] - (render! view))) - (geometry [_] - (if-let [view @view-ref] - (geometry view) - (->Size 1 1))))] - (add-watch view-ref l (fn [_ _ _ _] (update l))) - l)) + ([view-ref] + (ref-view view-ref identity)) + ([view-ref view-fn] + (let [v (reify + View + (render! [v] + (repaint-on-update v) + (when-let [view (view-fn @view-ref)] + (render! view))) + (geometry [_] + (if-let [view (view-fn @view-ref)] + (geometry view) + (->Size 1 1))))] + (add-watch view-ref v (fn [_ _ _ _] (update v))) + v))) ;; ;; View context decorators