Major works on the build ui. Fairly happy now.

This commit is contained in:
David Lannan 2024-11-07 19:44:49 +10:30
parent dbfd6eb241
commit fb6659908c
3 changed files with 124 additions and 117 deletions

View File

@ -4,52 +4,58 @@ local ffi = require("ffi")
-- ------------------------------------------------------------------------------------------------------
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 settings = {
rbuilder = {
appname = "rbuild",
version = "00.01.snow",
appname = { index = 1, value = "rbuild", slen = 7 },
version = { index = 2, value = "00.01.snow", slen = 32 },
},
platform = {
target = "Win64",
srlua_path = "../srlua/", -- initially rbuild will run for the tools/build/rbuilder folder
arch = ffi.arch,
os = ffi.os,
target = { index = 1, value = 1, ptype = "combo", plist = platforms },
srlua_path = { index = 2, value = "../srlua/", 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 = "default",
project_path = "./", -- Always starts empty. Will support a project file.
project_file = "default.slp" -- Sokol luajit project file
project_name = { index = 1, value = "default", slen = 64 },
project_path = { index = 2, value = "./", slen = 256 }, -- Always starts empty. Will support a project file.
project_file = { index = 3, value = "default.slp", slen = 64 }, -- Sokol luajit project file
project_start = { index = 4, value = "example1.lua", slen = 128 },
},
graphics = {
display_res = "1024x768",
display_width = 1024,
display_height = 768,
display_fps = 60,
antialias = "fxaa",
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 = 1.0,
effects_volume = 1.0,
music_volume = 1.0,
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 = "../../../../",
sokol_bin = "bin/",
sokol_ffi = "ffi/",
sokol_lua = "lua/",
sokol_examples = "examples/",
sokol_path = { index = 1, value = "../../../../", slen = 256 },
sokol_bin = { index = 2, value = "bin/", slen = 256 },
sokol_ffi = { index = 3, value = "ffi/", slen = 256 },
sokol_lua = { index = 4, value = "lua/", slen = 256 },
sokol_examples = { index = 5, value = "examples/", slen = 256 },
},
remote = {
-- These are futures --
remote_build = "https://mybuildserver.com/sokol_build",
remote_data = "https://myremotedata.com/data",
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
@ -58,7 +64,8 @@ local settings = {
},
}
settings.rbuilder.title = settings.rbuilder.appname.." ("..settings.rbuilder.version..")"
local title = settings.rbuilder.appname.value.." ("..settings.rbuilder.version.value..")"
settings.rbuilder.title = { value = title, slen = 32 }
-- ------------------------------------------------------------------------------------------------------

View File

@ -141,69 +141,104 @@ 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 sectionname, section in pairs(config) do
for key, value in pairs(section) do
if(type(value) == "string") then
section[key.."_ffi"] = ffi.new("char[256]")
--ffi.copy(section[key.."_ffi"], ffi.string(value))
section[key.."_len_ffi"] = ffi.new("int[1]", 0)
end
if(type(value) == "number") then
section[key.."_ffi"] = ffi.new("float[1]", value)
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)
end
end
end
-- 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]")
local platform_selected = 1
local platforms = { "Win64", "MacOS", "Linux", "IOS64" }
local res_selected = 1
local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768" }
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 bounds = nk.nk_window_get_content_region(ctx)
local prop_col = bounds.w * 0.25
local value_col = bounds.w * 0.75
local section = config[sectionname]
-- Collect the number of properties in the section
local count = 0
local sorted = {}
for k,v in pairs(section) do
if(not string.match(k, ".-_ffi$")) then
print(k,v)
if(type(v) == "string") then
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, prop_col)
nk.nk_label(ctx, k..":", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, value_col)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, section[k.."_ffi"], section[k.."_len_ffi"], 256, nk.nk_filter_default)
nk.nk_layout_row_end(ctx)
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)
nk.nk_layout_row_push(ctx, value_col)
if(v.ptype == "string" or v.ptype == nil) then
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, v.ffi, v.len_ffi, v.slen, nk.nk_filter_default)
elseif(v.ptype == "combo") then
v.value = wdgts.widget_combo_box(ctx, v.plist, v.value, 200)
elseif(v.ptype == "int") then
nk.nk_property_int(ctx, "", v.vmin, v.ffi, v.vmax, v.vstep, v.vinc)
elseif(v.ptype == "float") then
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)
display_section(ctx, "project")
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)
@ -211,7 +246,7 @@ end
-- --------------------------------------------------------------------------------------
local curr_tab = 1
local tabs = { "Lua Source", "Images", "Data" }
local tabs = { { name = "Lua Source" }, { name = "Images" }, { name = "Data" } }
local function assets_panel(ctx)
@ -252,7 +287,7 @@ local function main_ui(ctx)
nk.nk_style_set_font(ctx, myfonts[4].handle)
local flags = bit.bor(nk.NK_WINDOW_TITLE, nk.NK_WINDOW_BORDER)
local flags = 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})

View File

@ -174,78 +174,43 @@ end
widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, 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)
local spacing = ctx[0].style.window.spacing
ctx[0].style.window.spacing = nk.nk_vec2(0,0)
local rounding = ctx[0].style.button.rounding
ctx[0].style.button.rounding = 0
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 20, 3)
for i = 1, table.getn(tabs) do
for i, v in ipairs(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 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
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
if (nk.nk_button_label(ctx, v.name) == 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
if(nk.nk_button_label(ctx, v.name) == true) then current_tab = i end
end
end
nk.nk_style_pop_float(ctx)
ctx[0].style.button.rounding = rounding
ctx[0].style.window.spacing = spacing
-- /* Body */
nk.nk_layout_row_dynamic(ctx, height, 1)
if (nk.nk_group_begin(ctx, tab_name, 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, height-20, 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
for i,v in ipairs(tabs) do
if(current_tab == i) then
ctx[0].style.window.group_padding = nk.nk_vec2(14,10)
if(v.func) then v.func(ctx) end
ctx[0].style.window.group_padding = spacing
end
nk.nk_chart_end(ctx)
elseif(current_tab == chart_type.CHART_HISTO) then
nk.nk_layout_row_dynamic(ctx, height-20, 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, height-20, 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