From 5bd43f13f94ec6c41e5d4013b284bddc364b87a7 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 15 Apr 2017 11:18:15 +0200 Subject: [PATCH] added code snippet --- experiments/oldwidgets.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/experiments/oldwidgets.nim b/experiments/oldwidgets.nim index 46d87c2..fce9908 100644 --- a/experiments/oldwidgets.nim +++ b/experiments/oldwidgets.nim @@ -111,3 +111,22 @@ when false: if plugins.len > 0: plugins[0][1]() +var + images: seq[cstring] = @[cstring"a", "b", "c", "d"] + +proc carousel*(): VNode = + var currentIndex = 0 + + proc next(ev: Event; n: VNode) = + currentIndex = (currentIndex + 1) mod images.len + + proc prev(ev: Event; n: VNode) = + currentIndex = (currentIndex - 1) mod images.len + + result = buildHtml(tdiv): + text images[currentIndex] + button(onclick = next): + text "Next" + button(onclick = prev): + text "Previous" +