Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
- name: Run unit tests
if: ${{ !matrix.emscripten }}
run: |
nim r tests/test_semantic.nim
nim r tests/test_textboxes.nim
nim r tests/test_atlas_png.nim

- name: Compile examples
if: ${{ !matrix.emscripten }}
Expand Down
163 changes: 85 additions & 78 deletions examples/basicwindow/basicwindow.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ var
power = "Medium"
progress = 0.0
howMuch = 30.0
earlyReturn = true # Demonstrates that early return from a group works.
words = @["Alpha", "Bravo", "Charlie", "Delta"]
wordsIdx = 0
clickableEnabled = true
earlyReturn = true

proc returnTest() =
text("Return Test")
group(vec2(8, 8), LeftToRight):
text("Group")
text "return title":
characters "Return Test"
group "return row":
box 220, 34
layout LeftToRight
itemSpacing 8
text "return group":
characters "Group"
if earlyReturn:
return
text("You will not see this.")
text "return hidden":
characters "You will not see this."

window.onFrame = proc() =
if window.buttonPressed[KeyEqual] or
Expand All @@ -55,78 +58,82 @@ window.onFrame = proc() =

sk.beginUI(window, window.size)

# Draw tiled test texture as the background.
for x in 0 ..< 16:
for y in 0 ..< 10:
sk.at = vec2(x.float32 * 256, y.float32 * 256)
image("testTexture", rgbx(30, 30, 30, 255))

subWindow("A SubWindow", showWindow, vec2(100, 100), vec2(400, 700)):
text("Hello world!")
button("Close Me"):
showWindow = false
textInput("input", inputText)

radioButton("Avg", option, 1)
radioButton("Max", option, 2)
radioButton("Min", option, 3)

checkBox("Cumulative", cumulative)

text("Select an option:")
dropDown(element, ["Fire", "Water", "Earth", "Air"])
dropDown(power, ["Low", "Medium", "High"])

text("Progress Bar:")
progressBar(progress, 0, 100)
progress += 0.01
if progress > 100.0:
progress = 0.0

text(&"How much: {howMuch:.2f}")
scrubber("howMuch", howMuch, 0.0, 100.0)

group(vec2(8, 8), LeftToRight):
icon("heart")
text("Heart")
icon("cloud")
text("Cloud")

group(vec2(8, 8), LeftToRight):
clickableIcon("heart", true):
discard
text("on")
clickableIcon("heart", false):
discard
text("off")
clickableIcon("heart", clickableEnabled):
clickableEnabled = not clickableEnabled
text("switch")

group(vec2(8, 8), LeftToRight):
iconButton("cloud"):
wordsIdx = (wordsIdx + 1) mod words.len
text(words[wordsIdx])

text("A bunch of text to test the scrolling, in any direction.")
text("Does it work?")

for i in 0 ..< 10:
text("Time will tell...")

returnTest()

if not showWindow:
if window.buttonPressed[MouseLeft]:
showWindow = true
sk.at = vec2(100, 100)
text("Click anywhere to show the window")

let ms = sk.avgFrameTime * 1000
sk.at = sk.pos + vec2(sk.size.x - 250, 20)
text(&"ui scale: {sk.uiScale:>4.2f}x (+/-)")
sk.at = sk.pos + vec2(sk.size.x - 250, 48)
text(&"frame time: {ms:>7.3f}ms")
sk.drawImage("testTexture", vec2(x.float32 * 256, y.float32 * 256), rgbx(30, 30, 30, 255))

ui:
subWindow("A SubWindow", showWindow, vec2(100, 100), vec2(400, 700)):
text "hello":
characters "Hello world!"

button "Close Me":
showWindow = false

textInput "input", inputText

group "radio buttons":
box 350, 32
layout LeftToRight
itemSpacing 12
radioButton "Avg", option, 1
radioButton "Max", option, 2
radioButton "Min", option, 3

checkBox "Cumulative", cumulative

text "select label":
characters "Select an option:"
dropDown element, ["Fire", "Water", "Earth", "Air"]
dropDown power, ["Low", "Medium", "High"]

text "progress label":
characters "Progress Bar:"
progressBar progress, 0, 100
progress += 0.01
if progress > 100.0:
progress = 0.0

text "scrubber label":
characters &"How much: {howMuch:.2f}"
scrubber "howMuch", howMuch, 0.0, 100.0, &"{howMuch:.0f}"

group "icons row":
box 260, 32
layout LeftToRight
itemSpacing 8
icon "heart"
text "heart label":
characters "Heart"
icon "cloud"
text "cloud label":
characters "Cloud"

text "scroll one":
characters "A bunch of text to test the scrolling, in any direction."
text "scroll two":
characters "Does it work?"

for i in 0 ..< 10:
text "time line " & $i:
characters "Time will tell..."

returnTest()

if not showWindow:
text "closed message":
box 100, 100, 360, 32
characters "Click anywhere to show the window"
if window.buttonPressed[MouseLeft]:
showWindow = true

let ms = sk.avgFrameTime * 1000
text "scale readout":
box sk.size.x - 250, 20, 230, 22
characters &"ui scale: {sk.uiScale:>4.2f}x (+/-)"
text "time readout":
box sk.size.x - 250, 48, 230, 22
characters &"frame time: {ms:>7.3f}ms"

sk.endUi()
window.swapBuffers()
Expand Down
Loading
Loading