More utils. Will move to generic utils.

This commit is contained in:
David Lannan 2024-11-05 21:32:35 +10:30
parent 48c1a0d69c
commit e4c6315ac5
34 changed files with 283 additions and 219 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 648 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -19,17 +19,30 @@ local stb = require("stb")
local ffi = require("ffi")
-- --------------------------------------------------------------------------------------
-- For win - sleep so as to not consume all proc cycles for ui
ffi.cdef[[
void Sleep(uint32_t ms);
]]
-- --------------------------------------------------------------------------------------
local config = require("config.settings")
local wdgts = require("utils.widgets")
local fonts = require("utils.fonts")
local icons = ffi.new("struct nk_image [?]", 10)
-- --------------------------------------------------------------------------------------
local fonts = nil
local atlas = ffi.new("struct nk_font_atlas[1]")
local icons = ffi.new("struct nk_image [?]", 10)
local myfonts = nil
local font_list = {
{ font_file = "fontawesome-webfont.ttf", font_size = 30.0, range = nk.nk_font_awesome_glyph_ranges() },
{ font_file = "Rubik-Light.ttf", font_size = 16.0 },
{ font_file = "Rubik-Regular.ttf", font_size = 20.0 },
{ font_file = "Rubik-Bold.ttf", font_size = 21.0 },
}
-- --------------------------------------------------------------------------------------
@ -39,125 +52,8 @@ local icons = ffi.new("struct nk_image [?]", 10)
-- Note: Many vars are locally set or globals. This was from a direct C conversion.
-- To make static vars workaround then place them below.
local show_menu = ffi.new("bool[1]", {nk.nk_true})
local border = ffi.new("bool[1]", {nk.nk_true})
local resize = ffi.new("bool[1]", {nk.nk_true})
local movable = ffi.new("bool[1]", {nk.nk_true})
local no_scrollbar = ffi.new("bool[1]", {nk.nk_false})
local scale_left = ffi.new("bool[1]", {nk.nk_false})
local winrect = ffi.new("struct nk_rect[1]", {{10, 25, 1000, 600}})
-- /* window flags */
local window_flags = 0
local minimizable = ffi.new("bool[1]", {nk.nk_true})
-- /* popups */
local header_align = nk.NK_HEADER_RIGHT
local master_img_width = ffi.new("int[1]", 0)
local master_img_height = ffi.new("int[1]", 0)
-- --------------------------------------------------------------------------------------
local function font_loader( atlas, font_file, font_size, cfg)
local newfont = nk.nk_font_atlas_add_from_file(atlas, font_file, font_size, cfg)
local image = nk.nk_font_atlas_bake(atlas, master_img_width, master_img_height, nk.NK_FONT_ATLAS_RGBA32)
return image, newfont
end
-- --------------------------------------------------------------------------------------
local function font_atlas_img( image )
local sg_img_desc = ffi.new("sg_image_desc[1]")
sg_img_desc[0].width = master_img_width[0]
sg_img_desc[0].height = master_img_height[0]
sg_img_desc[0].pixel_format = sg.SG_PIXELFORMAT_RGBA8
sg_img_desc[0].sample_count = 1
sg_img_desc[0].data.subimage[0][0].ptr = image
sg_img_desc[0].data.subimage[0][0].size = master_img_width[0] * master_img_height[0] * 4
local new_img = sg.sg_make_image(sg_img_desc)
-- // create a sokol-nuklear image object which associates an sg_image with an sg_sampler
local img_desc = ffi.new("snk_image_desc_t[1]")
img_desc[0].image = new_img
local snk_img = nk.snk_make_image(img_desc)
local nk_hnd = nk.snk_nkhandle(snk_img)
return nk_hnd
end
-- --------------------------------------------------------------------------------------
-- Setup fonts
local function setup_font(ctx)
fonts = {}
local font_path = "font/"
local image = nil
nk.nk_font_atlas_init_default(atlas)
nk.nk_font_atlas_begin(atlas)
image = nk.nk_font_atlas_bake(atlas, master_img_width, master_img_height, nk.NK_FONT_ATLAS_RGBA32)
atlas[0].config.range = nk.nk_font_awesome_glyph_ranges()
image, fonts[1] = font_loader(atlas, font_path.."fontawesome-webfont.ttf", 40.0, atlas[0].config)
image, fonts[2] = font_loader(atlas, font_path.."Rubik-Light.ttf", 16.0, nil)
image, fonts[3] = font_loader(atlas, font_path.."Rubik-Regular.ttf", 20.0, nil)
image, fonts[4] = font_loader(atlas, font_path.."Rubik-Bold.ttf", 24.0, nil)
-- Dump the atlas to check it.
stb.stbi_write_png( "font/atlas_font.png", master_img_width[0], master_img_height[0], 4, image, master_img_width[0] * 4)
-- print(master_img_width[0], master_img_height[0], 4)
local nk_img = font_atlas_img(image)
nk.nk_font_atlas_end(atlas, nk_img, nil)
nk.nk_font_atlas_cleanup(atlas)
nk.nk_style_load_all_cursors(ctx, atlas[0].cursors)
nk.nk_style_set_font(ctx, fonts[1].handle)
end
-- --------------------------------------------------------------------------------------
-- returns struct nk_image
local function icon_load(filename)
local x = ffi.new("int[1]", {0})
local y = ffi.new("int[1]", {0})
local n = ffi.new("int[1]", {4})
local data = stb.stbi_load(filename, x, y, nil, 4)
if (data == nil) then error("[STB]: failed to load image: "..filename); end
print("Image Loaded: "..filename.." Width: "..x[0].." Height: "..y[0].." Channels: "..n[0])
local pixformat = sg.SG_PIXELFORMAT_RGBA8
local sg_img_desc = ffi.new("sg_image_desc[1]")
sg_img_desc[0].width = x[0]
sg_img_desc[0].height = y[0]
sg_img_desc[0].pixel_format = pixformat
sg_img_desc[0].sample_count = 1
sg_img_desc[0].data.subimage[0][0].ptr = data
sg_img_desc[0].data.subimage[0][0].size = x[0] * y[0] * n[0]
local new_img = sg.sg_make_image(sg_img_desc)
-- // create a sokol-nuklear image object which associates an sg_image with an sg_sampler
local img_desc = ffi.new("snk_image_desc_t[1]")
img_desc[0].image = new_img
local snk_img = nk.snk_make_image(img_desc)
local nk_hnd = nk.snk_nkhandle(snk_img)
local nk_img = nk.nk_image_handle(nk_hnd);
stb.stbi_image_free(data)
return nk_img
end
-- --------------------------------------------------------------------------------------
local pix = {}
@ -177,7 +73,7 @@ local function init(void)
nk.snk_setup(snk)
local base_path = "./"
pix["baboon"] = icon_load(base_path.."images/baboon.png")
pix["baboon"] = wdgts.icon_load(base_path.."images/baboon.png")
-- pix["copy"] = icon_load(base_path.."icon/copy.png")
-- pix["del"] = icon_load(base_path.."icon/delete.png")
-- pix["rocket"] = icon_load(base_path.."icon/rocket.png")
@ -223,9 +119,16 @@ end
-- --------------------------------------------------------------------------------------
-- TODO: These to all go into config
local group_width = ffi.new("int[1]", {320})
local group_height = ffi.new("int[1]", {200})
local project_path = ffi.new("char[256]")
local project_path_len = ffi.new("int[1]")
local project_startup_file = ffi.new("char[256]")
local project_startup_file_len = ffi.new("int[1]")
local project_name = ffi.new("char[256]")
local project_name_len = ffi.new("int[1]")
@ -235,10 +138,11 @@ local platforms = { "Win64", "MacOS", "Linux", "IOS64" }
local res_selected = 1
local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768" }
-- --------------------------------------------------------------------------------------
local function project_panel(ctx)
nk.nk_style_set_font(ctx, fonts[3].handle)
nk.nk_style_set_font(ctx, myfonts[3].handle)
local bounds = nk.nk_window_get_content_region(ctx)
local prop_col = bounds.w * 0.25
@ -255,6 +159,17 @@ local function project_panel(ctx)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, "Project Path:", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, value_col * 0.9)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, project_path, project_path_len, 256, nk.nk_filter_default)
nk.nk_layout_row_push(ctx, value_col * 0.1)
if(nk.nk_button_label(ctx, ffi.string("...")) == true) then
print("pressed")
end
nk.nk_layout_row_end(ctx)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, "sokol-luajit Path:", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, value_col * 0.9)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, project_name, project_name_len, 256, nk.nk_filter_default)
nk.nk_layout_row_push(ctx, value_col * 0.1)
if(nk.nk_button_label(ctx, ffi.string("...")) == true) then
@ -262,6 +177,17 @@ local function project_panel(ctx)
end
nk.nk_layout_row_end(ctx)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, "Startup Lua File:", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, value_col * 0.9)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, project_startup_file, project_startup_file_len, 256, nk.nk_filter_default)
nk.nk_layout_row_push(ctx, value_col * 0.1)
if(nk.nk_button_label(ctx, ffi.string("...")) == true) then
print("pressed")
end
nk.nk_layout_row_end(ctx)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, "Platform Target:", nk.NK_TEXT_LEFT)
@ -282,10 +208,14 @@ local function project_panel(ctx)
end
-- --------------------------------------------------------------------------------------
local curr_tab = 1
local tabs = { "Lua Source", "Images", "Data" }
local function properties_panel(ctx)
local function assets_panel(ctx)
nk.nk_style_set_font(ctx, fonts[3].handle)
nk.nk_style_set_font(ctx, myfonts[3].handle)
curr_tab = wdgts.widget_notebook(ctx, tabs, curr_tab, 120)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, 50)
@ -306,72 +236,30 @@ end
-- --------------------------------------------------------------------------------------
local function panel_properties_function(data, left, top, width, height)
properties_panel(data.ctx)
local function panel_assets_function(data, left, top, width, height)
assets_panel(data.ctx)
end
-- --------------------------------------------------------------------------------------
local function main_ui(ctx)
if(fonts == nil) then
setup_font(ctx)
if(myfonts == nil) then
myfonts = fonts.setup_font(ctx, font_list)
end
nk.nk_style_set_font(ctx, fonts[4].handle)
nk.nk_style_set_font(ctx, myfonts[4].handle)
local flags = bit.bor(nk.NK_WINDOW_TITLE, nk.NK_WINDOW_BORDER)
local height = sapp.sapp_height() - 20
local width = sapp.sapp_width() / 2 - 15
wdgts.widget_panel_fixed(ctx, "Project", 10, 10, width, height, flags, panel_project_function, {ctx=ctx})
nk.nk_style_set_font(ctx, fonts[4].handle)
nk.nk_style_set_font(ctx, myfonts[4].handle)
local height = sapp.sapp_height() - 20
local width = sapp.sapp_width() / 2 - 15
wdgts.widget_panel_fixed(ctx, "Properties", 10+width+10, 10, width, height, flags, panel_properties_function, {ctx=ctx})
-- if (nk.nk_begin(ctx, "rbuild", winrect[0], window_flags) == true) then
-- if (show_menu[0] == true) then
-- /* menubar */
-- local menu_states = { MENU_DEFAULT = 0, MENU_WINDOWS = 1}
-- nk.nk_menubar_begin(ctx)
-- -- /* menu #1 */
-- nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 40, 5)
-- nk.nk_layout_row_push(ctx, 40)
-- nk.nk_image(ctx, pix["baboon"])
-- /*------------------------------------------------
-- * CONTEXTUAL
-- *------------------------------------------------*/
-- if (nk.nk_contextual_begin(ctx, nk.NK_WINDOW_NO_SCROLLBAR, nk.nk_vec2(150, 300), nk.nk_window_get_bounds(ctx)) == true) then
-- nk.nk_layout_row_dynamic(ctx, 30, 1);
-- if (nk.nk_contextual_item_image_label(ctx, pix.copy, "Clone", nk.NK_TEXT_RIGHT) == true) then
-- print("pressed clone!\n")
-- end
-- if (nk.nk_contextual_item_image_label(ctx, pix.del, "Delete", nk.NK_TEXT_RIGHT) == true) then
-- print("pressed delete!\n")
-- end
-- if (nk.nk_contextual_item_image_label(ctx, pix.rocket, "Rocket", nk.NK_TEXT_RIGHT) == true) then
-- print("pressed rocket!\n")
-- end
-- if (nk.nk_contextual_item_image_label(ctx, pix.edit, "Edit", nk.NK_TEXT_RIGHT) == true) then
-- print("pressed edit!\n")
-- end
-- nk.nk_contextual_end(ctx)
-- end
-- nk.nk_layout_row_end(ctx)
-- end
-- nk.nk_end(ctx)
-- end
wdgts.widget_panel_fixed(ctx, "Assets", 10+width+10, 10, width, height, flags, panel_assets_function, {ctx=ctx})
return not nk.nk_window_is_closed(ctx, "Overview")
end
@ -382,7 +270,6 @@ local function frame(void)
local ctx = nk.snk_new_frame()
current_ctx = ctx
-- // see big function at end of file
main_ui(ctx)
-- // the sokol_gfx draw pass
@ -395,6 +282,8 @@ local function frame(void)
nk.snk_render(sapp.sapp_width(), sapp.sapp_height())
sg.sg_end_pass()
sg.sg_commit()
ffi.C.Sleep(3)
end
-- --------------------------------------------------------------------------------------

View File

@ -0,0 +1,94 @@
local sapp = require("sokol_app")
sg = require("sokol_nuklear")
local nk = sg
local slib = require("sokol_libs") -- Warn - always after gfx!!
local hmm = require("hmm")
local hutils = require("hmm_utils")
local stb = require("stb")
local ffi = require("ffi")
-- --------------------------------------------------------------------------------------
local fonts = {
master_img_width = ffi.new("int[1]", 0),
master_img_height = ffi.new("int[1]", 0),
atlas = ffi.new("struct nk_font_atlas[1]"),
}
-- --------------------------------------------------------------------------------------
local function font_loader( atlas, font_file, font_size, cfg)
local newfont = nk.nk_font_atlas_add_from_file(atlas, font_file, font_size, cfg)
local image = nk.nk_font_atlas_bake(atlas, fonts.master_img_width, fonts.master_img_height, nk.NK_FONT_ATLAS_RGBA32)
return image, newfont
end
-- --------------------------------------------------------------------------------------
local function font_atlas_img( image )
local sg_img_desc = ffi.new("sg_image_desc[1]")
sg_img_desc[0].width = fonts.master_img_width[0]
sg_img_desc[0].height = fonts.master_img_height[0]
sg_img_desc[0].pixel_format = sg.SG_PIXELFORMAT_RGBA8
sg_img_desc[0].sample_count = 1
sg_img_desc[0].data.subimage[0][0].ptr = image
sg_img_desc[0].data.subimage[0][0].size = fonts.master_img_width[0] * fonts.master_img_height[0] * 4
local new_img = sg.sg_make_image(sg_img_desc)
-- // create a sokol-nuklear image object which associates an sg_image with an sg_sampler
local img_desc = ffi.new("snk_image_desc_t[1]")
img_desc[0].image = new_img
local snk_img = nk.snk_make_image(img_desc)
local nk_hnd = nk.snk_nkhandle(snk_img)
return nk_hnd
end
-- --------------------------------------------------------------------------------------
-- Setup fonts
fonts.setup_font = function(ctx, font_list)
local atlas = fonts.atlas
local font_path = fonts.path or "fonts/"
local image = nil
nk.nk_font_atlas_init_default(atlas)
nk.nk_font_atlas_begin(atlas)
image = nk.nk_font_atlas_bake(atlas, fonts.master_img_width, fonts.master_img_height, nk.NK_FONT_ATLAS_RGBA32)
local font_handles = {}
for i,v in ipairs(font_list) do
if(v.range) then
atlas[0].config.range = v.range
image, v.font = font_loader(atlas, font_path..v.font_file, v.font_size, atlas[0].config)
else
image, v.font = font_loader(atlas, font_path..v.font_file, v.font_size, nil)
end
table.insert(font_handles, v.font)
end
-- Dump the atlas to check it.
stb.stbi_write_png( font_path.."atlas_font.png", fonts.master_img_width[0], fonts.master_img_height[0], 4, image, fonts.master_img_width[0] * 4)
-- print(master_img_width[0], master_img_height[0], 4)
local nk_img = font_atlas_img(image)
nk.nk_font_atlas_end(atlas, nk_img, nil)
nk.nk_font_atlas_cleanup(atlas)
nk.nk_style_load_all_cursors(ctx, atlas[0].cursors)
return font_handles
end
-- --------------------------------------------------------------------------------------
return fonts
-- --------------------------------------------------------------------------------------

View File

@ -144,7 +144,132 @@ end
--------------------------------------------------------------------------------
local piemenu_pos = nk.nk_vec2(0,0)
local piemenu_active = 0
widgets.make_pie_popup = function(ctx, icons, pie_size, pie_count)
pie_size = pie_size or 140
pie_count = pie_count or 6
if ((nk.nk_input_is_mouse_click_down_in_rect(ctx.input, nk.NK_BUTTON_RIGHT, nk.nk_window_get_bounds(ctx),nk.nk_true) == true) and
piemenu_active == 0) then
piemenu_pos = nk.nk_vec2(ctx.input.mouse.pos.x, ctx.input.mouse.pos.y)
piemenu_active = 1
end
local ret = -1
if (piemenu_active == 1) then
ret = widgets.widget_pie_menu(ctx, piemenu_pos.x, piemenu_pos.y, pie_size, icons, pie_count)
if (ret == -2) then piemenu_active = 0 end
if (ret ~= -1) then
piemenu_active = 0
end
end
return ret
end
--------------------------------------------------------------------------------
widgets.widget_notebook = function(ctx, tabs, current_tab, tab_fixed_width)
local step = (2*3.141592654) / 32
local chart_type = {CHART_LINE=1, CHART_HISTO=2, CHART_MIXED=3}
-- /* Header */
nk.nk_style_push_vec2(ctx, ctx[0].style.window.spacing, nk.nk_vec2(0,0))
local rnding = ffi.new("float[1]", {ctx[0].style.button.rounding})
nk.nk_style_push_float(ctx, rnding, 0)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 20, 3)
for i = 1, table.getn(tabs) do
-- /* make sure button perfectly fits text */
local f = ctx[0].style.font
local text_width = tab_fixed_width or f.width(f.userdata, f.height, tabs[i], string.len(tabs[i]))
local widget_width = text_width + 4 * ctx[0].style.button.padding.x
nk.nk_layout_row_push(ctx, widget_width)
if (current_tab == i) then
-- /* active tab gets highlighted */
local button_color = ctx[0].style.button.normal
ctx[0].style.button.normal = ctx[0].style.button.active
if (nk.nk_button_label(ctx, tabs[i]) == true ) then current_tab = i end
ctx[0].style.button.normal = button_color
else
if(nk.nk_button_label(ctx, tabs[i]) == true) then current_tab = i end
end
end
nk.nk_style_pop_float(ctx)
-- /* Body */
nk.nk_layout_row_dynamic(ctx, 140, 1)
if (nk.nk_group_begin(ctx, "Notebook", nk.NK_WINDOW_BORDER) == true) then
nk.nk_style_pop_vec2(ctx)
if(current_tab == chart_type.CHART_LINE) then
nk.nk_layout_row_dynamic(ctx, 100, 1)
if (nk.nk_chart_begin_colored(ctx, nk.NK_CHART_LINES, nk.nk_rgb(255,0,0), nk.nk_rgb(150,0,0), 32, 0.0, 1.0)) then
nk.nk_chart_add_slot_colored(ctx, nk.NK_CHART_LINES, nk.nk_rgb(0,0,255), nk.nk_rgb(0,0,150),32, -1.0, 1.0)
local id = 0
for i = 0, 32 -1 do
nk.nk_chart_push_slot(ctx, math.abs(math.sin(id)), 0)
nk.nk_chart_push_slot(ctx, math.cos(id), 1)
id = id + step
end
end
nk.nk_chart_end(ctx)
elseif(current_tab == chart_type.CHART_HISTO) then
nk.nk_layout_row_dynamic(ctx, 100, 1)
if (nk.nk_chart_begin_colored(ctx, nk.NK_CHART_COLUMN, nk.nk_rgb(255,0,0), nk.nk_rgb(150,0,0), 32, 0.0, 1.0)) then
local id = 0
for i = 0, 32-1 do
nk.nk_chart_push_slot(ctx, math.abs(math.sin(id)), 0)
id = id + step
end
end
nk.nk_chart_end(ctx)
elseif(current_tab == chart_type.CHART_MIXED) then
nk.nk_layout_row_dynamic(ctx, 100, 1)
if (nk.nk_chart_begin_colored(ctx, nk.NK_CHART_LINES, nk.nk_rgb(255,0,0), nk.nk_rgb(150,0,0), 32, 0.0, 1.0)) then
nk.nk_chart_add_slot_colored(ctx, nk.NK_CHART_LINES, nk.nk_rgb(0,0,255), nk.nk_rgb(0,0,150),32, -1.0, 1.0)
nk.nk_chart_add_slot_colored(ctx, nk.NK_CHART_COLUMN, nk.nk_rgb(0,255,0), nk.nk_rgb(0,150,0), 32, 0.0, 1.0)
local id = 0
for i = 0, 32-1 do
nk.nk_chart_push_slot(ctx, math.abs(math.sin(id)), 0)
nk.nk_chart_push_slot(ctx, math.abs(math.cos(id)), 1)
nk.nk_chart_push_slot(ctx, math.abs(math.sin(id)), 2)
id = id + step
end
end
nk.nk_chart_end(ctx)
end
nk.nk_group_end(ctx)
else
nk.nk_style_pop_vec2(ctx)
end
return current_tab
end
--------------------------------------------------------------------------------
widgets.widget_combo_box = function(ctx, items, selected_item, height)
local buffer = ffi.string(items[selected_item])
if (nk.nk_combo_begin_label(ctx, buffer, nk.nk_vec2(nk.nk_widget_width(ctx), height)) == true) then
nk.nk_layout_row_dynamic(ctx, 35, 1);
local count = table.getn(items)
for i = 1, count do
if (nk.nk_combo_item_label(ctx, ffi.string(items[i]), nk.NK_TEXT_LEFT) == true) then
selected_item = i
end
end
nk.nk_combo_end(ctx)
end
return selected_item
end
--------------------------------------------------------------------------------
-- returns struct nk_image
widgets.icon_load = function(filename)
local x = ffi.new("int[1]", {0})
@ -181,50 +306,6 @@ end
--------------------------------------------------------------------------------
local piemenu_pos = nk.nk_vec2(0,0)
local piemenu_active = 0
widgets.make_pie_popup = function(ctx, icons, pie_size, pie_count)
pie_size = pie_size or 140
pie_count = pie_count or 6
if ((nk.nk_input_is_mouse_click_down_in_rect(ctx.input, nk.NK_BUTTON_RIGHT, nk.nk_window_get_bounds(ctx),nk.nk_true) == true) and
piemenu_active == 0) then
piemenu_pos = nk.nk_vec2(ctx.input.mouse.pos.x, ctx.input.mouse.pos.y)
piemenu_active = 1
end
local ret = -1
if (piemenu_active == 1) then
ret = widgets.widget_pie_menu(ctx, piemenu_pos.x, piemenu_pos.y, pie_size, icons, pie_count)
if (ret == -2) then piemenu_active = 0 end
if (ret ~= -1) then
piemenu_active = 0
end
end
return ret
end
--------------------------------------------------------------------------------
widgets.widget_combo_box = function(ctx, items, selected_item, height)
local buffer = ffi.string(items[selected_item])
if (nk.nk_combo_begin_label(ctx, buffer, nk.nk_vec2(nk.nk_widget_width(ctx), height)) == true) then
nk.nk_layout_row_dynamic(ctx, 35, 1);
local count = table.getn(items)
for i = 1, count do
if (nk.nk_combo_item_label(ctx, ffi.string(items[i]), nk.NK_TEXT_LEFT) == true) then
selected_item = i
end
end
nk.nk_combo_end(ctx)
end
return selected_item
end
--------------------------------------------------------------------------------
return widgets
--------------------------------------------------------------------------------