             :submorphs []},
             20])
 
-(defn render-bubble [origin r fill]
-  {:morph {:Position origin}
+(defn render-bubble [origin r fill branch]
+  { :id (if (contains? branch :id) (branch :id) (get-in branch [:root :id]))
+    :morph {:Position origin
+           :onClick (fn [this]
+                      (branch-merge/select-for-merge 
+                        (if (contains? branch :id) branch (branch :root))
+                        (fn [a b]
+                          (let [[fp pa pb] (branch-merge/fork-point a b @rendered-tree)]
+                            (visualize-merge-candidates fp pa pb))))
+                      (let [fill (if (= (get-in this [:shape :Fill]) "red") 
+                                    (do
+                                      ; (remove-morph branch-view (this :id) (str "box-" (this :id)))
+                                      "green")
+                                    (let [textfield { :id (str "box-" (this :id))
+                                                      :morph {:Position {:x 15 :y -3} 
+                                                             :MorphClass "Text" 
+                                                             :TextString (str (this :id))}
+                                                      :shape {:ShapeClass "Text"}}]
+                                       (add-morph branch-view (this :id) textfield)
+                                       "red"))]
+                        (set-fill branch-view (this :id) fill))
+                      false)}
    :shape {:ShapeClass "Ellipse"
            :Extent {:x r :y r}
-           :Fill fill}})
+           :Fill fill}
+   :submorphs []})
 
 (defn render-leaf [cont start-point]
-  (let [fill (if (is-on-current cont) "green" "black")]
+  (let [fill (get-coloring cont)]
     [{ ; id nessecary? not for now... we do not alter the morph structure but just rerender it completely
       :morph {:MorphClass "Path"
               :Position start-point
-              :onClick (fn [e] 
+              :onClick (fn [this] 
                           (if (contains? cont :root)
                             (let [b (cont :root)]
-                              (prn "switching via leaf click to branch: " (b :id))
                               (@branch-callback-fn b))
                             (let [b cont]
-                              (prn "switching via stub leaf click to branch: " (b :id))
                               (@branch-callback-fn b)))
                           false)}
       :shape {:ShapeClass "Path"
               :StrokeWidth 5
               :Fill fill
-              :PathElements [{:x 0 :y 0} {:x (count @(cont :data)) :y 0}]}
-              :submorphs [(render-bubble {:x (count @(cont :data)) :y -1} 10 fill)]}, ; place a cute bubble at the end :-)
+              :PathElements [{:x 0 :y 0} {:x (count @(cont :data)) :y 0} ]}
+              :submorphs [(render-bubble {:x (count @(cont :data)) :y -1} 10 fill cont)]}, ; place a cute bubble at the end :-)
               20]))
 
 (defn smoothen [vertices]
   ; interpolate last 2 edges, 
   ; by substituting the last 2 points with an arc
-  (prn "smoothening: " vertices)
   (let [[middle end] (take-last 2 vertices)
         half-point (- (end :x) (middle :x))
         rounded-edge {:type :arc

            (= @current-branch-ref (branch :root))))
    false))

(defn scale-branch-model [model max-width] model)

(defn render-stub [branch start-point]
  [{ ; id nessecary? not for now... we do not alter the morph structure but just rerender it completely
    :morph {:MorphClass "Path"
            :Position start-point
            :onClick (fn [e] 
                        (prn "switching via stub click to branch " (branch :id))
                        (@branch-callback-fn branch)
                        false)}
    :shape {:ShapeClass "Path"

            [om.dom :as dom :include-macros true]
            [cljs-workspace.morph 
              :as morphic 
              :refer [morph set-position set-fill set-extent add-morph remove-morph]]
            [cljs-workspace.branch-merge :as branch-merge]))

(enable-console-print!)
;; utilities to render a branching unrolled linked list
