https://github.com/haoyu234/buju
buju (布局) is a simple layout engine, based on layout.h
https://github.com/haoyu234/buju
layout-engine nim
Last synced: about 1 month ago
JSON representation
buju (布局) is a simple layout engine, based on layout.h
- Host: GitHub
- URL: https://github.com/haoyu234/buju
- Owner: haoyu234
- License: mit
- Created: 2024-09-29T14:01:26.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T13:52:04.000Z (7 months ago)
- Last Synced: 2024-10-25T01:13:16.758Z (7 months ago)
- Topics: layout-engine, nim
- Language: JavaScript
- Homepage: https://htmlpreview.github.io/?https://github.com/haoyu234/buju/blob/main/assets/demo.html
- Size: 106 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buju
buju (布局) is a simple layout engine, it is a Nim port of [layout.h](https://github.com/randrew/layout).
It has fixed several bugs left over from the original implementation and optimized the performance of some functions.```nim
import bujuvar l = default(Layout)
let root = l.node()
l.setSize(root, vec2(50, 50))template alignBox(n, flags) =
let n = l.node()
l.setSize(n, vec2(10, 10))
l.setLayoutFlags(n, flags)
l.insertChild(root, n)# |2|4|3|
# |5|7|6|
# |8|10|9|alignBox(node2, LayoutTop or LayoutLeft)
alignBox(node3, LayoutTop or LayoutRight)
alignBox(node4, LayoutTop)alignBox(node5, LayoutLeft)
alignBox(node6, LayoutRight)
alignBox(node7, 0)alignBox(node8, LayoutBottom or LayoutLeft)
alignBox(node9, LayoutBottom or LayoutRight)
alignBox(node10, LayoutBottom)l.compute(root)
check l.computed(node2) == vec4(0, 0, 10, 10)
check l.computed(node3) == vec4(40, 0, 10, 10)
check l.computed(node4) == vec4(20, 0, 10, 10)check l.computed(node5) == vec4(0, 20, 10, 10)
check l.computed(node6) == vec4(40, 20, 10, 10)
check l.computed(node7) == vec4(20, 20, 10, 10)check l.computed(node8) == vec4(0, 40, 10, 10)
check l.computed(node9) == vec4(40, 40, 10, 10)
check l.computed(node10) == vec4(20, 40, 10, 10)```
The [online editor](https://htmlpreview.github.io/?https://github.com/haoyu234/buju/blob/main/assets/demo.html) is in `assets/demo.html`, and here is the output:
