https://github.com/nimaoth/nimclay
Nim wrapper for clay (UI layout library)
https://github.com/nimaoth/nimclay
Last synced: 12 months ago
JSON representation
Nim wrapper for clay (UI layout library)
- Host: GitHub
- URL: https://github.com/nimaoth/nimclay
- Owner: Nimaoth
- License: mit
- Created: 2024-12-23T18:15:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T18:58:56.000Z (over 1 year ago)
- Last Synced: 2024-12-23T19:43:27.911Z (over 1 year ago)
- Language: Nim
- Size: 0 Bytes
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nimclay
Nim wrapper for [clay](https://github.com/nicbarker/clay)
## Installation
Add this to your nimble file:
```nim
requires "https://github.com/Nimaoth/nimclay >= 0.1.0"
```
## Usage
```nim
import clay
proc measureClayText(str: ptr ClayString, config: ptr ClayTextElementConfig): ClayDimensions {.cdecl.} =
return ClayDimensions(width: str.length.float * 10, height: 20)
proc main() =
let totalMemorySize = clay.minMemorySize()
var memory = ClayArena(label: cs"my memory arena", capacity: totalMemorySize, memory: cast[cstring](allocShared0(totalMemorySize)))
clay.initialize(memory, ClayDimensions(width: 1024, height: 768))
clay.setMeasureTextFunction(measureClayText)
var layoutElement = ClayLayoutConfig(padding: ClayPadding(x: 5, y: 10))
var textConfig = ClayTextElementConfig(textColor: clayColor(1, 1, 1))
# every frame
clay.beginLayout()
UI(rectangle(color = clayColor(1, 0, 0)), layout(layoutElement)):
UI(rectangle(color = clayColor(0, 1, 0), cornerRadius = cornerRadius(1, 2, 3, 4)), layout(padding = ClayPadding(x: 20, y: 30))):
clayText("hello", textColor = clayColor(0, 1, 1))
clayText("world", textConfig)
let renderCommands = clay.endLayout()
# ...
main()
```