Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nabeel20/badar
🌕 Simple custom UI syntax for Löve2D
https://github.com/nabeel20/badar
gui love2d lua
Last synced: 3 months ago
JSON representation
🌕 Simple custom UI syntax for Löve2D
- Host: GitHub
- URL: https://github.com/nabeel20/badar
- Owner: Nabeel20
- License: mit
- Created: 2024-04-09T05:33:40.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-09-24T20:51:54.000Z (3 months ago)
- Last Synced: 2024-09-30T08:02:28.009Z (3 months ago)
- Topics: gui, love2d, lua
- Language: Lua
- Homepage:
- Size: 159 KB
- Stars: 21
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Badar 🌕
Badar _(Full moon in Arabic)_ is a simple and fun way to write UI, prioritizing both _**developer experience**_ and _**readability**_.
### Usage
Copy [badar.lua](badar.lua) to your project for basic functionality _and_ [signal.lua](components/signal.lua) for signals handling.
🌙 For a **_functional_** example see: [example.lua](components/example.lua)```lua
function love.load()
local menu = component { column = true, gap = 10 }
+ label 'Hello, World!'
+ label { text = 'love2d', id = '#2' }
+ button {
text = 'Click me!',
onClick = function(self)
-- get child by id
(self.parent % '#2').text = 'awesome'
end
}
end
```### Functions
- Creating a `new` component. `column (boolean)` & `row (boolean)` and `gap (number)` are used for basic layout calculations. For inspiration see [components](components).
```lua
local newComponent = component {
x = 10, y = 10,
visible = true,
myCustomProp = true,
customFunction = myCustomLogic(),
draw = function(self)
if not self.visible then return end
love.graphics.print('Hello!', self.x, self.y)
end,
}
```- `component = component + child`
Adds the child to its parent’s children table and register its signals.
- `component = component - child`
Removes the child from its parent’s children table, and unregister its signals.
- `component % id (string)`:
Returns child by id in its parent children list. Useful for modifying children within the same parent.
```lua
(parent % id).value = newValue
```- `:isMouseInside()`
> [!NOTE]
> Badar uses `signal.lua` by default. Feel free to use your own methods (eg. update `__add` and `__sub` in badar.lua).## License
This library is free software; you can redistribute it and/or modify it under
the terms of the MIT license. See [LICENSE](LICENSE) for details.