Jaidyn Ann ee7ad3923e Nova biblioteko, Lynx | 3 年 前 | |
---|---|---|
.. | ||
LICENCE | 3 年 前 | |
README.md | 3 年 前 | |
button.lua | 3 年 前 | |
classic.lua | 3 年 前 | |
init.lua | 3 年 前 | |
item.lua | 3 年 前 | |
list.lua | 3 年 前 | |
love_lynx.lua | 3 年 前 | |
lynx.h | 3 年 前 | |
menu.lua | 3 年 前 | |
observer.lua | 3 年 前 | |
raylua_lynx.lua | 3 年 前 | |
slider.lua | 3 年 前 | |
text.lua | 3 年 前 |
Lynx is a very-lightweight work-in-progress list-based UI library. It allows to build efficient and functionnal menues with only a few lines of codes and without needing to worry about the coordinates of all menu elements.
It also includes a minimal C port.
To use Lynx, place this directory in your project, then when you need Lynx :
local lynx = require "lynx"
-- or
local lynx = require "path.to.lynx"
You also need a "funcs" table which contains all platform-specific functions to draw our menu. For love2d, you can use love-lynx :
local lynx_funcs = lynx.love_lynx
To create a menu, you need a item list (which is a table containing items you can make with e.g lynx.button) and a parameter table which contains few parameters as defined in menu.lua.
A demo menu :
menu = lynx.menu({
lynx.text "Sample text 1",
lynx.text "Sample text 2",
lynx.text "Sample text 3",
lynx.button("Simple hello button", function () print "Hello World !" end, {})
}, {
viewport = { 0, 0, 300, 200 },
offset = { 0, 50 },
default_height = 20,
funcs = lynx_funcs
})
You can access all parameters of few other things directly from menu. All informations of params are copied into this table, you can safely modify these parameters. menu.current must be lower than #menu.items otherwise, behavior is undefined.
menu:update(dt)
Update all items with item:update(dt).
menu:draw()
Draw all items with correct coordinates at menu.viewport.
menu:input_key(key, key_state)
Insert key event, can be a platform-specific key if funcs.simpleKey is implemented to consider them. key_state might be "pressed", "up" or "down".
menu:input_mouse(x, y, btn)
Insert mouse event, x, y, btn must be numbers, btn can be 0 which indicate no button pressed. Some specific buttons have some defined behavior :
menu:input_key("enter", "pressed")
event.menu:pop()
These behavior currently cannot be customized.
As this project is still work-in-progress, bugs can exist, some features can be missing, some others are hard-coded. This library is designed to be very simple and lightweight with a modular architecture (following the KISS philosophy) while still being functionnal and powerful.