xonecas.io
70160
Ce

cel-tui / commit b1f40b1

refactor: simple-scroll example uses uncontrolled scroll

Removed scrollOffset/onScroll state — the framework manages scroll
position internally. The example now demonstrates the simplest
scrollable pattern: just overflow: "scroll" and scrollbar: true.

xonecas2026-04-04 b1f40b11ad37e02b2072eb894850847c53f2f0dc parent 85f87ef

1 file changed

examples/simple-scroll.ts+9−15
@@ -2,7 +2,10 @@
22 * Scroll test — a large list inside a scrollable VStack.
33 * Mouse wheel should scroll the list up/down.
44 *
5- * Run: bun run examples/scroll-test.ts
5+ * Uses uncontrolled scroll — the framework manages scroll position
6+ * internally. No scrollOffset/onScroll state needed.
7+ *
8+ * Run: bun run examples/simple-scroll.ts
69 */
710 import { cel, VStack, HStack, Text, ProcessTerminal } from "@cel-tui/core";
811
@@ -39,8 +42,6 @@ function fake(): string {
3942 ).join(" ");
4043 }
4144
42-let scrollOffset = 0;
43-
4445 function quit() {
4546 cel.stop();
4647 process.exit();
@@ -88,21 +89,12 @@ cel.viewport(() => {
8889 HStack({ padding: { x: 1 } }, [
8990 Text("Scroll Test", { bold: true, fgColor: "cyan" }),
9091 VStack({ flex: 1 }, []),
91- Text(`offset: ${scrollOffset}`, { fgColor: "brightBlack" }),
92+ Text("uncontrolled", { fgColor: "brightBlack" }),
9293 ]),
9394 Text("─", { repeat: "fill", fgColor: "brightBlack" }),
9495
9596 VStack(
96- {
97- flex: 1,
98- overflow: "scroll",
99- scrollbar: true,
100- scrollOffset,
101- onScroll: (off) => {
102- scrollOffset = off;
103- cel.render();
104- },
105- },
97+ { flex: 1, overflow: "scroll", scrollbar: true },
10698 items.map((item, i) =>
10799 HStack({ padding: { x: 1 } }, [
108100 Text(`${String(i + 1).padStart(3)}.`, { fgColor: "yellow" }),
@@ -113,7 +105,9 @@ cel.viewport(() => {
113105
114106 Text("─", { repeat: "fill", fgColor: "brightBlack" }),
115107 HStack({ padding: { x: 1 } }, [
116- Text("Mouse wheel to scroll · Ctrl+Q quit", { fgColor: "brightBlack" }),
108+ Text("Mouse wheel to scroll · Ctrl+Q quit", {
109+ fgColor: "brightBlack",
110+ }),
117111 ]),
118112 ],
119113 );