Skip to content

Instantly share code, notes, and snippets.

@R3V1Z3
Last active December 22, 2025 07:24
Show Gist options
  • Select an option

  • Save R3V1Z3/6ad7540692053f1c1406bf27d3a8b490 to your computer and use it in GitHub Desktop.

Select an option

Save R3V1Z3/6ad7540692053f1c1406bf27d3a8b490 to your computer and use it in GitHub Desktop.
title styles
TUI Test
label button.normal button.focused button.hover button.active checkbox.normal checkbox.focused slider.normal slider.focused
fg bg
200
200
200
20
20
20
fg bg bold
255
255
255
50
50
150
false
fg bg bold
255
255
100
80
80
200
true
fg bg bold
255
255
150
70
70
180
true
fg bg bold
200
200
50
100
100
220
true
fg bg
200
200
200
20
20
20
fg bg bold
255
255
100
20
20
20
true
fg bg
100
150
255
20
20
20
fg bg bold
150
200
255
20
20
20
true

TUI Widget Test

Simple test of TUI widgets.

Controls:

  • Press I/D/R keys to increment/decrement/reset counter
  • Press Q to quit
# Global counter variable
var clickCount = 0
var lastClickedButton = ""

# Create widget manager
nimini_newWidgetManager()

# Enable mouse support for widgets
nimini_enableMouse()

# Add widgets
nimini_newLabel("title", 2, 2, 40, 1, "TUI Widget Test")
nimini_newLabel("counter", 2, 4, 40, 1, "Clicks: 0")

# Buttons
nimini_newButton("btn_inc", 5, 7, 12, 3, "Increment")
nimini_newButton("btn_dec", 20, 7, 12, 3, "Decrement")
nimini_newButton("btn_reset", 35, 7, 10, 3, "Reset")

# Checkbox
nimini_newCheckBox("check1", 5, 12, "Feature enabled", false)

# Slider
nimini_newSlider("slider1", 5, 15, 30, 0, 100)
nimini_newLabel("slider_val", 37, 15, 15, 1, "Value: 50")

# Status
nimini_newLabel("status", 2, 18, 50, 1, "Ready")
# Update widgets
nimini_widgetManagerUpdate(deltaTime)

# Update counter display
nimini_widgetSetText("counter", "Clicks: " & str(clickCount))

# Update slider value display
var sliderValue = nimini_widgetGetValue("slider1")
if sliderValue != 0:
  nimini_widgetSetText("slider_val", "Value: " & str(int(sliderValue)))
# Clear layers
bgClear()
fgClear()

# Draw instructions
bgWriteText(2, 20, "Press I/D/R keys or click widgets")

# Render all widgets
nimini_widgetManagerRender("foreground")
# Handle keyboard shortcuts for I/D/R keys before widgets
# Alphanumeric keys come as text events!
if event.type == "text":
  if event.keyCode == 105:  # 'i' key
    clickCount = clickCount + 1
    nimini_widgetSetText("status", "Incremented!")
    return 1
  if event.keyCode == 100:  # 'd' key
    clickCount = clickCount - 1  
    nimini_widgetSetText("status", "Decremented!")
    return 1
  if event.keyCode == 114:  # 'r' key
    clickCount = 0
    nimini_widgetSetText("status", "Reset!")
    return 1

# Let widget manager handle all other input (including mouse events for slider drag)
var handled = nimini_widgetManagerHandleInput()
if handled:
  # Check for button clicks immediately after widget manager handles input
  if nimini_widgetWasClicked("btn_inc"):
    clickCount = clickCount + 1
    nimini_widgetSetText("status", "Incremented!")
  
  if nimini_widgetWasClicked("btn_dec"):
    clickCount = clickCount - 1
    nimini_widgetSetText("status", "Decremented!")
  
  if nimini_widgetWasClicked("btn_reset"):
    clickCount = 0
    nimini_widgetSetText("status", "Reset!")
  
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment