Added folder selection

This commit is contained in:
David Lannan 2024-11-17 23:30:11 +10:30
parent 3fb2569dc5
commit d568386a18
13 changed files with 611 additions and 356 deletions

View File

@ -4,12 +4,20 @@ local ffi = require("ffi")
-- ------------------------------------------------------------------------------------------------------ -- ------------------------------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------------------------------
-- The main module table
local settings = {}
-- Default settings if none are loaded or found
local default_settings = [[
local platforms = { "Win64", "MacOS", "Linux", "IOS64" } local platforms = { "Win64", "MacOS", "Linux", "IOS64" }
local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768" } local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768" }
local arch = { "x86", "x64", "arm", "arm64", "arm64be", "ppc", "mips", "mipsel", "mips64", "mips64el", "mips64r6", "mips64r6el" } local arch = { "x86", "x64", "arm", "arm64", "arm64be", "ppc", "mips", "mipsel", "mips64", "mips64el", "mips64r6", "mips64r6el" }
local oss = { "Windows", "Linux", "OSX", "BSD", "POSIX", "Other" } local oss = { "Windows", "Linux", "OSX", "BSD", "POSIX", "Other" }
local settings = { local default = {
rbuilder = { rbuilder = {
appname = { index = 1, value = "rbuild", slen = 7 }, appname = { index = 1, value = "rbuild", slen = 7 },
@ -24,7 +32,7 @@ local settings = {
}, },
project = { project = {
project_name = { index = 1, value = "default", slen = 64 }, project_name = { index = 1, value = "default", ptype = "string", slen = 64 },
project_path = { index = 2, value = "./", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file. project_path = { index = 2, value = "./", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
project_file = { index = 3, value = "default.slp", ptype = "file", slen = 64 }, -- Sokol luajit project file project_file = { index = 3, value = "default.slp", ptype = "file", slen = 64 }, -- Sokol luajit project file
project_start = { index = 4, value = "example1.lua", ptype = "file", slen = 128 }, project_start = { index = 4, value = "example1.lua", ptype = "file", slen = 128 },
@ -60,15 +68,54 @@ local settings = {
-- Assets will be populated by project file -- Assets will be populated by project file
assets = { assets = {
lua = {},
images = {},
data = {},
}, },
} }
local title = settings.rbuilder.appname.value.." ("..settings.rbuilder.version.value..")" return default
settings.rbuilder.title = { value = title, slen = 32 } ]]
-- ------------------------------------------------------------------------------------------------------ -- ------------------------------------------------------------------------------------------------------
local function loadconfig(projectpath)
local res = nil
local fh = io.open(projectpath, "r")
if(fh) then
res = fh:read("*a")
fh:close()
res = load(res)()
print(res)
else
print("[Error] settings.load - unable to load config: "..projectpath)
end
return res
end
-- ------------------------------------------------------------------------------------------------------
settings.load = function( projectpath )
if( projectpath == nil ) then
projectpath = "./projects/default.slp"
-- Attempt to load it. If it fails, this is the first time run! save a default!
local fh = io.open(projectpath, "r")
if(fh == nil) then
fh = io.open(projectpath, "w")
fh:write(default_settings)
end
fh:close()
end
-- Load the project settings into the local config
settings.config = loadconfig(projectpath)
local title = settings.config.rbuilder.appname.value.." ("..settings.config.rbuilder.version.value..")"
settings.config.rbuilder.title = { value = title, slen = 32 }
return settings.config
end
-- ------------------------------------------------------------------------------------------------------ -- ------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,64 @@
local platforms = { "Win64", "MacOS", "Linux", "IOS64" }
local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768" }
local arch = { "x86", "x64", "arm", "arm64", "arm64be", "ppc", "mips", "mipsel", "mips64", "mips64el", "mips64r6", "mips64r6el" }
local oss = { "Windows", "Linux", "OSX", "BSD", "POSIX", "Other" }
local default = {
rbuilder = {
appname = { index = 1, value = "rbuild", slen = 7 },
version = { index = 2, value = "00.01.snow", slen = 32 },
},
platform = {
target = { index = 1, value = 1, ptype = "combo", plist = platforms },
srlua_path = { index = 2, value = "../srlua/", ptype = "path", slen = 256 }, -- initially rbuild will run for the tools/build/rbuilder folder
arch = { index = 3, value = 2, ptype = "combo", plist = arch },
os = { index = 4, value = 1, ptype = "combo", plist = oss },
},
project = {
project_name = { index = 1, value = "default", ptype = "string", slen = 64 },
project_path = { index = 2, value = "./", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
project_file = { index = 3, value = "default.slp", ptype = "file", slen = 64 }, -- Sokol luajit project file
project_start = { index = 4, value = "example1.lua", ptype = "file", slen = 128 },
},
graphics = {
display_res = { index = 1, value = 1, ptype = "combo", plist = resolutions },
display_width = { index = 2, value = 1024, vmin = 640, vmax = 8192, vstep = 32, vinc = 0.1, ptype = "int" },
display_height = { index = 3, value = 768, vmin = 480, vmax = 8192, vstep = 32, vinc = 0.1, ptype = "int" },
display_fps = { index = 4, value = 60, vmin = 25, vmax = 200, vstep = 5, vinc = 0.1, ptype = "int" },
antialias = { index = 5, value = "fxaa", slen = 16 },
},
audio = {
master_volume = { index = 1, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
effects_volume = { index = 2, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
music_volume = { index = 3, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
},
sokol = {
sokol_path = { index = 1, value = "../../../../", ptype = "path", slen = 256 },
sokol_bin = { index = 2, value = "bin/", ptype = "path", slen = 256 },
sokol_ffi = { index = 3, value = "ffi/", ptype = "path", slen = 256 },
sokol_lua = { index = 4, value = "lua/", ptype = "path", slen = 256 },
sokol_examples = { index = 5, value = "examples/", ptype = "path", slen = 256 },
},
remote = {
-- These are futures --
remote_build = { index = 1, value = "https://mybuildserver.com/sokol_build", slen = 256 },
remote_data = { index = 2, value = "https://myremotedata.com/data", slen = 256 },
},
-- Assets will be populated by project file
assets = {
lua = {},
images = {},
data = {},
},
}
return default

View File

@ -19,88 +19,16 @@ local stb = require("stb")
local ffi = require("ffi") local ffi = require("ffi")
local panel = require("ui.panels")
-- -------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------
-- For win - sleep so as to not consume all proc cycles for ui -- For win - sleep so as to not consume all proc cycles for ui
ffi.cdef[[ ffi.cdef[[
void Sleep(uint32_t ms); 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 myfonts = nil
local font_list = {
{ font_file = "fontawesome-webfont.ttf", font_size = 16.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 },
}
-- --------------------------------------------------------------------------------------
local folder_select = {
popup_active = 0,
popup_dim = ffi.new("struct nk_rect",{20, 100, 220, 90}),
folder_path = ".",
ui_func = function(ctx, dim, udata)
nk.nk_layout_row_dynamic(ctx, 25, 1)
nk.nk_label(ctx, "A terrible error as occured", nk.NK_TEXT_LEFT)
nk.nk_layout_row_dynamic(ctx, 25, 2)
if (nk.nk_button_label(ctx, "OK") == true) then
udata.popup_active = 0
nk.nk_popup_close(ctx)
end
if (nk.nk_button_label(ctx, "WTF") == true) then
udata.popup_active = 0
nk.nk_popup_close(ctx)
end
return udata.popup_active
end,
}
-- --------------------------------------------------------------------------------------
local visited = {}
local function tdump(o, level)
local level = level or 1
if(level == 0) then visited = {} end
if type(o) == 'table' then
local s = ' {\n'
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..tostring(k)..'"' end
if(visited[v] == nil) then
visited[v] = true
s = s .. string.rep(" ", level)..'['..k..'] = ' .. tdump(v, level+1)
end
end
return s .. string.rep(" ", level-1)..'}\n'
else
return tostring(o).."\n"
end
end
-- --------------------------------------------------------------------------------------
-- Static vars
--
-- 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 winrect = ffi.new("struct nk_rect[1]", {{10, 25, 1000, 600}})
-- --------------------------------------------------------------------------------------
local pix = {}
local function init(void) local function init(void)
-- // setup sokol-gfx, sokol-time and sokol-imgui -- // setup sokol-gfx, sokol-time and sokol-imgui
local sg_desc = ffi.new("sg_desc[1]") local sg_desc = ffi.new("sg_desc[1]")
@ -115,31 +43,9 @@ local function init(void)
snk[0].logger.func = slib.slog_func snk[0].logger.func = slib.slog_func
nk.snk_setup(snk) nk.snk_setup(snk)
local base_path = "./"
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")
-- pix["edit"] = icon_load(base_path.."icon/edit.png")
sapp.sapp_show_mouse(false) sapp.sapp_show_mouse(false)
winrect[0].x = 0 panel.init()
winrect[0].y = 0
winrect[0].w = sapp.sapp_width()
winrect[0].h = sapp.sapp_height()
icons[0] = wdgts.icon_load("./icon/home.png")
icons[1] = wdgts.icon_load("./icon/phone.png")
icons[2] = wdgts.icon_load("./icon/plane.png")
icons[3] = wdgts.icon_load("./icon/wifi.png")
icons[4] = wdgts.icon_load("./icon/settings.png")
icons[5] = wdgts.icon_load("./icon/volume.png")
folder_select.popup_dim.w = sapp.sapp_width()* 0.4
folder_select.popup_dim.h = sapp.sapp_height()* 0.7
folder_select.popup_dim.x = sapp.sapp_width()/2-8 - folder_select.popup_dim.w/2
folder_select.popup_dim.y = sapp.sapp_height()/2-40 - folder_select.popup_dim.h/2
end end
-- -------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------
@ -155,8 +61,8 @@ local current_ctx = nil
local function input(event) local function input(event)
if(event.type == sapp.SAPP_EVENTTYPE_RESIZED) then if(event.type == sapp.SAPP_EVENTTYPE_RESIZED) then
nk.snk_handle_event(event) nk.snk_handle_event(event)
folder_select.popup_dim.x = sapp.sapp_width()/2 - folder_select.popup_dim.w/2 -- folder_select.popup_dim.x = sapp.sapp_width()/2 - folder_select.popup_dim.w/2
folder_select.popup_dim.y = sapp.sapp_height()/2 - folder_select.popup_dim.h -- folder_select.popup_dim.y = sapp.sapp_height()/2 - folder_select.popup_dim.h
elseif(event.type == sapp.SAPP_EVENTTYPE_MOUSE_ENTER) then elseif(event.type == sapp.SAPP_EVENTTYPE_MOUSE_ENTER) then
nk.nk_style_show_cursor(current_ctx) nk.nk_style_show_cursor(current_ctx)
sapp.sapp_show_mouse(false) sapp.sapp_show_mouse(false)
@ -168,250 +74,13 @@ local function input(event)
end end
end end
-- --------------------------------------------------------------------------------------
-- Extract config and build ffi objects for them
-- Each config property shall have a shadow ffi property labeled with _ffi
for sectionname, section in pairs(config) do
for key, prop in pairs(section) do
-- If ptype is nill or string its a string
if(prop.ptype == nil or prop.ptype == "string") then
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
elseif(prop.ptype == "combo") then
prop.ffi = ffi.new("int[1]", prop.value)
elseif(prop.ptype == "int") then
prop.ffi = ffi.new("int[1]", prop.value)
elseif(prop.ptype == "float") then
prop.ffi = ffi.new("float[1]", prop.value)
elseif(prop.ptype == "path") then
print(prop.value)
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
elseif(prop.ptype == "file") then
print(prop.value)
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
end
end
end
local group_width = ffi.new("int[1]", {320})
local group_height = ffi.new("int[1]", {200})
-- --------------------------------------------------------------------------------------
local range_float_value = ffi.new("float[1]")
local function display_section(ctx, sectionname)
local section = config[sectionname]
-- Collect the number of properties in the section
local count = 0
local sorted = {}
for k,v in pairs(section) do
count = count + 1
v.key = k
sorted[v.index] = v
end
nk.nk_layout_row_dynamic(ctx, 28 * count + 60, 1)
local bounds = nk.nk_window_get_content_region(ctx)
local prop_col = bounds.w * 0.23
local value_col = bounds.w * 0.73
local flags = bit.bor(nk.NK_WINDOW_BORDER, nk.NK_WINDOW_TITLE)
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
if (nk.nk_group_begin(ctx, sectionname, flags) == true) then
for k,v in ipairs(sorted) do
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 28, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, v.key..":", nk.NK_TEXT_LEFT)
if(v.ptype == "string" or v.ptype == nil) then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
elseif(v.ptype == "path") then
nk.nk_layout_row_push(ctx, value_col - 34)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
nk.nk_style_set_font(ctx, myfonts[1].handle)
nk.nk_layout_row_push(ctx, 30)
if(nk.nk_button_label(ctx, "") == true) then
folder_select.popup_active = 1
end
nk.nk_style_set_font(ctx, myfonts[3].handle)
elseif(v.ptype == "file") then
nk.nk_layout_row_push(ctx, value_col - 34)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
nk.nk_style_set_font(ctx, myfonts[1].handle)
nk.nk_layout_row_push(ctx, 30)
nk.nk_button_label(ctx, "")
nk.nk_style_set_font(ctx, myfonts[3].handle)
elseif(v.ptype == "combo") then
nk.nk_layout_row_push(ctx, value_col)
v.value = wdgts.widget_combo_box(ctx, v.plist, v.value, 200)
elseif(v.ptype == "int") then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_property_int(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
elseif(v.ptype == "float") then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_property_float(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
end
nk.nk_layout_row_end(ctx)
end
nk.nk_group_end(ctx)
end
end
-- --------------------------------------------------------------------------------------
local project_curr_tab = 1
local project_tabs = {
{
name = "Project",
func = function(ctx)
display_section(ctx, "project")
display_section(ctx, "sokol")
end,
},
{
name = "Build",
func = function(ctx)
display_section(ctx, "platform")
end,
},
{
name = "Logs"
}
}
-- --------------------------------------------------------------------------------------
local function project_panel(ctx)
nk.nk_style_set_font(ctx, myfonts[3].handle)
project_curr_tab = wdgts.widget_notebook(ctx, "assets", project_tabs, project_curr_tab, 500, 120)
-- display_section(ctx, "graphics")
-- display_section(ctx, "audio")
-- Awesome little radial popup.
local res = wdgts.make_pie_popup(ctx, icons, 100, 6)
end
-- --------------------------------------------------------------------------------------
local curr_tab = 1
local files = {}
-- Fill with temp file list of dir /b
local fh = io.popen("dir /b", "r")
local d = fh:read("*a")
fh:close()
for f in string.gmatch(d, "(.-)\n") do
local newfile = { name = ffi.string(f)}
newfile.select = ffi.new("nk_bool[1]")
newfile.select[0] = 0
table.insert(files, newfile)
end
local tabs = {
{
name = "Lua Source",
func = function(ctx)
local bounds = nk.nk_window_get_content_region(ctx)
nk.nk_layout_row_dynamic(ctx, bounds.h, 1)
wdgts.widget_list_selectable(ctx, "source_files", nk.NK_WINDOW_BORDER, files, bounds.w -40 )
end,
},
{
name = "Images"
},
{
name = "Data"
}
}
-- --------------------------------------------------------------------------------------
local function assets_panel(ctx)
nk.nk_style_set_font(ctx, myfonts[3].handle)
curr_tab = wdgts.widget_notebook(ctx, "assets", tabs, curr_tab, 500, 120)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, 50)
nk.nk_label(ctx, "size:", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, 130)
nk.nk_property_int(ctx, "#Width:", 100, group_width, 500, 10, 1)
nk.nk_layout_row_push(ctx, 130)
nk.nk_property_int(ctx, "#Height:", 100, group_height, 500, 10, 1)
nk.nk_layout_row_end(ctx)
end
-- --------------------------------------------------------------------------------------
local function main_ui(ctx)
if(myfonts == nil) then
myfonts = fonts.setup_font(ctx, font_list)
end
wdgts.widget_panel_fixed(ctx, "WinMain", 0, 0, sapp.sapp_width(), sapp.sapp_height(), 0, function(data)
folder_select.popup_active = wdgts.widget_popup_panel(ctx, "popup", folder_select.popup_dim, folder_select.ui_func, folder_select, folder_select.popup_active)
nk.nk_style_set_font(ctx, myfonts[4].handle)
local flags = nk.NK_WINDOW_BORDER
local height = sapp.sapp_height()
nk.nk_layout_row_dynamic(ctx, height-20, 2)
-- wdgts.widget_panel_fixed(ctx, "Project", 10, 10, width, height, flags, function(data)
if (nk.nk_group_begin(ctx, "Project", flags) == true) then
local padding = ctx[0].style.window.padding
ctx[0].style.window.padding = nk.nk_vec2(10,10)
project_panel(data.ctx)
-- end, {ctx=ctx})
nk.nk_group_end(ctx)
end
nk.nk_style_set_font(ctx, myfonts[4].handle)
-- wdgts.widget_panel_fixed(ctx, "Assets", 10+width+10, 10, width, height, flags, function(data)
if (nk.nk_group_begin(ctx, "Assets", flags) == true) then
local padding = ctx[0].style.window.padding
ctx[0].style.window.padding = nk.nk_vec2(10,10)
assets_panel(data.ctx)
-- end, {ctx=ctx})
nk.nk_group_end(ctx)
end
end, {ctx=ctx})
return not nk.nk_window_is_closed(ctx, "Overview")
end
-- -------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------
local function frame(void) local function frame(void)
local ctx = nk.snk_new_frame() local ctx = nk.snk_new_frame()
current_ctx = ctx current_ctx = ctx
panel.main_ui(ctx)
main_ui(ctx)
-- // the sokol_gfx draw pass -- // the sokol_gfx draw pass
local pass = ffi.new("sg_pass[1]") local pass = ffi.new("sg_pass[1]")
@ -436,7 +105,7 @@ app_desc[0].cleanup_cb = cleanup
app_desc[0].event_cb = input app_desc[0].event_cb = input
app_desc[0].width = 1280 app_desc[0].width = 1280
app_desc[0].height = 800 app_desc[0].height = 800
app_desc[0].window_title = config.rbuilder.title.value app_desc[0].window_title = panel.config.rbuilder.title.value
app_desc[0].icon.sokol_default = true app_desc[0].icon.sokol_default = true
app_desc[0].logger.func = slib.slog_func app_desc[0].logger.func = slib.slog_func
app_desc[0].enable_clipboard = true app_desc[0].enable_clipboard = true

View File

@ -0,0 +1,355 @@
-- --------------------------------------------------------------------------------------
local ffi = require("ffi")
local dirtools = require("tools.dirtools")
local sapp = require("sokol_app")
sg = require("sokol_nuklear")
local nk = sg
local slib = require("sokol_libs") -- Warn - always after gfx!!
-- --------------------------------------------------------------------------------------
local settings = require("config.settings")
local wdgts = require("utils.widgets")
local fonts = require("utils.fonts")
local icons = ffi.new("struct nk_image [?]", 10)
local config = settings.load()
-- --------------------------------------------------------------------------------------
-- Static vars
--
-- 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 winrect = ffi.new("struct nk_rect[1]", {{10, 25, 1000, 600}})
-- --------------------------------------------------------------------------------------
local myfonts = nil
local font_list = {
{ font_file = "fontawesome-webfont.ttf", font_size = 16.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 },
}
-- --------------------------------------------------------------------------------------
local curr_tab = 1
local tabs = {
{
name = "Lua Source",
func = function(ctx)
local bounds = nk.nk_window_get_content_region(ctx)
nk.nk_layout_row_dynamic(ctx, bounds.h, 1)
local files = config.assets.lua
wdgts.widget_list_selectable(ctx, "source_files", nk.NK_WINDOW_BORDER, files, bounds.w -40 )
end,
},
{
name = "Images",
func = function(ctx)
local bounds = nk.nk_window_get_content_region(ctx)
nk.nk_layout_row_dynamic(ctx, bounds.h, 1)
local files = config.assets.images
wdgts.widget_list_selectable(ctx, "source_files", nk.NK_WINDOW_BORDER, files, bounds.w -40 )
end,
},
{
name = "Data",
func = function(ctx)
local bounds = nk.nk_window_get_content_region(ctx)
nk.nk_layout_row_dynamic(ctx, bounds.h, 1)
local files = config.assets.data
wdgts.widget_list_selectable(ctx, "source_files", nk.NK_WINDOW_BORDER, files, bounds.w -40 )
end,
}
}
-- --------------------------------------------------------------------------------------
local folder_select = {
popup_active = 0,
popup_dim = ffi.new("struct nk_rect",{20, 100, 220, 90}),
folder_path = ".",
hit = {0, "", 0},
ui_func = function(ctx, dim, udata)
nk.nk_layout_row_dynamic(ctx, dim.h-20, 1)
local flags = bit.bor(nk.NK_WINDOW_BORDER, nk.NK_WINDOW_TITLE)
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
if (nk.nk_group_begin(ctx, "Select Folder", flags) == true) then
nk.nk_layout_row_dynamic(ctx, dim.h-90, 1)
local files = dirtools.get_folderslist(udata.folder_path)
if(#files == 0 or files[1].name ~= "..") then table.insert(files, 1, { name = ".." }) end
local bhit = wdgts.widget_list_buttons(ctx, "folder_files", nil, files, dim.w -40 )
if(bhit) then
udata.hit = bhit
if(bhit[2] == "..") then
udata.folder_path = udata.folder_path:match("(.-)[^\\]-[^%.]+$")
if(udata.folder_path == nil or udata.folder_path == "") then udata.folder_path = "." end
else
udata.folder_path = udata.folder_path.."\\"..udata.hit[2]
end
print(udata.folder_path)
end
nk.nk_layout_row_dynamic(ctx, 25, 2)
if (nk.nk_button_label(ctx, "Cancel") == true) then
udata.popup_active = 0
end
if (nk.nk_button_label(ctx, "OK") == true) then
udata.popup_active = 0
end
nk.nk_group_end(ctx)
end
if(udata.popup_active == 0) then nk.nk_popup_close(ctx) end
return udata.popup_active
end,
}
-- --------------------------------------------------------------------------------------
-- Extract config and build ffi objects for them
-- Each config property shall have a shadow ffi property labeled with _ffi
for sectionname, section in pairs(config) do
for key, prop in pairs(section) do
-- If ptype is nill or string its a string
if(prop.ptype == "string") then
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
elseif(prop.ptype == "combo") then
prop.ffi = ffi.new("int[1]", prop.value)
elseif(prop.ptype == "int") then
prop.ffi = ffi.new("int[1]", prop.value)
elseif(prop.ptype == "float") then
prop.ffi = ffi.new("float[1]", prop.value)
elseif(prop.ptype == "path") then
print(prop.value)
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
elseif(prop.ptype == "file") then
print(prop.value)
prop.ffi = ffi.new("char[?]", prop.slen )
ffi.fill(prop.ffi, prop.slen, 0)
ffi.copy(prop.ffi, ffi.string(prop.value))
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
end
end
end
local group_width = ffi.new("int[1]", {320})
local group_height = ffi.new("int[1]", {200})
-- --------------------------------------------------------------------------------------
local range_float_value = ffi.new("float[1]")
local function display_section(ctx, sectionname)
local section = config[sectionname]
-- Collect the number of properties in the section
local count = 0
local sorted = {}
for k,v in pairs(section) do
count = count + 1
v.key = k
sorted[v.index] = v
end
nk.nk_layout_row_dynamic(ctx, 28 * count + 60, 1)
local bounds = nk.nk_window_get_content_region(ctx)
local prop_col = bounds.w * 0.23
local value_col = bounds.w * 0.73
local flags = bit.bor(nk.NK_WINDOW_BORDER, nk.NK_WINDOW_TITLE)
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
if (nk.nk_group_begin(ctx, sectionname, flags) == true) then
for k,v in ipairs(sorted) do
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 28, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, v.key..":", nk.NK_TEXT_LEFT)
if(v.ptype == "string" or v.ptype == nil) then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
elseif(v.ptype == "path") then
nk.nk_layout_row_push(ctx, value_col - 34)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
nk.nk_style_set_font(ctx, myfonts[1].handle)
nk.nk_layout_row_push(ctx, 30)
if(nk.nk_button_label(ctx, "") == true) then
folder_select.popup_active = 1
end
nk.nk_style_set_font(ctx, myfonts[3].handle)
elseif(v.ptype == "file") then
nk.nk_layout_row_push(ctx, value_col - 34)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
nk.nk_style_set_font(ctx, myfonts[1].handle)
nk.nk_layout_row_push(ctx, 30)
nk.nk_button_label(ctx, "")
nk.nk_style_set_font(ctx, myfonts[3].handle)
elseif(v.ptype == "combo") then
nk.nk_layout_row_push(ctx, value_col)
v.value = wdgts.widget_combo_box(ctx, v.plist, v.value, 200)
elseif(v.ptype == "int") then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_property_int(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
elseif(v.ptype == "float") then
nk.nk_layout_row_push(ctx, value_col)
nk.nk_property_float(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
end
nk.nk_layout_row_end(ctx)
end
nk.nk_group_end(ctx)
end
end
-- --------------------------------------------------------------------------------------
local project_curr_tab = 1
local project_tabs = {
{
name = "Project",
func = function(ctx)
display_section(ctx, "project")
display_section(ctx, "sokol")
end,
},
{
name = "Build",
func = function(ctx)
display_section(ctx, "platform")
end,
},
{
name = "Logs"
}
}
-- --------------------------------------------------------------------------------------
local function project_panel(ctx)
nk.nk_style_set_font(ctx, myfonts[3].handle)
project_curr_tab = wdgts.widget_notebook(ctx, "assets", project_tabs, project_curr_tab, 500, 120)
-- display_section(ctx, "graphics")
-- display_section(ctx, "audio")
-- Awesome little radial popup.
local res = wdgts.make_pie_popup(ctx, icons, 100, 6)
end
-- --------------------------------------------------------------------------------------
local function assets_panel(ctx)
nk.nk_style_set_font(ctx, myfonts[3].handle)
curr_tab = wdgts.widget_notebook(ctx, "assets", tabs, curr_tab, 500, 120)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_end(ctx)
end
-- --------------------------------------------------------------------------------------
local function main_ui(ctx)
if(myfonts == nil) then
myfonts = fonts.setup_font(ctx, font_list)
end
wdgts.widget_panel_fixed(ctx, "WinMain", 0, 0, sapp.sapp_width(), sapp.sapp_height(), 0, function(data)
folder_select.popup_active = wdgts.widget_popup_panel(ctx, "popup", folder_select.popup_dim, folder_select.ui_func, folder_select, folder_select.popup_active)
nk.nk_style_set_font(ctx, myfonts[4].handle)
local flags = nk.NK_WINDOW_BORDER
local height = sapp.sapp_height()
nk.nk_layout_row_dynamic(ctx, height-20, 2)
-- wdgts.widget_panel_fixed(ctx, "Project", 10, 10, width, height, flags, function(data)
if (nk.nk_group_begin(ctx, "Project", flags) == true) then
local padding = ctx[0].style.window.padding
ctx[0].style.window.padding = nk.nk_vec2(10,10)
project_panel(data.ctx)
-- end, {ctx=ctx})
nk.nk_group_end(ctx)
end
nk.nk_style_set_font(ctx, myfonts[4].handle)
-- wdgts.widget_panel_fixed(ctx, "Assets", 10+width+10, 10, width, height, flags, function(data)
if (nk.nk_group_begin(ctx, "Assets", flags) == true) then
assets_panel(data.ctx)
-- end, {ctx=ctx})
nk.nk_group_end(ctx)
end
end, {ctx=ctx})
return not nk.nk_window_is_closed(ctx, "Overview")
end
-- --------------------------------------------------------------------------------------
local pix = {}
local function init()
local base_path = "./"
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")
-- pix["edit"] = icon_load(base_path.."icon/edit.png")
winrect[0].x = 0
winrect[0].y = 0
winrect[0].w = sapp.sapp_width()
winrect[0].h = sapp.sapp_height()
icons[0] = wdgts.icon_load("./icon/home.png")
icons[1] = wdgts.icon_load("./icon/phone.png")
icons[2] = wdgts.icon_load("./icon/plane.png")
icons[3] = wdgts.icon_load("./icon/wifi.png")
icons[4] = wdgts.icon_load("./icon/settings.png")
icons[5] = wdgts.icon_load("./icon/volume.png")
folder_select.popup_dim.w = sapp.sapp_width()* 0.4
folder_select.popup_dim.h = sapp.sapp_height()* 0.7
folder_select.popup_dim.x = sapp.sapp_width()/2-8 - folder_select.popup_dim.w/2
folder_select.popup_dim.y = sapp.sapp_height()/2-40 - folder_select.popup_dim.h/2
end
-- --------------------------------------------------------------------------------------
return {
config = config,
init = init,
main_ui = main_ui,
}
-- --------------------------------------------------------------------------------------

View File

@ -0,0 +1,28 @@
-- --------------------------------------------------------------------------------------
local visited = {}
local function tdump(o, level)
local level = level or 1
if(level == 0) then visited = {} end
if type(o) == 'table' then
local s = ' {\n'
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..tostring(k)..'"' end
if(visited[v] == nil) then
visited[v] = true
s = s .. string.rep(" ", level)..'['..k..'] = ' .. tdump(v, level+1)
end
end
return s .. string.rep(" ", level-1)..'}\n'
else
return tostring(o).."\n"
end
end
-- --------------------------------------------------------------------------------------
return {
tdump = tdump,
}
-- --------------------------------------------------------------------------------------

View File

@ -175,29 +175,29 @@ end
widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, tab_fixed_width) widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, tab_fixed_width)
-- /* Header */ -- /* Header */
local spacing = ctx[0].style.window.spacing local spacing = ctx.style.window.spacing
ctx[0].style.window.spacing = nk.nk_vec2(0,0) ctx.style.window.spacing = nk.nk_vec2(0,0)
local rounding = ctx[0].style.button.rounding local rounding = ctx.style.button.rounding
ctx[0].style.button.rounding = 0 ctx.style.button.rounding = 0
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 24, 3) nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 24, 3)
for i, v in ipairs(tabs) do for i, v in ipairs(tabs) do
-- /* make sure button perfectly fits text */ -- /* make sure button perfectly fits text */
local f = ctx[0].style.font local f = ctx.style.font
local text_width = tab_fixed_width or f.width(f.userdata, f.height, v.name, string.len(tabs[i])) local text_width = tab_fixed_width or f.width(f.userdata, f.height, v.name, string.len(tabs[i]))
local widget_width = text_width + 4 * ctx[0].style.button.padding.x local widget_width = text_width + 4 * ctx.style.button.padding.x
nk.nk_layout_row_push(ctx, widget_width) nk.nk_layout_row_push(ctx, widget_width)
if (current_tab == i) then if (current_tab == i) then
-- /* active tab gets highlighted */ -- /* active tab gets highlighted */
local button_color = ctx[0].style.button.normal local button_color = ctx.style.button.normal
ctx[0].style.button.normal = ctx[0].style.button.active ctx.style.button.normal = ctx.style.button.active
if (nk.nk_button_label(ctx, v.name) == true ) then current_tab = i end if (nk.nk_button_label(ctx, v.name) == true ) then current_tab = i end
ctx[0].style.button.normal = button_color ctx.style.button.normal = button_color
else else
if(nk.nk_button_label(ctx, v.name) == true) then current_tab = i end if(nk.nk_button_label(ctx, v.name) == true) then current_tab = i end
end end
end end
ctx[0].style.button.rounding = rounding ctx.style.button.rounding = rounding
ctx[0].style.window.spacing = spacing ctx.style.window.spacing = spacing
-- /* Body */ -- /* Body */
nk.nk_layout_row_dynamic(ctx, height, 1) nk.nk_layout_row_dynamic(ctx, height, 1)
@ -205,9 +205,9 @@ widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, tab
for i,v in ipairs(tabs) do for i,v in ipairs(tabs) do
if(current_tab == i) then if(current_tab == i) then
ctx[0].style.window.group_padding = nk.nk_vec2(14,10) ctx.style.window.group_padding = nk.nk_vec2(14,10)
if(v.func) then v.func(ctx) end if(v.func) then v.func(ctx) end
ctx[0].style.window.group_padding = spacing ctx.style.window.group_padding = spacing
end end
end end
nk.nk_group_end(ctx) nk.nk_group_end(ctx)
@ -250,6 +250,30 @@ widgets.widget_list_selectable = function(ctx, title, flags, items, width)
end end
end end
--------------------------------------------------------------------------------
widgets.widget_list_buttons = function(ctx, title, flags, items, width)
local pressed = nil
local button_align = ctx.style.button.text_alignment
local rounding = ctx.style.button.rounding
ctx.style.button.rounding = 0
ctx.style.button.text_alignment = nk.NK_TEXT_LEFT
flags = flags or nk.NK_WINDOW_BORDER -- default setup
if (nk.nk_group_begin(ctx, title, flags) == true) then
for i, item in ipairs(items) do
nk.nk_layout_row_static(ctx, 22, width, 1)
if(nk.nk_button_label(ctx, item.name) == true) then
pressed = {i, item.name}
end
end
nk.nk_group_end(ctx)
end
ctx.style.button.rounding = rounding
ctx.style.button.text_alignment = button_align
return pressed
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
widgets.widget_popup_panel = function(ctx, title, dim, content_func, userdata, active) widgets.widget_popup_panel = function(ctx, title, dim, content_func, userdata, active)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -50,6 +50,74 @@ dirtools.get_app_path = function( expected_root_folder )
return base_dir return base_dir
end end
-- --------------------------------------------------------------------------------------
local dir_cmd = "dir /b"
if(ffi.os ~= "Windows") then dir_cmd = "ls -1" end
local list_cache = {}
dirtools.get_dirlist = function(path, cache_update)
if(list_cache[path] and cache_update == nil) then return list_cache[path] end
local files = {}
local res = ""
-- Fill with temp file list of dir /b
local fh = io.popen(dir_cmd.." "..path, "r")
if(fh) then
res = fh:read("*a")
fh:close()
else
print("[Error] dirtools.get_dirlist bad path: "..tostring(path))
return files
end
for f in string.gmatch(res, "(.-)\n") do
local newfile = { name = ffi.string(f)}
newfile.select = ffi.new("int[1]")
newfile.select[0] = 0
table.insert(files, newfile)
end
list_cache[path] = files
return files
end
-- --------------------------------------------------------------------------------------
local folders_cmd = "dir /Ad /b"
if(ffi.os ~= "Windows") then folders_cmd = "ls -1 -d */" end
local list_folders_cache = {}
dirtools.get_folderslist = function(path, cache_update)
if(list_folders_cache[path] and cache_update == nil) then return list_folders_cache[path] end
local files = {}
local res = ""
-- Fill with temp file list of dir /b
local fh = io.popen(folders_cmd.." "..path, "r")
if(fh) then
res = fh:read("*a")
fh:close()
else
print("[Error] dirtools.get_folderslist bad path: "..tostring(path))
return files
end
for f in string.gmatch(res, "(.-)\n") do
local newfile = { name = ffi.string(f)}
newfile.select = ffi.new("int[1]")
newfile.select[0] = 0
table.insert(files, newfile)
end
list_folders_cache[path] = files
return files
end
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- By default the paths are added -- By default the paths are added