mirror of
https://github.com/keharriso/love-nuklear.git
synced 2025-09-10 16:17:47 -04:00
Add template layout and allow manual edit focus/unfocus
This commit is contained in:
parent
752eacec7c
commit
bb3ffeb957
3 changed files with 90 additions and 0 deletions
|
@ -7,6 +7,7 @@ local draw = require 'draw'
|
||||||
local overview = require 'overview'
|
local overview = require 'overview'
|
||||||
local style = require 'style'
|
local style = require 'style'
|
||||||
local skin = require 'skin'
|
local skin = require 'skin'
|
||||||
|
local template = require 'template'
|
||||||
local transform = require 'transform'
|
local transform = require 'transform'
|
||||||
|
|
||||||
local ui1, ui2
|
local ui1, ui2
|
||||||
|
@ -21,6 +22,7 @@ function love.update(dt)
|
||||||
style(ui1)
|
style(ui1)
|
||||||
overview(ui1)
|
overview(ui1)
|
||||||
draw(ui1)
|
draw(ui1)
|
||||||
|
template(ui1)
|
||||||
skin(ui1)
|
skin(ui1)
|
||||||
ui1:frameEnd()
|
ui1:frameEnd()
|
||||||
ui2:frameBegin()
|
ui2:frameBegin()
|
||||||
|
|
19
example/template.lua
Normal file
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
|
|
@ -1808,6 +1808,16 @@ static int nk_love_window_is_collapsed(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nk_love_window_is_closed(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 2);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
const char *name = luaL_checkstring(L, 2);
|
||||||
|
int is_closed = nk_window_is_closed(&context->nkctx, name);
|
||||||
|
lua_pushboolean(L, is_closed);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int nk_love_window_is_hidden(lua_State *L)
|
static int nk_love_window_is_hidden(lua_State *L)
|
||||||
{
|
{
|
||||||
nk_love_assert_argc(lua_gettop(L) == 2);
|
nk_love_assert_argc(lua_gettop(L) == 2);
|
||||||
|
@ -2027,6 +2037,43 @@ static int nk_love_layout_row_end(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nk_love_layout_template_begin(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 2);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
float height = luaL_checknumber(L, 2);
|
||||||
|
nk_layout_row_template_begin(&context->nkctx, height);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nk_love_layout_template_push(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 2 || lua_gettop(L) == 3);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
const char *mode = luaL_checkstring(L, 2);
|
||||||
|
if (lua_gettop(L) == 2) {
|
||||||
|
nk_love_assert(!strcmp(mode, "dynamic"), "%s: expecting 'dynamic' mode or width argument");
|
||||||
|
nk_layout_row_template_push_dynamic(&context->nkctx);
|
||||||
|
} else {
|
||||||
|
float width = luaL_checknumber(L, 3);
|
||||||
|
if (!strcmp(mode, "variable")) {
|
||||||
|
nk_layout_row_template_push_variable(&context->nkctx, width);
|
||||||
|
} else if (!strcmp(mode, "static")) {
|
||||||
|
nk_layout_row_template_push_static(&context->nkctx, width);
|
||||||
|
} else {
|
||||||
|
return luaL_argerror(L, 2, "expecting 'dynamic', 'variable', or 'static' modes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nk_love_layout_template_end(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 1);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
nk_layout_row_template_end(&context->nkctx);
|
||||||
|
}
|
||||||
|
|
||||||
static int nk_love_layout_space_begin(lua_State *L)
|
static int nk_love_layout_space_begin(lua_State *L)
|
||||||
{
|
{
|
||||||
nk_love_assert_argc(lua_gettop(L) == 4);
|
nk_love_assert_argc(lua_gettop(L) == 4);
|
||||||
|
@ -2658,6 +2705,22 @@ static int nk_love_edit(lua_State *L)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nk_love_edit_focus(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 1);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
nk_edit_focus(&context->nkctx, NK_EDIT_DEFAULT);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nk_love_edit_unfocus(lua_State *L)
|
||||||
|
{
|
||||||
|
nk_love_assert_argc(lua_gettop(L) == 1);
|
||||||
|
nk_love_assert_context(1);
|
||||||
|
nk_edit_unfocus(&context->nkctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int nk_love_popup_begin(lua_State *L)
|
static int nk_love_popup_begin(lua_State *L)
|
||||||
{
|
{
|
||||||
nk_love_assert_argc(lua_gettop(L) >= 7);
|
nk_love_assert_argc(lua_gettop(L) >= 7);
|
||||||
|
@ -3977,6 +4040,7 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState)
|
||||||
NK_LOVE_REGISTER("windowGetContentRegion", nk_love_window_get_content_region);
|
NK_LOVE_REGISTER("windowGetContentRegion", nk_love_window_get_content_region);
|
||||||
NK_LOVE_REGISTER("windowHasFocus", nk_love_window_has_focus);
|
NK_LOVE_REGISTER("windowHasFocus", nk_love_window_has_focus);
|
||||||
NK_LOVE_REGISTER("windowIsCollapsed", nk_love_window_is_collapsed);
|
NK_LOVE_REGISTER("windowIsCollapsed", nk_love_window_is_collapsed);
|
||||||
|
NK_LOVE_REGISTER("windowIsClosed", nk_love_window_is_closed);
|
||||||
NK_LOVE_REGISTER("windowIsHidden", nk_love_window_is_hidden);
|
NK_LOVE_REGISTER("windowIsHidden", nk_love_window_is_hidden);
|
||||||
NK_LOVE_REGISTER("windowIsActive", nk_love_window_is_active);
|
NK_LOVE_REGISTER("windowIsActive", nk_love_window_is_active);
|
||||||
NK_LOVE_REGISTER("windowIsHovered", nk_love_window_is_hovered);
|
NK_LOVE_REGISTER("windowIsHovered", nk_love_window_is_hovered);
|
||||||
|
@ -3996,6 +4060,9 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState)
|
||||||
NK_LOVE_REGISTER("layoutRowBegin", nk_love_layout_row_begin);
|
NK_LOVE_REGISTER("layoutRowBegin", nk_love_layout_row_begin);
|
||||||
NK_LOVE_REGISTER("layoutRowPush", nk_love_layout_row_push);
|
NK_LOVE_REGISTER("layoutRowPush", nk_love_layout_row_push);
|
||||||
NK_LOVE_REGISTER("layoutRowEnd", nk_love_layout_row_end);
|
NK_LOVE_REGISTER("layoutRowEnd", nk_love_layout_row_end);
|
||||||
|
NK_LOVE_REGISTER("layoutTemplateBegin", nk_love_layout_template_begin);
|
||||||
|
NK_LOVE_REGISTER("layoutTemplatePush", nk_love_layout_template_push);
|
||||||
|
NK_LOVE_REGISTER("layoutTemplateEnd", nk_love_layout_template_end);
|
||||||
NK_LOVE_REGISTER("layoutSpaceBegin", nk_love_layout_space_begin);
|
NK_LOVE_REGISTER("layoutSpaceBegin", nk_love_layout_space_begin);
|
||||||
NK_LOVE_REGISTER("layoutSpacePush", nk_love_layout_space_push);
|
NK_LOVE_REGISTER("layoutSpacePush", nk_love_layout_space_push);
|
||||||
NK_LOVE_REGISTER("layoutSpaceEnd", nk_love_layout_space_end);
|
NK_LOVE_REGISTER("layoutSpaceEnd", nk_love_layout_space_end);
|
||||||
|
@ -4026,6 +4093,8 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState)
|
||||||
NK_LOVE_REGISTER("colorPicker", nk_love_color_picker);
|
NK_LOVE_REGISTER("colorPicker", nk_love_color_picker);
|
||||||
NK_LOVE_REGISTER("property", nk_love_property);
|
NK_LOVE_REGISTER("property", nk_love_property);
|
||||||
NK_LOVE_REGISTER("edit", nk_love_edit);
|
NK_LOVE_REGISTER("edit", nk_love_edit);
|
||||||
|
NK_LOVE_REGISTER("editFocus", nk_love_edit_focus);
|
||||||
|
NK_LOVE_REGISTER("editUnfocus", nk_love_edit_unfocus);
|
||||||
NK_LOVE_REGISTER("popupBegin", nk_love_popup_begin);
|
NK_LOVE_REGISTER("popupBegin", nk_love_popup_begin);
|
||||||
NK_LOVE_REGISTER("popupClose", nk_love_popup_close);
|
NK_LOVE_REGISTER("popupClose", nk_love_popup_close);
|
||||||
NK_LOVE_REGISTER("popupEnd", nk_love_popup_end);
|
NK_LOVE_REGISTER("popupEnd", nk_love_popup_end);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue