| Paint glimmer with nothing under it f554a01 nandi 11d ago | 1 | (ns glimmer-gfx.counter |
| 2 | "The glimmer counter, rendered by gfx's own rasterizer. |
| 3 | |
| 4 | Compare examples/ in glimmer-vidya: the component is the same shape, because |
| 5 | the component never knew which backend it had." |
| 6 | (:require [glimmer.ratom :as ra] |
| 7 | [glimmer.core :as ui] |
| 8 | [glimmer-gfx.core])) ; installs the backend |
| 9 | |
| 10 | (def state (ra/atom {:count 0 :volume 40 :loud? false})) |
| 11 | |
| 12 | (defn app [] |
| 13 | (let [{:keys [count volume loud?]} (ra/deref state)] |
| 14 | [:page {:max-width 440} |
| 15 | [:card {:spacing 8} |
| 16 | [:title {:label "Counter"}] |
| 17 | [:label {:label (str "Count: " count)}] |
| 18 | [:hbox {:spacing 8} |
| 19 | [:button {:label "- 1" :on-click #(ra/swap! state update :count dec)}] |
| 20 | [:button {:label "+ 1" :kind :primary |
| 21 | :on-click #(ra/swap! state update :count inc)}] |
| 22 | [:button {:label "reset" :on-click #(ra/swap! state assoc :count 0)}]] |
| 23 | [:spacer {:size 6}] |
| 24 | [:label {:label "Volume" :dim true}] |
| 25 | [:slider {:value volume :min 0 :max 100 |
| 26 | :on-change #(ra/swap! state assoc :volume (long %))}] |
| 27 | [:checkbox {:label "loud" :checked loud? |
| 28 | :on-click #(ra/swap! state update :loud? not)}]]])) |
| 29 | |
| 30 | (defn -main [& _] |
| 31 | (ui/run app :title "glimmer-gfx" :width 480 :height 340)) |