From 0cca218ac72f71c39130277dac1a6d1c9aceef69 Mon Sep 17 00:00:00 2001 From: Kevin Harrison Date: Thu, 17 Oct 2019 19:40:43 -0400 Subject: [PATCH] Add support for *GetScroll and *SetScroll for windows, groups, and popups --- src/nuklear | 2 +- src/nuklear_love.c | 78 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/nuklear b/src/nuklear index 181cfd8..adc52d7 160000 --- a/src/nuklear +++ b/src/nuklear @@ -1 +1 @@ -Subproject commit 181cfd86c47ae83eceabaf4e640587b844e613b6 +Subproject commit adc52d710fe3c87194b99f540c53e82eb75c2521 diff --git a/src/nuklear_love.c b/src/nuklear_love.c index 3741e8f..a4488da 100644 --- a/src/nuklear_love.c +++ b/src/nuklear_love.c @@ -39,7 +39,6 @@ #define NK_LOVE_COMBOBOX_MAX_ITEMS 1024 #define NK_LOVE_MAX_FONTS 1024 #define NK_LOVE_MAX_RATIOS 1024 -#define NK_LOVE_GRADIENT_RESOLUTION 32 static lua_State *L; static char *edit_buffer; @@ -1848,6 +1847,17 @@ static int nk_love_window_get_size(lua_State *L) return 2; } +static int nk_love_window_get_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 1); + nk_love_assert_context(1); + nk_uint offset_x, offset_y; + nk_window_get_scroll(&context->nkctx, &offset_x, &offset_y); + lua_pushinteger(L, offset_x); + lua_pushinteger(L, offset_y); + return 2; +} + static int nk_love_window_get_content_region(lua_State *L) { nk_love_assert_argc(lua_gettop(L) == 1); @@ -1982,6 +1992,17 @@ static int nk_love_window_set_focus(lua_State *L) return 0; } +static int nk_love_window_set_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 3); + nk_love_assert_context(1); + nk_uint offset_x, offset_y; + offset_x = luaL_checkinteger(L, 2); + offset_y = luaL_checkinteger(L, 3); + nk_window_set_scroll(&context->nkctx, offset_x, offset_y); + return 0; +} + static int nk_love_window_close(lua_State *L) { nk_love_assert_argc(lua_gettop(L) == 2); @@ -2371,6 +2392,29 @@ static int nk_love_group(lua_State *L) return 0; } +static int nk_love_group_get_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 2); + nk_love_assert_context(1); + const char *id = luaL_checkstring(L, 2); + nk_uint x_offset, y_offset; + nk_group_get_scroll(&context->nkctx, id, &x_offset, &y_offset); + lua_pushinteger(L, x_offset); + lua_pushinteger(L, y_offset); + return 2; +} + +static int nk_love_group_set_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 4); + nk_love_assert_context(1); + const char *id = luaL_checkstring(L, 2); + nk_uint x_offset = luaL_checkint(L, 3); + nk_uint y_offset = luaL_checkint(L, 4); + nk_group_set_scroll(&context->nkctx, id, x_offset, y_offset); + return 0; +} + static int nk_love_tree_push(lua_State *L) { int argc = lua_gettop(L); @@ -3020,6 +3064,28 @@ static int nk_love_popup(lua_State *L) return 0; } +static int nk_love_popup_get_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 1); + nk_love_assert_context(1); + nk_uint offset_x, offset_y; + nk_popup_get_scroll(&context->nkctx, &offset_x, &offset_y); + lua_pushinteger(L, offset_x); + lua_pushinteger(L, offset_y); + return 2; +} + +static int nk_love_popup_set_scroll(lua_State *L) +{ + nk_love_assert_argc(lua_gettop(L) == 3); + nk_love_assert_context(1); + nk_uint offset_x, offset_y; + offset_x = luaL_checkinteger(L, 2); + offset_y = luaL_checkinteger(L, 3); + nk_popup_set_scroll(&context->nkctx, offset_x, offset_y); + return 0; +} + static int nk_love_combobox(lua_State *L) { int argc = lua_gettop(L); @@ -3067,14 +3133,14 @@ static int nk_love_combobox(lua_State *L) if (argc >= 6 && !lua_isnil(L, 6)) size.y = luaL_checknumber(L, 6); if (lua_isnumber(L, 2)) { - int value = lua_tointeger(L, 2) - 1; + int value = luaL_checkinteger(L, 2) - 1; value = nk_combo(&context->nkctx, combobox_items, i, value, item_height, size); lua_pushnumber(L, value + 1); } else if (lua_istable(L, 2)) { lua_getfield(L, 2, "value"); if (!lua_isnumber(L, -1)) luaL_argerror(L, 2, "should have a number value"); - int value = lua_tointeger(L, -1) - 1; + int value = luaL_checkinteger(L, -1) - 1; int old = value; nk_combobox(&context->nkctx, combobox_items, i, &value, item_height, size); int changed = value != old; @@ -4449,6 +4515,7 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState) NK_LOVE_REGISTER("windowGetBounds", nk_love_window_get_bounds); NK_LOVE_REGISTER("windowGetPosition", nk_love_window_get_position); NK_LOVE_REGISTER("windowGetSize", nk_love_window_get_size); + NK_LOVE_REGISTER("windowGetScroll", nk_love_window_get_scroll); NK_LOVE_REGISTER("windowGetContentRegion", nk_love_window_get_content_region); NK_LOVE_REGISTER("windowHasFocus", nk_love_window_has_focus); NK_LOVE_REGISTER("windowIsCollapsed", nk_love_window_is_collapsed); @@ -4462,6 +4529,7 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState) NK_LOVE_REGISTER("windowSetPosition", nk_love_window_set_position); NK_LOVE_REGISTER("windowSetSize", nk_love_window_set_size); NK_LOVE_REGISTER("windowSetFocus", nk_love_window_set_focus); + NK_LOVE_REGISTER("windowSetScroll", nk_love_window_set_scroll); NK_LOVE_REGISTER("windowClose", nk_love_window_close); NK_LOVE_REGISTER("windowCollapse", nk_love_window_collapse); NK_LOVE_REGISTER("windowExpand", nk_love_window_expand); @@ -4490,6 +4558,8 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState) NK_LOVE_REGISTER("groupBegin", nk_love_group_begin); NK_LOVE_REGISTER("groupEnd", nk_love_group_end); NK_LOVE_REGISTER("group", nk_love_group); + NK_LOVE_REGISTER("groupGetScroll", nk_love_group_get_scroll); + NK_LOVE_REGISTER("groupSetScroll", nk_love_group_set_scroll); NK_LOVE_REGISTER("treePush", nk_love_tree_push); NK_LOVE_REGISTER("treePop", nk_love_tree_pop); @@ -4519,6 +4589,8 @@ LUALIB_API int luaopen_nuklear(lua_State *luaState) NK_LOVE_REGISTER("popupClose", nk_love_popup_close); NK_LOVE_REGISTER("popupEnd", nk_love_popup_end); NK_LOVE_REGISTER("popup", nk_love_popup); + NK_LOVE_REGISTER("popupGetScroll", nk_love_popup_get_scroll); + NK_LOVE_REGISTER("popupSetScroll", nk_love_popup_set_scroll); NK_LOVE_REGISTER("combobox", nk_love_combobox); NK_LOVE_REGISTER("comboboxBegin", nk_love_combobox_begin); NK_LOVE_REGISTER("comboboxItem", nk_love_combobox_item);