Editor taking shape
This commit is contained in:
parent
84e0301ce5
commit
4d3eedab64
@ -1,6 +1,6 @@
|
|||||||
-- Add your panel actions here.
|
-- Add your panel actions here.
|
||||||
local sapp = require("sokol_app")
|
local sapp = require("sokol_app")
|
||||||
|
local nk = sg
|
||||||
|
|
||||||
local panel_actions = {}
|
local panel_actions = {}
|
||||||
|
|
||||||
@ -8,6 +8,6 @@ panel_actions["quit_app"] = function(event, element)
|
|||||||
|
|
||||||
sapp.sapp_quit()
|
sapp.sapp_quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return panel_actions
|
return panel_actions
|
||||||
@ -5,25 +5,57 @@ local panels = {}
|
|||||||
|
|
||||||
panels.windows = {}
|
panels.windows = {}
|
||||||
|
|
||||||
panels.windows.popup = {
|
-- Note: In Niklear panels/windows are top level and cannot be nested.
|
||||||
|
|
||||||
|
panels.windows.panel_simple = {
|
||||||
type = "panel",
|
type = "panel",
|
||||||
title = "Main",
|
title = "simple",
|
||||||
size = {600, "auto"},
|
size = {600, "auto"},
|
||||||
pos = {"left", "top"}, -- Can be pixels or strings
|
pos = {0, 0}, -- Can be pixels or strings
|
||||||
color = { background = 0x000000ff, text = 0xffffffff, border = 0x888888ff },
|
color = { background = 0x000000ff, text = 0xffffffff, border = 0x888888ff },
|
||||||
window_flags = bit.bor(nk.NK_WINDOW_TITLE, nk.NK_WINDOW_MOVABLE),
|
window_flags = bit.bor(0, nk.NK_WINDOW_NO_SCROLLBAR),
|
||||||
|
|
||||||
layout = {
|
layout = {
|
||||||
{
|
{
|
||||||
type = "row", height = 24, layout = {
|
type = "row", height = 24, layout = {
|
||||||
{ type = "label", text = "Some text", width = 0.1 },
|
{ type = "button", text = "Project", action = "project_config", width = "auto" },
|
||||||
{ type = "button", text = "Build Project", action = "build_project", width = "auto" },
|
{ type = "button", text = "Paths", action = "paths_config", width = "auto" },
|
||||||
{ type = "button", text = "Export", action = "export_assets", width = 200 },
|
{ type = "button", text = "World", action = "world_view", width = "auto" },
|
||||||
{ type = "button", text = "Quit", action = "quit_app", width = "auto" },
|
{ type = "button", text = "Assets", action = "assets_view", width = "auto" },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panels.windows.panel_icon_bar = {
|
||||||
|
type = "panel",
|
||||||
|
title = "icon_bar",
|
||||||
|
size = {"auto", 30},
|
||||||
|
pos = {600, "top"}, -- Can be pixels or strings
|
||||||
|
color = { background = 0x000000ff, text = 0xffffffff, border = 0x888888ff },
|
||||||
|
window_flags = bit.bor(0, nk.NK_WINDOW_NO_SCROLLBAR),
|
||||||
|
|
||||||
|
layout = {
|
||||||
|
{
|
||||||
|
type = "row", height = 24, layout = {
|
||||||
|
{ type = "button", text = "Scene", action = "scene_view", width = 80 },
|
||||||
|
{ type = "button", text = "Models", action = "model_view", width = 80 },
|
||||||
|
{ type = "button", text = "Scripts", action = "scripts_view",width = 80 },
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
panels.windows.panel_master = {
|
||||||
|
type = "group",
|
||||||
|
size = {"auto", "auto"},
|
||||||
|
pos = {"left", "top"}, -- Can be pixels or strings
|
||||||
|
|
||||||
|
layout = {
|
||||||
|
panels.windows.panel_simple,
|
||||||
|
panels.windows.panel_icon_bar,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return panels
|
return panels
|
||||||
@ -52,7 +52,7 @@ function SmainGui:Init(wwidth, wheight)
|
|||||||
-- SmenuMain:Init(wwidth, wheight)
|
-- SmenuMain:Init(wwidth, wheight)
|
||||||
-- SenvHandler:Init(wwidth, wheight)
|
-- SenvHandler:Init(wwidth, wheight)
|
||||||
print("Display: "..wwidth.." x "..wheight)
|
print("Display: "..wwidth.." x "..wheight)
|
||||||
panels.windows.popup.parent = { size = { wwidth, wheight } }
|
panels.windows.panel_master.parent = { size = { wwidth, wheight } }
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
|
||||||
@ -102,19 +102,21 @@ local function get_parent_size( ele )
|
|||||||
local size = { 1920, 1440 }
|
local size = { 1920, 1440 }
|
||||||
-- Calc size first since this may be used in positioning (like center etc)
|
-- Calc size first since this may be used in positioning (like center etc)
|
||||||
if(ele.size) then
|
if(ele.size) then
|
||||||
|
local pwidth = ele.parent.size[1] or 1920
|
||||||
if(ele.size[1]) then
|
if(ele.size[1]) then
|
||||||
if(type(ele.size[1]) == "string") then
|
if(type(ele.size[1]) == "string") then
|
||||||
if(ele.size[1] == "auto") then
|
if(ele.size[1] == "auto") then
|
||||||
size[1] = ele.parent.size[1] or 1920
|
size[1] = pwidth
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
size[1] = tonumber(ele.size[1]) or 100
|
size[1] = tonumber(ele.size[1]) or 100
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local pheight = ele.parent.size[2] or 1440
|
||||||
if(ele.size[2]) then
|
if(ele.size[2]) then
|
||||||
if(type(ele.size[2]) == "string") then
|
if(type(ele.size[2]) == "string") then
|
||||||
if(ele.size[2] == "auto") then
|
if(ele.size[2] == "auto") then
|
||||||
size[2] = ele.parent.size[2] or 1440
|
size[2] = pheight
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
size[2] = tonumber(ele.size[2]) or 100
|
size[2] = tonumber(ele.size[2]) or 100
|
||||||
@ -156,6 +158,7 @@ end
|
|||||||
local function get_geometry( ele, winrect )
|
local function get_geometry( ele, winrect )
|
||||||
|
|
||||||
local size = get_parent_size( ele )
|
local size = get_parent_size( ele )
|
||||||
|
ele.size = size
|
||||||
winrect[0].w, winrect[0].h = size[1], size[2]
|
winrect[0].w, winrect[0].h = size[1], size[2]
|
||||||
if(ele.pos) then
|
if(ele.pos) then
|
||||||
if(ele.pos[1]) then
|
if(ele.pos[1]) then
|
||||||
@ -196,7 +199,19 @@ end
|
|||||||
|
|
||||||
local function render_element( ctx, element )
|
local function render_element( ctx, element )
|
||||||
|
|
||||||
if(element.type == "panel") then
|
if(element.type == "group") then
|
||||||
|
|
||||||
|
element.winrect = element.winrect or ffi.new("struct nk_rect[1]", {{0, 0, 400, 600}})
|
||||||
|
get_geometry(element, element.winrect)
|
||||||
|
if(element.layout) then
|
||||||
|
for i,v in ipairs(element.layout) do
|
||||||
|
v.parent = element
|
||||||
|
render_element(ctx, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif(element.type == "panel") then
|
||||||
|
|
||||||
element.winrect = element.winrect or ffi.new("struct nk_rect[1]", {{0, 0, 400, 600}})
|
element.winrect = element.winrect or ffi.new("struct nk_rect[1]", {{0, 0, 400, 600}})
|
||||||
get_geometry(element, element.winrect)
|
get_geometry(element, element.winrect)
|
||||||
if (nk.nk_begin(ctx, element.title or "", element.winrect[0], element.window_flags or 0) == true) then
|
if (nk.nk_begin(ctx, element.title or "", element.winrect[0], element.window_flags or 0) == true) then
|
||||||
@ -257,7 +272,7 @@ function SmainGui:Update(mxi, myi, buttons)
|
|||||||
|
|
||||||
-- SmenuMain:Update(mxi, myi, buttons)
|
-- SmenuMain:Update(mxi, myi, buttons)
|
||||||
-- SenvHandler:Update(mxi, myi, buttons)
|
-- SenvHandler:Update(mxi, myi, buttons)
|
||||||
render_element(mainState.ctx, panels.windows.popup)
|
render_element(mainState.ctx, panels.windows.panel_master)
|
||||||
--nkgui:render()
|
--nkgui:render()
|
||||||
|
|
||||||
self.prevmxi = mxi
|
self.prevmxi = mxi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user