From 15c4616e19d997c64a983e39501289c7d9f50d0a Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 16:39:30 +0100 Subject: Add a tally example: a keyed list on every surface examples/tally.aup counts typed words in a list keyed by the word: the screen stays sorted with each word once, typing a word again counts it and moves the focus to it. It runs on the three surfaces with the other examples, and vega check finds nothing in it. --- examples/tally.aup | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/tally.aup (limited to 'examples') diff --git a/examples/tally.aup b/examples/tally.aup new file mode 100644 index 0000000..5c3d9e9 --- /dev/null +++ b/examples/tally.aup @@ -0,0 +1,38 @@ +# Words typed, tallied. A list keyed by the word keeps each word once and in +# order: the screen is sorted without a sort anywhere, and typing a word +# again counts it and moves the focus to it. +use vega + +record Tally { + word: text + times = 0 +} + +state tallies: list of Tally by word +state at: index of tallies + +input add = text +input up = key ArrowUp +input down = key ArrowDown +input drop = key Delete + +on add { + if !tallies.has(add) { + tallies.add(Tally { word: add }) + } + tallies[add].times = tallies[add].times + 1 + at = tallies[add] +} +on up.down { at = at - 1 } +on down.down { at = at + 1 } +on drop.down { tallies.remove(at) } + +view title = "Tally" +view typed = "{sum(t.times for t in tallies)} typed, {tallies.count} different" + +view tallies_list = each t in tallies { + label = t.word + badge = "{t.times}" + tone = vega.when(t.times > 1, vega.accent) +} +view tallies_list_focus = at.position -- cgit v1.2.3