                                                :columns 80
                                                ))
                        "span,growx"]]
-              :constraints ["fill", "[][grow][]", ""])]
-
-    ;; set up username edit to wait for user input become idle
-    (let [te-name (select form [:#username])
-          lb-log (select form [:#log])
-          active-chan (chan 1)
-          keys-chan (chan 1)
-          stop-listening (fn []
-                           ;; (log lb-log "Stopping listening\n")
-                           (go
-                            (if (<! active-chan)
-                              (do
-                                ;; important to put it back to channel immediately so others could read
-                                (>! active-chan false)
-                                (prepare-avatars (text te-name) lb-log form)
+              :constraints ["fill", "[][grow][]", ""])
+        te-name (select form [:#username])
+        lb-log (select form [:#log])
+        active-chan (chan 1)
+        keys-chan (chan 1)
+        stop-listening (fn []
+                         ;; (log lb-log "Stopping listening\n")
+                         (go
+                          (if (<! active-chan)
+                            (do
+                              ;; important to put it back to channel immediately so others could read
+                              (>! active-chan false)
+                              (prepare-avatars (text te-name) lb-log form)
                               ))))
 
-          start-listening (fn []
-                            ;;(log lb-log "Starting listening\n")
-                            (go
+        start-listening (fn []
+                          ;;(log lb-log "Starting listening\n")
+                          (go
+                           (>! active-chan true)
+                           (loop []
+                             (let [[v ch] (alts! [keys-chan (timeout 800)])]
+                               (if (not (blank? v))
+                                 (recur)
+                                 (do
+                                   ;;       (log lb-log "timeout reached\n")
+                                   (stop-listening))
+                                 ))
+                             )))]
+    ;; It is important in this scheme to return value to the channel as soon as it had been read:
+    ;; so that others interested can read back
+    (listen te-name
+            :focus-gained (fn [e]
+                            (put! active-chan false))
+
+            :document (fn [e]
+                        (go
+                         (if (<! active-chan)
+                           (do
+                             ;; important to put it back to channel immediately so others could read
                              (>! active-chan true)
-                             (loop []
-                               (let [[v ch] (alts! [keys-chan (timeout 800)])]
-                                 (if (not (blank? v))
-                                   (recur)
-                                   (do
-                              ;;       (log lb-log "timeout reached\n")
-                                     (stop-listening))
-                                   ))
-                               )))]
-      ;; It is important in this scheme to return value to the channel as soon as it had been read:
-      ;; so that others interested can read back
-      (listen te-name
-              :focus-gained (fn [e]
-                              (put! active-chan false))
-
-              :document (fn [e]
-                          (go
-                           (if (<! active-chan)
-                             (do
-                               ;; important to put it back to channel immediately so others could read
-                               (>! active-chan true)
-                               (>! keys-chan "1")
-                               )
-                             (do
-                               ;(log lb-log "in not-active mode, initiating listening\n")
-                               (start-listening))
-                             ))
-                          )
-              :focus-lost (fn [e]
-                            ;(log lb-log "focus lost, stopping\n")
-                            (stop-listening)
-                            )
-              )
-      form)))
+                             (>! keys-chan "1"))
+                           (do
+                                        ;(log lb-log "in not-active mode, initiating listening\n")
+                             (start-listening)))))
+            :focus-lost (fn [e]
+                                        ;(log lb-log "focus lost, stopping\n")
+                          (stop-listening)))
+    (listen bg-stamp-pos :selection
+            (fn [e]
+              (when-let [image (:image-orig @state)]
+                (when-let [s (selection bg-stamp-pos)]
+                  (update-state :stamp-type (config s :id))
+                  (update-stamped-image form)
+                  ))))
+    form))
 
 (defn build-posts-tab []
   (label "Posts"))

       (if (= resp :error)
         (log lb-log (str "failed to retrieve avatar image for '" username "'\n"))
         (let [image (<! (av/read-image (first resp) c))
               ext (second resp)
               stamped-image (av/stamped image (:stamp-type @state) ext)]
           (log lb-log (str "successfully read image, detected extension is '" ext "'\n"))
           (log lb-log (str "type is '" (.getType stamped-image) "'\n"))
           (config! (select form [:#orig-ava]) :icon image)
           (config! (select form [:#stamped-ava]) :icon stamped-image)
           ))
       ))))

(defn build-avatars-tab []
  (let [bg-stamp-pos (button-group)

                              :halign :center)
                       "span 1 3,w 105px::, h 105px::,wrap,top"]
                      [(label "Положение штампа:")]
                      [(flow-panel :items [(radio :id :top
                                                  :text "Сверху"
                                                  :group bg-stamp-pos
                                                  :selected? (not= :bottom (:stamp-type @state)))
                                           (radio :id :bottom
                                                  :text "Снизу"
                                                  :group bg-stamp-pos
                                                  :selected? (= :bottom (:stamp-type @state))
                                                  )]) "wrap"]
                      [(button :text "Проштамповать") "wrap,skip 1"]
                      [(label "") "grow,push,span 2"] ;; empty filler
                      [(label :id :stamped-ava
