Compare commits
66 commits
Author | SHA1 | Date | |
---|---|---|---|
|
5336818494 | ||
|
8d092eefa4 | ||
|
1b8058071e | ||
|
829dc151c0 | ||
|
e9be4aa952 | ||
|
018aaf60a0 | ||
|
0347818eca | ||
|
640a50532b | ||
|
9ba37e4e4a | ||
|
7491ab58b2 | ||
|
d1cfcf2a47 | ||
|
d41e9d1875 | ||
|
efc53612bf | ||
|
09cdd09716 | ||
|
fef4e00a60 | ||
|
f33c94db66 | ||
|
213be47f91 | ||
|
f7ab5085f1 | ||
|
0cca218ac7 | ||
|
ccfb6ec005 | ||
|
b3af181896 | ||
|
05dfdb5c34 | ||
|
bf89bf9f08 | ||
|
be9b57393a | ||
|
d463002a97 | ||
|
0d14e1c2cf | ||
|
2fd70e6062 | ||
|
de05b2595c | ||
|
8d081e50e6 | ||
|
3254a42992 | ||
|
901c47fe2c | ||
|
f652c1936f | ||
|
206f937e6e | ||
|
5255830af4 | ||
|
75da1af2b6 | ||
|
08abd141ce | ||
|
a7991c524e | ||
|
42ca8ed3c0 | ||
|
976ff9f63b | ||
|
bb3ffeb957 | ||
|
752eacec7c | ||
|
8f7926039b | ||
|
06114619e6 | ||
|
a3d532378b | ||
|
dfeed19486 | ||
|
d73fde8fb1 | ||
|
d7ed3d0fb7 | ||
|
569591e6eb | ||
|
2880f0532a | ||
|
d4f4980ae8 | ||
|
4d001728a0 | ||
|
c09651b655 | ||
|
4b844d6341 | ||
|
36b788c05a | ||
|
d8234fcc1c | ||
|
b51de073da | ||
|
26f05c82e4 | ||
|
8b5482e74f | ||
|
47128fed66 | ||
|
c2fefb0601 | ||
|
8aa93de803 | ||
|
1d86aa51f4 | ||
|
47a7a6044d | ||
|
0b794f3538 | ||
|
8c0a93e6c5 | ||
|
2d0611adfe |
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/
|
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "src/nuklear"]
|
||||
path = src/nuklear
|
||||
url = https://github.com/vurtun/nuklear.git
|
||||
url = https://github.com/Immediate-Mode-UI/Nuklear.git
|
||||
|
|
|
@ -24,4 +24,14 @@ TARGET_LINK_LIBRARIES(
|
|||
${LUA_LIBRARIES}
|
||||
)
|
||||
|
||||
IF(MSVC)
|
||||
TARGET_COMPILE_DEFINITIONS(${LIB_NAME} PRIVATE LUA_BUILD_AS_DLL)
|
||||
endif(MSVC)
|
||||
|
||||
SET_TARGET_PROPERTIES("${LIB_NAME}" PROPERTIES PREFIX "")
|
||||
|
||||
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "..." FORCE)
|
||||
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
|
||||
INSTALL(TARGETS "${LIB_NAME}" DESTINATION .)
|
||||
|
|
122
README.md
|
@ -1,6 +1,6 @@
|
|||
# LÖVE-Nuklear
|
||||
|
||||
[Nuklear](https://github.com/vurtun/nuklear) module for the [LÖVE](https://love2d.org/) game engine.
|
||||
[Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) module for the [LÖVE](https://love2d.org/) game engine.
|
||||
|
||||
Provides a lightweight immediate mode GUI for LÖVE games.
|
||||
|
||||
|
@ -8,81 +8,145 @@ Provides a lightweight immediate mode GUI for LÖVE games.
|
|||
```lua
|
||||
-- Simple UI example.
|
||||
|
||||
local nk = require 'nuklear'
|
||||
local nuklear = require 'nuklear'
|
||||
|
||||
local ui
|
||||
|
||||
function love.load()
|
||||
nk.init()
|
||||
ui = nuklear.newUI()
|
||||
end
|
||||
|
||||
local combo = {value = 1, items = {'A', 'B', 'C'}}
|
||||
|
||||
function love.update(dt)
|
||||
nk.frameBegin()
|
||||
if nk.windowBegin('Simple Example', 100, 100, 200, 160,
|
||||
ui:frameBegin()
|
||||
if ui:windowBegin('Simple Example', 100, 100, 200, 160,
|
||||
'border', 'title', 'movable') then
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.label('Hello, world!')
|
||||
nk.layoutRow('dynamic', 30, 2)
|
||||
nk.label('Combo box:')
|
||||
if nk.combobox(combo, combo.items) then
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:label('Hello, world!')
|
||||
ui:layoutRow('dynamic', 30, 2)
|
||||
ui:label('Combo box:')
|
||||
if ui:combobox(combo, combo.items) then
|
||||
print('Combo!', combo.items[combo.value])
|
||||
end
|
||||
nk.layoutRow('dynamic', 30, 3)
|
||||
nk.label('Buttons:')
|
||||
if nk.button('Sample') then
|
||||
ui:layoutRow('dynamic', 30, 3)
|
||||
ui:label('Buttons:')
|
||||
if ui:button('Sample') then
|
||||
print('Sample!')
|
||||
end
|
||||
if nk.button('Button') then
|
||||
if ui:button('Button') then
|
||||
print('Button!')
|
||||
end
|
||||
end
|
||||
nk.windowEnd()
|
||||
nk.frameEnd()
|
||||
ui:windowEnd()
|
||||
ui:frameEnd()
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
nk.draw()
|
||||
ui:draw()
|
||||
end
|
||||
|
||||
function love.keypressed(key, scancode, isrepeat)
|
||||
nk.keypressed(key, scancode, isrepeat)
|
||||
ui:keypressed(key, scancode, isrepeat)
|
||||
end
|
||||
|
||||
function love.keyreleased(key, scancode)
|
||||
nk.keyreleased(key, scancode)
|
||||
ui:keyreleased(key, scancode)
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, button, istouch)
|
||||
nk.mousepressed(x, y, button, istouch)
|
||||
function love.mousepressed(x, y, button, istouch, presses)
|
||||
ui:mousepressed(x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, button, istouch)
|
||||
nk.mousereleased(x, y, button, istouch)
|
||||
function love.mousereleased(x, y, button, istouch, presses)
|
||||
ui:mousereleased(x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
function love.mousemoved(x, y, dx, dy, istouch)
|
||||
nk.mousemoved(x, y, dx, dy, istouch)
|
||||
ui:mousemoved(x, y, dx, dy, istouch)
|
||||
end
|
||||
|
||||
function love.textinput(text)
|
||||
nk.textinput(text)
|
||||
ui:textinput(text)
|
||||
end
|
||||
|
||||
function love.wheelmoved(x, y)
|
||||
nk.wheelmoved(x, y)
|
||||
ui:wheelmoved(x, y)
|
||||
end
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Windows and Linux binaries are available for each [release](https://github.com/keharriso/love-nuklear/releases).
|
||||
Windows binaries are available for each [release](https://github.com/keharriso/love-nuklear/releases).
|
||||
|
||||
To build the library yourself, grab the code with:
|
||||
```sh
|
||||
$ git clone --recursive git@github.com:keharriso/love-nuklear.git
|
||||
$ git clone --recursive https://github.com/keharriso/love-nuklear.git
|
||||
```
|
||||
|
||||
Compile with CMake (I recommend using the MinGW generator on Windows). You'll need to tell CMake where to find the LuaJIT headers and binaries. The end result is a native Lua module.
|
||||
Next, you need to compile the code to a native Lua module.
|
||||
|
||||
### Compiling with CMake on Linux
|
||||
|
||||
1. First, ensure you have a C compiler and the `cmake` and `luajit` or `lua51-luajit` (for openSUSE) packages installed, as well as `libluajit-5.1-dev` (for Ubuntu/Debian), `luajit-devel` (for Fedora), or `lua51-luajit-devel` (for openSUSE) if your distro has one of these packages.
|
||||
2. Create a new folder next to `love-nuklear` called `love-nuklear-build`.
|
||||
3. Open a terminal inside `love-nuklear-build`.
|
||||
4. Compile the library with
|
||||
```sh
|
||||
$ cmake -DCMAKE_BUILD_TYPE=Release ../love-nuklear
|
||||
$ make
|
||||
```
|
||||
5. Locate `nuklear.so` in the build folder.
|
||||
|
||||
#### Via GNU Guix
|
||||
|
||||
LÖVE-Nuklear is also available as a [Guix](http://guix.gnu.org/) package, and can thus be directly downloaded and built via:
|
||||
```
|
||||
$ guix package --install love-nuklear
|
||||
```
|
||||
|
||||
### Compiling with CMake and MinGW on Windows
|
||||
|
||||
1. Install [CMake](https://cmake.org/download/) and [MinGW](http://mingw.org/) or [MinGW-w64](https://mingw-w64.org/doku.php).
|
||||
2. Download the source code for [LuaJIT](http://luajit.org/download.html).
|
||||
3. Open a command window inside the LuaJIT folder (the one that contains "README").
|
||||
4. Compile LuaJIT with
|
||||
```sh
|
||||
$ mingw32-make
|
||||
```
|
||||
5. Remember the path to `lua51.dll` inside the LuaJIT `src` folder.
|
||||
6. Run the CMake GUI.
|
||||
7. Click "Browse Source" at the top right, then select the `love-nuklear` folder.
|
||||
8. Enter a path for the build folder. It should be separate from the source folder.
|
||||
9. Press "Configure" at the bottom.
|
||||
10. Select "MinGW Makefiles" from the generator drop list, then click "Finish".
|
||||
11. You should receive an error. This is normal.
|
||||
12. Open the LUA tree by clicking the triangle on the left.
|
||||
13. Replace "LUA_INCLUDE_DIR-NOTFOUND" with the path to the LuaJIT `src` folder.
|
||||
14. Replace "LUA_LIBRARY-NOTFOUND" with the path to `lua51.dll` inside the LuaJIT `src` folder.
|
||||
15. Click "Generate" at the bottom.
|
||||
16. Open a command window inside the build folder.
|
||||
17. Compile with
|
||||
```sh
|
||||
$ mingw32-make
|
||||
```
|
||||
18. Locate `nuklear.dll` inside the build folder.
|
||||
|
||||
### Compiling with CMake and MSVC on Windows
|
||||
|
||||
1. Install [CMake](https://cmake.org/download/) and [Visual Studio](https://visualstudio.microsoft.com/).
|
||||
Community or Express edition is sufficient.
|
||||
2. Download the source code for [LuaJIT](http://luajit.org/download.html).
|
||||
3. Open a Visual Studio Command Prompt (x86 or x64 depending on what architecture you need)
|
||||
and set the current directory to the LuaJIT folder (the one that contains "README"). Also
|
||||
remember this path.
|
||||
4. At the VS Command Prompt, set your current directory to `src` then
|
||||
execute `msvcbuild.bat`. This will create lua51.dll, lua51.lib, and luajit.exe
|
||||
5. Now open new command prompt window inside the `love-nuklear` folder.
|
||||
6. Type `set "LUA_DIR=<path to directory at step 3>"`
|
||||
7. Then type `cmake -Bbuild -H. -A Win32 -DLUA_INCLUDE_DIR=%LUA_DIR%\src -DLUA_LIBRARY=%LUA_DIR%\src\lua51.lib -DCMAKE_INSTALL_PREFIX=%CD%\install`.
|
||||
If you previously compile LuaJIT using x64 VS command prompt, replace `Win32` with `x64` at above command.
|
||||
8. Then type `cmake --build build --config Release --target install` and you'll found `nuklear.dll` inside "install" folder.
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
find_path(LUA_INCLUDE_DIR luajit.h
|
||||
HINTS
|
||||
ENV LUA_DIR
|
||||
PATH_SUFFIXES include/luajit-2.0 include
|
||||
PATH_SUFFIXES include/luajit-2.0 include/luajit-2.1 include/luajit-5_1-2.1 include
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
-- Simple calculator example, adapted from the original nuklear demo.
|
||||
|
||||
local nk = require 'nuklear'
|
||||
|
||||
local ops = {'+', '-', '*', '/'}
|
||||
local a, b, op = '0'
|
||||
|
||||
|
@ -60,36 +58,36 @@ local function display()
|
|||
return b or a
|
||||
end
|
||||
|
||||
return function ()
|
||||
if nk.windowBegin('Calculator', 50, 50, 180, 250, 'border', 'movable', 'title') then
|
||||
nk.layoutRow('dynamic', 35, 1)
|
||||
nk.label(display(), 'right')
|
||||
nk.layoutRow('dynamic', 35, 4)
|
||||
return function (ui)
|
||||
if ui:windowBegin('Calculator', 50, 50, 180, 250, 'border', 'movable', 'title') then
|
||||
ui:layoutRow('dynamic', 35, 1)
|
||||
ui:label(display(), 'right')
|
||||
ui:layoutRow('dynamic', 35, 4)
|
||||
for i=1,16 do
|
||||
if i >= 13 and i < 16 then
|
||||
if i == 13 then
|
||||
if nk.button('C') then
|
||||
if ui:button('C') then
|
||||
clear()
|
||||
end
|
||||
if nk.button('0') then
|
||||
if ui:button('0') then
|
||||
digit('0')
|
||||
end
|
||||
if nk.button('=') then
|
||||
if ui:button('=') then
|
||||
equals()
|
||||
end
|
||||
end
|
||||
elseif i % 4 ~= 0 then
|
||||
local d = tostring(math.floor(i / 4) * 3 + (i % 4))
|
||||
if nk.button(d) then
|
||||
if ui:button(d) then
|
||||
digit(d)
|
||||
end
|
||||
else
|
||||
local o = ops[math.floor(i / 4)]
|
||||
if nk.button(o) then
|
||||
if ui:button(o) then
|
||||
operator(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
nk.windowEnd()
|
||||
ui:windowEnd()
|
||||
end
|
||||
|
|
51
example/closure.lua
Normal file
|
@ -0,0 +1,51 @@
|
|||
-- Show off the optional closure-oriented versions of basic functions
|
||||
|
||||
local function menu(ui)
|
||||
ui:layoutRow('dynamic', 30, 2)
|
||||
ui:menu('Menu A', nil, 100, 200, function ()
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
if ui:menuItem('Item 1') then
|
||||
print 'Closure: Item 1'
|
||||
end
|
||||
if ui:menuItem('Item 2') then
|
||||
print 'Closure: Item 2'
|
||||
end
|
||||
end)
|
||||
ui:menu('Menu B', nil, 100, 200, function ()
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
if ui:menuItem('Item 3') then
|
||||
print 'Closure: Item 3'
|
||||
end
|
||||
if ui:menuItem('Item 4') then
|
||||
print 'Closure: Item 4'
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local comboText = 'Combo 1'
|
||||
|
||||
function combo(ui)
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
if ui:comboboxItem('Combo 1') then
|
||||
print 'Closure: Combo 1'
|
||||
comboText = 'Combo 1'
|
||||
end
|
||||
if ui:comboboxItem('Combo 2') then
|
||||
print 'Closure: Combo 2'
|
||||
comboText = 'Combo 2'
|
||||
end
|
||||
if ui:comboboxItem('Combo 3') then
|
||||
print 'Closure: Combo 3'
|
||||
comboText = 'Combo 3'
|
||||
end
|
||||
end
|
||||
|
||||
local function window(ui)
|
||||
ui:menubar(menu)
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:combobox(comboText, combo)
|
||||
end
|
||||
|
||||
return function (ui)
|
||||
ui:window('Closure', 200, 200, 150, 120, {'title', 'movable', 'border'}, window)
|
||||
end
|
21
example/draw.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
-- Demonstrate a number of custom drawing functions.
|
||||
|
||||
local img = love.graphics.newImage 'skin/button.png'
|
||||
|
||||
return function (ui)
|
||||
if ui:windowBegin('Draw Example', 300, 300, 200, 200, 'title', 'movable', 'border') then
|
||||
local x, y, w, h = ui:windowGetBounds()
|
||||
love.graphics.setColor(1, 0, 0)
|
||||
ui:line(x + 10, y + 40, x + 50, y + 40, x + 50, y + 80)
|
||||
ui:curve(x + 50, y + 80, x + 80, y + 40, x + 100, y + 80, x + 80, y + 80)
|
||||
ui:polygon('line', x + 100, y + 150, x + 60, y + 140, x + 70, y + 70)
|
||||
ui:circle('line', x + 130, y + 140, 50)
|
||||
ui:ellipse('fill', x + 30, y + 150, 20, 40)
|
||||
ui:arc('fill', x + 150, y + 80, 40, 3 * math.pi / 2, 2 * math.pi);
|
||||
ui:rectMultiColor(x + 95, y + 50, 50, 50, '#ff0000', '#00ff00', '#0000ff', '#000000')
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
ui:image(img, x + 120, y + 120, 70, 50)
|
||||
ui:text('DRAW TEXT', x + 15, y + 75, 100, 100)
|
||||
end
|
||||
ui:windowEnd()
|
||||
end
|
|
@ -1,53 +1,72 @@
|
|||
-- Several simple examples.
|
||||
|
||||
local nk = require 'nuklear'
|
||||
local nuklear = require 'nuklear'
|
||||
|
||||
local calculator = require 'calculator'
|
||||
local closure = require 'closure'
|
||||
local draw = require 'draw'
|
||||
local overview = require 'overview'
|
||||
local style = require 'style'
|
||||
local skin = require 'skin'
|
||||
local template = require 'template'
|
||||
local transform = require 'transform'
|
||||
|
||||
local ui1, ui2
|
||||
|
||||
function love.load()
|
||||
nk.init()
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
ui1, ui2 = nuklear.newUI(), nuklear.newUI()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
nk.frameBegin()
|
||||
calculator()
|
||||
style()
|
||||
overview()
|
||||
skin()
|
||||
nk.frameEnd()
|
||||
ui1:frameBegin()
|
||||
calculator(ui1)
|
||||
style(ui1)
|
||||
closure(ui1)
|
||||
overview(ui1)
|
||||
draw(ui1)
|
||||
template(ui1)
|
||||
skin(ui1)
|
||||
ui1:frameEnd()
|
||||
ui2:frameBegin()
|
||||
transform(ui2)
|
||||
ui2:frameEnd()
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
nk.draw()
|
||||
ui1:draw()
|
||||
ui2:draw()
|
||||
love.graphics.print('Current FPS: '..tostring(love.timer.getFPS( )), 10, 10)
|
||||
end
|
||||
|
||||
local function input(name, ...)
|
||||
return ui2[name](ui2, ...) or ui1[name](ui1, ...)
|
||||
end
|
||||
|
||||
function love.keypressed(key, scancode, isrepeat)
|
||||
nk.keypressed(key, scancode, isrepeat)
|
||||
input('keypressed', key, scancode, isrepeat)
|
||||
end
|
||||
|
||||
function love.keyreleased(key, scancode)
|
||||
nk.keyreleased(key, scancode)
|
||||
input('keyreleased', key, scancode)
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, button, istouch)
|
||||
nk.mousepressed(x, y, button, istouch)
|
||||
function love.mousepressed(x, y, button, istouch, presses)
|
||||
input('mousepressed', x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, button, istouch)
|
||||
nk.mousereleased(x, y, button, istouch)
|
||||
function love.mousereleased(x, y, button, istouch, presses)
|
||||
input('mousereleased', x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
function love.mousemoved(x, y, dx, dy, istouch)
|
||||
nk.mousemoved(x, y, dx, dy, istouch)
|
||||
input('mousemoved', x, y, dx, dy, istouch)
|
||||
end
|
||||
|
||||
function love.textinput(text)
|
||||
nk.textinput(text)
|
||||
input('textinput', text)
|
||||
end
|
||||
|
||||
function love.wheelmoved(x, y)
|
||||
nk.wheelmoved(x, y)
|
||||
input('wheelmoved', x, y)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
-- An overview of most of the supported widgets.
|
||||
|
||||
local nk = require 'nuklear'
|
||||
|
||||
local checkA = {value = false}
|
||||
local checkB = {value = true}
|
||||
local radio = {value = 'A'}
|
||||
|
@ -13,94 +11,108 @@ local colorPicker = {value = '#ff0000'}
|
|||
local property = {value = 6}
|
||||
local edit = {value = 'Edit text'}
|
||||
local comboA = {value = 1, items = {'A', 'B', 'C'}}
|
||||
local scissorActive = false
|
||||
|
||||
return function ()
|
||||
if nk.windowBegin('Overview', 100, 100, 600, 450, 'border', 'movable', 'title') then
|
||||
nk.menubarBegin()
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
if nk.menuBegin('Menu', nil, 120, 90) then
|
||||
nk.layoutRow('dynamic', 40, 1)
|
||||
nk.menuItem('Item A')
|
||||
nk.menuItem('Item B')
|
||||
nk.menuItem('Item C')
|
||||
nk.menuEnd()
|
||||
return function (ui)
|
||||
if ui:windowBegin('Overview', 100, 100, 600, 450, 'border', 'movable', 'title') then
|
||||
ui:menubarBegin()
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
if ui:menuBegin('Menu', nil, 120, 90) then
|
||||
ui:layoutRow('dynamic', 40, 1)
|
||||
ui:menuItem('Item A')
|
||||
ui:menuItem('Item B')
|
||||
ui:menuItem('Item C')
|
||||
ui:menuEnd()
|
||||
end
|
||||
nk.menubarEnd()
|
||||
nk.layoutRow('dynamic', 400, 3)
|
||||
nk.groupBegin('Group 1', 'border')
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.label('Left label')
|
||||
nk.label('Centered label', 'centered')
|
||||
nk.label('Right label', 'right')
|
||||
nk.label('Colored label', 'left', '#ff0000')
|
||||
if nk.treePush('tab', 'Tree Tab') then
|
||||
if nk.treePush('node', 'Tree Node 1') then
|
||||
nk.label('Label 1')
|
||||
nk.treePop()
|
||||
ui:menubarEnd()
|
||||
ui:layoutRow('dynamic', 375, 3)
|
||||
if ui:groupBegin('Group 1', 'border') then
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:label('Left label')
|
||||
ui:label('Centered label', 'centered')
|
||||
ui:label('Right label', 'right')
|
||||
ui:label('Colored label', 'left', '#ff0000')
|
||||
if ui:treePush('tab', 'Tree Tab') then
|
||||
if ui:treePush('node', 'Tree Node 1') then
|
||||
ui:label('Label 1')
|
||||
ui:treePop()
|
||||
end
|
||||
if nk.treePush('node', 'Tree Node 2') then
|
||||
nk.label('Label 2')
|
||||
nk.treePop()
|
||||
if ui:treePush('node', 'Tree Node 2') then
|
||||
ui:label('Label 2')
|
||||
ui:treePop()
|
||||
end
|
||||
nk.treePop()
|
||||
ui:treePop()
|
||||
end
|
||||
nk.spacing(1)
|
||||
if nk.button('Button') then
|
||||
ui:spacing(1)
|
||||
if ui:button('Button') then
|
||||
print('button pressed!')
|
||||
end
|
||||
nk.spacing(1)
|
||||
nk.checkbox('Checkbox A', checkA)
|
||||
nk.checkbox('Checkbox B', checkB)
|
||||
nk.groupEnd()
|
||||
nk.groupBegin('Group 2', 'border')
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.label('Radio buttons:')
|
||||
nk.layoutRow('dynamic', 30, 3)
|
||||
nk.radio('A', radio)
|
||||
nk.radio('B', radio)
|
||||
nk.radio('C', radio)
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.selectable('Selectable A', selectA)
|
||||
nk.selectable('Selectable B', selectB)
|
||||
nk.layoutRow('dynamic', 30, {.35, .65})
|
||||
nk.label('Slider:')
|
||||
nk.slider(0, slider, 1, 0.05)
|
||||
nk.label('Progress:')
|
||||
nk.progress(progress, 10, true)
|
||||
nk.layoutRow('dynamic', 30, 2)
|
||||
nk.spacing(2)
|
||||
nk.label('Color picker:')
|
||||
nk.button(nil, colorPicker.value)
|
||||
nk.layoutRow('dynamic', 90, 1)
|
||||
nk.colorPicker(colorPicker)
|
||||
nk.groupEnd()
|
||||
nk.groupBegin('Group 3', 'border')
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.property('Property', 0, property, 10, 0.25, 0.05)
|
||||
nk.spacing(1)
|
||||
nk.label('Edit:')
|
||||
nk.layoutRow('dynamic', 90, 1)
|
||||
nk.edit('box', edit)
|
||||
nk.layoutRow('dynamic', 5, 1)
|
||||
nk.spacing(1)
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.label('Combobox:')
|
||||
nk.combobox(comboA, comboA.items)
|
||||
nk.layoutRow('dynamic', 5, 1)
|
||||
nk.spacing(1)
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
if nk.widgetIsHovered() then
|
||||
nk.tooltip('Test tooltip')
|
||||
ui:spacing(1)
|
||||
ui:checkbox('Checkbox A', checkA)
|
||||
ui:checkbox('Checkbox B', checkB)
|
||||
if ui:button('Scissor') then
|
||||
scissorActive = not scissorActive
|
||||
end
|
||||
ui:groupEnd()
|
||||
end
|
||||
if ui:groupBegin('Group 2', 'border') then
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:label('Radio buttons:')
|
||||
ui:layoutRow('dynamic', 30, 3)
|
||||
ui:radio('A', radio)
|
||||
ui:radio('B', radio)
|
||||
ui:radio('C', radio)
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:selectable('Selectable A', selectA)
|
||||
ui:selectable('Selectable B', selectB)
|
||||
ui:layoutRow('dynamic', 30, {.35, .65})
|
||||
ui:label('Slider:')
|
||||
ui:slider(0, slider, 1, 0.05)
|
||||
ui:label('Progress:')
|
||||
ui:progress(progress, 10, true)
|
||||
ui:layoutRow('dynamic', 30, 2)
|
||||
ui:spacing(2)
|
||||
ui:label('Color picker:')
|
||||
ui:button(nil, colorPicker.value)
|
||||
ui:layoutRow('dynamic', 90, 1)
|
||||
ui:colorPicker(colorPicker)
|
||||
ui:groupEnd()
|
||||
end
|
||||
if ui:groupBegin('Group 3', 'border') then
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:property('Property', 0, property, 10, 0.25, 0.05)
|
||||
ui:spacing(1)
|
||||
ui:label('Edit:')
|
||||
ui:layoutRow('dynamic', 90, 1)
|
||||
ui:edit('box', edit)
|
||||
ui:layoutRow('dynamic', 5, 1)
|
||||
ui:spacing(1)
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:label('Combobox:')
|
||||
ui:combobox(comboA, comboA.items)
|
||||
ui:layoutRow('dynamic', 5, 1)
|
||||
ui:spacing(1)
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
if ui:widgetIsHovered() then
|
||||
ui:tooltip('Test tooltip')
|
||||
end
|
||||
local x, y, w, h = nk.widgetBounds()
|
||||
if nk.contextualBegin(100, 100, x, y, w, h) then
|
||||
nk.layoutRow('dynamic', 30, 1)
|
||||
nk.contextualItem('Item A')
|
||||
nk.contextualItem('Item B')
|
||||
nk.contextualEnd()
|
||||
local x, y, w, h = ui:widgetBounds()
|
||||
if ui:contextualBegin(100, 100, x, y, w, h) then
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:contextualItem('Item A')
|
||||
ui:contextualItem('Item B')
|
||||
ui:contextualEnd()
|
||||
end
|
||||
nk.label('Contextual (Right click me)')
|
||||
nk.groupEnd()
|
||||
ui:label('Contextual (Right click me)')
|
||||
ui:groupEnd()
|
||||
end
|
||||
end
|
||||
ui:windowEnd()
|
||||
if(scissorActive) then
|
||||
love.graphics.setScissor()
|
||||
love.graphics.clear()
|
||||
love.graphics.setScissor(130, 130, 500, 400)
|
||||
else
|
||||
love.graphics.setScissor()
|
||||
end
|
||||
nk.windowEnd()
|
||||
end
|
||||
|
|
|
@ -1,28 +1,34 @@
|
|||
local nk = require 'nuklear'
|
||||
-- Basic skinning example.
|
||||
|
||||
local windowHeader = love.graphics.newImage 'skin/window_header.png'
|
||||
local checkboxSkin = love.graphics.newImage 'skin/checkbox_false.png'
|
||||
local checkboxCheck = love.graphics.newImage 'skin/checkbox_true.png'
|
||||
local windowBody = love.graphics.newImage 'skin/window.png'
|
||||
local checkboxTexture = love.graphics.newImage 'skin/checkbox.png'
|
||||
local checkboxOff = {checkboxTexture, love.graphics.newQuad(0, 0, 51, 55, 58, 115)}
|
||||
local checkboxOn = {checkboxTexture, love.graphics.newQuad(0, 55, 58, 60, 58, 115)}
|
||||
local buttonTexture = love.graphics.newImage 'skin/button.png'
|
||||
local buttonNormal = {buttonTexture, love.graphics.newQuad(0, 0, 69, 52, 69, 156)}
|
||||
local buttonActive = {buttonTexture, love.graphics.newQuad(0, 52, 69, 52, 69, 156)}
|
||||
local buttonHover = {buttonTexture, love.graphics.newQuad(0, 104, 69, 52, 69, 156)}
|
||||
|
||||
local style = {
|
||||
['text'] = {
|
||||
['color'] = '#000000'
|
||||
},
|
||||
['button'] = {
|
||||
['normal'] = love.graphics.newImage 'skin/button.png',
|
||||
['hover'] = love.graphics.newImage 'skin/button_hover.png',
|
||||
['active'] = love.graphics.newImage 'skin/button_active.png',
|
||||
['normal'] = buttonNormal,
|
||||
['hover'] = buttonHover,
|
||||
['active'] = buttonActive,
|
||||
['text background'] = '#00000000',
|
||||
['text normal'] = '#000000',
|
||||
['text hover'] = '#000000',
|
||||
['text active'] = '#ffffff'
|
||||
},
|
||||
['checkbox'] = {
|
||||
['normal'] = checkboxSkin,
|
||||
['hover'] = checkboxSkin,
|
||||
['active'] = checkboxSkin,
|
||||
['cursor normal'] = checkboxCheck,
|
||||
['cursor hover'] = checkboxCheck,
|
||||
['normal'] = checkboxOff,
|
||||
['hover'] = checkboxOff,
|
||||
['active'] = checkboxOff,
|
||||
['cursor normal'] = checkboxOn,
|
||||
['cursor hover'] = checkboxOn,
|
||||
['text normal'] = '#000000',
|
||||
['text hover'] = '#000000',
|
||||
['text active'] = '#000000',
|
||||
|
@ -38,25 +44,25 @@ local style = {
|
|||
['label active'] = '#000000',
|
||||
['label padding'] = {x = 10, y = 8}
|
||||
},
|
||||
['fixed background'] = love.graphics.newImage 'skin/window.png',
|
||||
['fixed background'] = windowBody,
|
||||
['background'] = '#d3ceaa'
|
||||
}
|
||||
}
|
||||
|
||||
local check = {value = false}
|
||||
|
||||
return function ()
|
||||
nk.stylePush(style)
|
||||
if nk.windowBegin('Skin Example', 200, 200, 350, 200, 'title', 'movable') then
|
||||
nk.layoutSpaceBegin('dynamic', 150, 3)
|
||||
nk.layoutSpacePush(0.14, 0.15, 0.72, 0.3)
|
||||
nk.label('Skin example! Styles can change skins, colors, padding, font, and more.', 'wrap')
|
||||
nk.layoutSpacePush(0.2, 0.55, 0.2, 0.2)
|
||||
nk.button('Button')
|
||||
nk.layoutSpacePush(0.55, 0.55, 0.3, 0.2)
|
||||
nk.checkbox('Checkbox', check)
|
||||
nk.layoutSpaceEnd()
|
||||
return function (ui)
|
||||
ui:stylePush(style)
|
||||
if ui:windowBegin('Skin Example', 200, 200, 350, 200, 'title', 'movable') then
|
||||
ui:layoutSpaceBegin('dynamic', 150, 3)
|
||||
ui:layoutSpacePush(0.14, 0.15, 0.72, 0.3)
|
||||
ui:label('Skin example! Styles can change skins, colors, padding, font, and more.', 'wrap')
|
||||
ui:layoutSpacePush(0.2, 0.55, 0.2, 0.2)
|
||||
ui:button('Button')
|
||||
ui:layoutSpacePush(0.55, 0.55, 0.3, 0.2)
|
||||
ui:checkbox('Checkbox', check)
|
||||
ui:layoutSpaceEnd()
|
||||
end
|
||||
nk.windowEnd()
|
||||
nk.stylePop()
|
||||
ui:windowEnd()
|
||||
ui:stylePop()
|
||||
end
|
||||
|
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.4 KiB |
BIN
example/skin/checkbox.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 2.9 KiB |
|
@ -1,6 +1,6 @@
|
|||
-- Show off some of the styling options.
|
||||
|
||||
local nk = require 'nuklear'
|
||||
local nuklear = require "nuklear"
|
||||
|
||||
local colors = {
|
||||
['text'] = '#afafaf',
|
||||
|
@ -41,28 +41,29 @@ end
|
|||
|
||||
table.sort(colorNames)
|
||||
|
||||
return function ()
|
||||
nk.styleLoadColors(colors)
|
||||
nk.windowBegin('Style', 400, 50, 350, 450, 'border', 'movable', 'title', 'scrollbar')
|
||||
nk.layoutRow('dynamic', 25, 2)
|
||||
return function (ui)
|
||||
ui:styleLoadColors(colors)
|
||||
if ui:windowBegin('Style', 400, 50, 350, 450, 'border', 'movable', 'title', 'scrollbar') then
|
||||
ui:layoutRow('dynamic', 25, 2)
|
||||
for _,name in ipairs(colorNames) do
|
||||
nk.label(name..':')
|
||||
ui:label(name..':')
|
||||
local color = colors[name]
|
||||
if nk.comboboxBegin(nil, color, 200, 200) then
|
||||
nk.layoutRow('dynamic', 90, 1)
|
||||
color = nk.colorPicker(color)
|
||||
if ui:comboboxBegin(nil, color, 200, 200) then
|
||||
ui:layoutRow('dynamic', 90, 1)
|
||||
color = ui:colorPicker(color)
|
||||
colors[name] = color
|
||||
local r, g, b = nk.colorParseRGBA(color)
|
||||
nk.layoutRow('dynamic', 25, {.25, .75})
|
||||
nk.label('R: '..r)
|
||||
r = nk.slider(0, r, 255, 1)
|
||||
nk.label('G: '..g)
|
||||
g = nk.slider(0, g, 255, 1)
|
||||
nk.label('B: '..b)
|
||||
b = nk.slider(0, b, 255, 1)
|
||||
colors[name] = nk.colorRGBA(r, g, b)
|
||||
nk.comboboxEnd()
|
||||
local r, g, b = nuklear.colorParseRGBA(color)
|
||||
ui:layoutRow('dynamic', 25, {.25, .75})
|
||||
ui:label('R: '..r)
|
||||
r = ui:slider(0, r, 255, 1)
|
||||
ui:label('G: '..g)
|
||||
g = ui:slider(0, g, 255, 1)
|
||||
ui:label('B: '..b)
|
||||
b = ui:slider(0, b, 255, 1)
|
||||
colors[name] = nuklear.colorRGBA(r, g, b)
|
||||
ui:comboboxEnd()
|
||||
end
|
||||
end
|
||||
nk.windowEnd()
|
||||
end
|
||||
ui:windowEnd()
|
||||
end
|
||||
|
|
19
example/template.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
-- Show off the template row layout
|
||||
|
||||
return function(ui)
|
||||
if ui:windowBegin('Template Layout', 200, 100, 300, 200,
|
||||
'title', 'border', 'movable', 'scalable') then
|
||||
x, y, width, height = ui:windowGetContentRegion()
|
||||
ui:layoutRow('dynamic', 40, 1)
|
||||
ui:label('Scale me!');
|
||||
ui:layoutTemplateBegin(height - 40)
|
||||
ui:layoutTemplatePush('static', 75)
|
||||
ui:layoutTemplatePush('dynamic')
|
||||
ui:layoutTemplatePush('variable', 75)
|
||||
ui:layoutTemplateEnd()
|
||||
ui:button(nil, '#ff0000')
|
||||
ui:button(nil, '#00ff00')
|
||||
ui:button(nil, '#0000ff')
|
||||
end
|
||||
ui:windowEnd()
|
||||
end
|
16
example/transform.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
-- Apply transformations to a basic UI.
|
||||
|
||||
return function(ui)
|
||||
local t = love.timer.getTime()
|
||||
ui:translate(350 + 100 * math.cos(t / 4), 350 + 100 * math.sin(t / 4))
|
||||
ui:rotate(t / 8)
|
||||
ui:scale(1 + math.sin(t / 4) / 2, 1 + math.cos(t / 4) / 2)
|
||||
ui:shear(math.cos(t / 8) / 4, math.sin(t / 8) / 4)
|
||||
if ui:windowBegin('Transform', 0, 0, 200, 200, 'border', 'movable', 'title') then
|
||||
ui:layoutRow('dynamic', 100, 1)
|
||||
ui:label('You can apply transformations to the UI using ui:rotate, ui:scale, ui:shear, and ui:translate.', 'wrap')
|
||||
ui:layoutRow('dynamic', 30, 1)
|
||||
ui:button('Try and catch me!')
|
||||
end
|
||||
ui:windowEnd()
|
||||
end
|
|
@ -1 +1 @@
|
|||
Subproject commit ca1c9b3275cf8e31b01fcd61c4d5116f88d4e24d
|
||||
Subproject commit 614abce05b9455849bbf1519b7f86e53c78b04ab
|