From ea9aa4c463aeb1b8e20f244b2cfb62e3f5b90c77 Mon Sep 17 00:00:00 2001 From: John Emhoff Date: Tue, 5 Sep 2023 18:20:31 -0400 Subject: [PATCH] Attempt to add support for 9-slice Renders oddly; clearly there's something I'm missing either in the lua, love2d, or nuklear API. --- example/skin.lua | 6 +++++- src/nuklear_love.c | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/example/skin.lua b/example/skin.lua index 77827b4..0303cf9 100644 --- a/example/skin.lua +++ b/example/skin.lua @@ -6,10 +6,14 @@ 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)} + +-- last 4 args are 9-patch t/l/b/r. These are encoded as the number of pixels from the corresponding +-- edge (e.g. "4" for "r" means "4 pixels from the right edge", or w - 4). +local buttonNormal = {buttonTexture, love.graphics.newQuad(0, 0, 69, 52, 69, 156), 25, 12, 22, 12} + local style = { ['text'] = { ['color'] = '#000000' diff --git a/src/nuklear_love.c b/src/nuklear_love.c index a740913..ffb9f8a 100644 --- a/src/nuklear_love.c +++ b/src/nuklear_love.c @@ -3681,7 +3681,26 @@ static int nk_love_style_push_item(lua_State *L, struct nk_style_item *field) } item.type = NK_STYLE_ITEM_COLOR; item.data.color = nk_love_checkcolor(L, -1); - } else { + } else if (lua_istable(L, -1) && lua_objlen(L, -1) == 6) { + item.type = NK_STYLE_ITEM_NINE_SLICE; + + int index = lua_gettop(L); + nk_love_checkImage(L, -1, &item.data.slice.img); + + lua_rawgeti(L, index, 3); + item.data.slice.l = lua_tointeger(L, -1); + + lua_rawgeti(L, index, 4); + item.data.slice.t = lua_tointeger(L, -1); + + lua_rawgeti(L, index, 5); + item.data.slice.r = lua_tointeger(L, -1); + + lua_rawgeti(L, index, 6); + item.data.slice.b = lua_tointeger(L, -1); + lua_pop(L, 4); + } + else { item.type = NK_STYLE_ITEM_IMAGE; nk_love_checkImage(L, -1, &item.data.image); }