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