Jaidyn Ann ee7ad3923e Nova biblioteko, Lynx | il y a 3 ans | |
---|---|---|
.. | ||
LICENCE | il y a 3 ans | |
README.md | il y a 3 ans | |
button.lua | il y a 3 ans | |
classic.lua | il y a 3 ans | |
init.lua | il y a 3 ans | |
item.lua | il y a 3 ans | |
list.lua | il y a 3 ans | |
love_lynx.lua | il y a 3 ans | |
lynx.h | il y a 3 ans | |
menu.lua | il y a 3 ans | |
observer.lua | il y a 3 ans | |
raylua_lynx.lua | il y a 3 ans | |
slider.lua | il y a 3 ans | |
text.lua | il y a 3 ans |
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.