|
| 1 | +# Lynx |
| 2 | + |
| 3 | +Lynx is a very-lightweight work-in-progress list-based UI library. It allows to |
| 4 | +build efficient and functionnal menues with only a few lines of codes and without |
| 5 | +needing to worry about the coordinates of all menu elements. |
| 6 | + |
| 7 | +It also includes a minimal C port. |
| 8 | + |
| 9 | +# Installation |
| 10 | +To use Lynx, place this directory in your project, then when you need Lynx : |
| 11 | +```lua |
| 12 | +local lynx = require "lynx" |
| 13 | +-- or |
| 14 | +local lynx = require "path.to.lynx" |
| 15 | +``` |
| 16 | + |
| 17 | +You also need a "funcs" table which contains all platform-specific functions to draw our menu. |
| 18 | +For love2d, you can use love-lynx : |
| 19 | +```lua |
| 20 | +local lynx_funcs = lynx.love_lynx |
| 21 | +``` |
| 22 | + |
| 23 | +# Creation |
| 24 | + |
| 25 | +To create a menu, you need a item list (which is a table containing items you can make with e.g lynx.button) |
| 26 | +and a parameter table which contains few parameters as defined in menu.lua. |
| 27 | + |
| 28 | +A demo menu : |
| 29 | +```lua |
| 30 | +menu = lynx.menu({ |
| 31 | + lynx.text "Sample text 1", |
| 32 | + lynx.text "Sample text 2", |
| 33 | + lynx.text "Sample text 3", |
| 34 | + lynx.button("Simple hello button", function () print "Hello World !" end, {}) |
| 35 | +}, { |
| 36 | + viewport = { 0, 0, 300, 200 }, |
| 37 | + offset = { 0, 50 }, |
| 38 | + default_height = 20, |
| 39 | + funcs = lynx_funcs |
| 40 | +}) |
| 41 | +``` |
| 42 | + |
| 43 | +# Usage |
| 44 | + |
| 45 | +### Modifying a menu |
| 46 | + |
| 47 | +You can access all parameters of few other things directly from menu. |
| 48 | +All informations of params are copied into this table, you can safely |
| 49 | +modify these parameters. |
| 50 | +menu.current must be lower than #menu.items otherwise, behavior is undefined. |
| 51 | + |
| 52 | +### Updating a menu |
| 53 | + |
| 54 | +```lua |
| 55 | +menu:update(dt) |
| 56 | +``` |
| 57 | +Update all items with item:update(dt). |
| 58 | + |
| 59 | +### Drawing a menu |
| 60 | + |
| 61 | +```lua |
| 62 | +menu:draw() |
| 63 | +``` |
| 64 | +Draw all items with correct coordinates at menu.viewport. |
| 65 | + |
| 66 | +### Managing input |
| 67 | + |
| 68 | +```lua |
| 69 | +menu:input_key(key, key_state) |
| 70 | +``` |
| 71 | +Insert key event, can be a platform-specific key if funcs.simpleKey is implemented to consider them. |
| 72 | +key_state might be "pressed", "up" or "down". |
| 73 | + |
| 74 | +```lua |
| 75 | +menu:input_mouse(x, y, btn) |
| 76 | +``` |
| 77 | +Insert mouse event, x, y, btn must be numbers, btn can be 0 which indicate no button pressed. |
| 78 | +Some specific buttons have some defined behavior : |
| 79 | + - btn == 0 : Inserts `menu:input_key("enter", "pressed")` event. |
| 80 | + - btn == 1 : Do `menu:pop()` |
| 81 | + |
| 82 | +These behavior currently cannot be customized. |
| 83 | + |
| 84 | +### And then ? |
| 85 | + |
| 86 | +As this project is still work-in-progress, bugs can exist, some features can be missing, some |
| 87 | +others are hard-coded. |
| 88 | +This library is designed to be very simple and lightweight with a modular architecture (following |
| 89 | +the KISS philosophy) while still being functionnal and powerful. |
0 commit comments