Attempt to add support for 9-slice

Renders oddly; clearly there's something I'm missing either in the lua,
love2d, or nuklear API.
This commit is contained in:
John Emhoff 2023-09-05 18:20:31 -04:00
parent 8d092eefa4
commit ea9aa4c463
2 changed files with 25 additions and 2 deletions

View file

@ -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'

View file

@ -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);
}