Views, events as messages, and a patch, over plain Avalonia
A program is a model, an update and a view. A view is a Bjolang value; an
event finds its message in the view its control was last given, and the next
view is compared with the last so only what differs is changed. Controls are
made with plain constructors and changed with SetValue, so nothing is
subclassed, and a program never names an Avalonia type.
Text, button, text input, checkbox, column and row. tests/app.bjo drives an
app through its real controls with no window.
🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-4-8)
Co-Authored-By: eca-agent <git@eca.dev>
2026-10-25 16:18:09 +01:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
;; bjogui/examples/counter.bjo — a counter and a greeting in a window.
|
|
|
|
|
;;
|
|
|
|
|
;; bjo run examples/counter.bjo
|
|
|
|
|
|
|
|
|
|
(import (std prelude))
|
|
|
|
|
(import (bjogui view))
|
|
|
|
|
(import (bjogui app))
|
|
|
|
|
|
|
|
|
|
(type (: Msg (Union Inc Dec (: Typed string))))
|
|
|
|
|
(type (: Model (Record (: count int) (: name string))))
|
|
|
|
|
|
2026-10-25 17:02:02 +01:00
|
|
|
(: gui-update (-> Msg Model (Tuple Model (List (Event Msg)))))
|
|
|
|
|
(defun (gui-update msg m)
|
|
|
|
|
(next
|
|
|
|
|
(match msg
|
|
|
|
|
(Inc (record-set m (count (+ (.count m) 1))))
|
|
|
|
|
(Dec (record-set m (count (- (.count m) 1))))
|
|
|
|
|
((Typed s) (record-set m (name s))))))
|
Views, events as messages, and a patch, over plain Avalonia
A program is a model, an update and a view. A view is a Bjolang value; an
event finds its message in the view its control was last given, and the next
view is compared with the last so only what differs is changed. Controls are
made with plain constructors and changed with SetValue, so nothing is
subclassed, and a program never names an Avalonia type.
Text, button, text input, checkbox, column and row. tests/app.bjo drives an
app through its real controls with no window.
🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-4-8)
Co-Authored-By: eca-agent <git@eca.dev>
2026-10-25 16:18:09 +01:00
|
|
|
|
|
|
|
|
(: view (-> Model (View Msg)))
|
|
|
|
|
(defun (view m)
|
|
|
|
|
(column #:spacing 8.0 #:margin 16.0
|
|
|
|
|
(text-input (.name m) Typed #:placeholder "Your name")
|
|
|
|
|
(text #"Hello, ${(if (string-empty? (.name m)) "stranger" (.name m))}!" #:size 18.0)
|
|
|
|
|
(row #:spacing 8.0
|
|
|
|
|
(button "-" Dec #:width 40.0)
|
|
|
|
|
(text #"${(.count m)}" #:size 18.0 #:margin 4.0)
|
|
|
|
|
(button "+" Inc #:width 40.0))))
|
|
|
|
|
|
|
|
|
|
(defun (main)
|
2026-10-25 17:02:02 +01:00
|
|
|
(run-app (Model (count 0) (name "")) gui-update view #:title "Counter" #:width 320.0 #:height 200.0))
|