Added radial popup. Probably dont need it! :)

This commit is contained in:
David Lannan 2024-11-05 12:59:41 +10:30
parent 7d4c30f114
commit b77bc74e2b
32 changed files with 286 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -22,12 +22,15 @@ local ffi = require("ffi")
-- --------------------------------------------------------------------------------------
local config = require("config.settings")
local wdgts = require("utils.widgets")
-- --------------------------------------------------------------------------------------
local fonts = nil
local atlas = ffi.new("struct nk_font_atlas[1]")
local icons = ffi.new("struct nk_image [?]", 10)
-- --------------------------------------------------------------------------------------
-- --------------------------------------------------------------------------------------
@ -186,6 +189,13 @@ local function init(void)
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")
end
-- --------------------------------------------------------------------------------------
@ -238,6 +248,44 @@ local function project_panel(ctx)
nk.nk_layout_row_push(ctx, 130)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, group_name, group_name_len, 64, nk.nk_filter_default)
nk.nk_layout_row_end(ctx)
-- Awesome little radial popup.
local res = wdgts.make_pie_popup(ctx, icons, 140, 6)
end
-- --------------------------------------------------------------------------------------
local function properties_panel(ctx)
nk.nk_style_set_font(ctx, fonts[3].handle)
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)
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
nk.nk_layout_row_push(ctx, 50)
nk.nk_label(ctx, "name:", nk.NK_TEXT_LEFT)
nk.nk_layout_row_push(ctx, 130)
nk.nk_edit_string(ctx, nk.NK_EDIT_SIMPLE, group_name, group_name_len, 64, nk.nk_filter_default)
nk.nk_layout_row_end(ctx)
end
-- --------------------------------------------------------------------------------------
local function panel_project_function(data, left, top, width, height)
project_panel(data.ctx)
end
-- --------------------------------------------------------------------------------------
local function panel_properties_function(data, left, top, width, height)
properties_panel(data.ctx)
end
-- --------------------------------------------------------------------------------------
@ -250,32 +298,33 @@ local function main_ui(ctx)
nk.nk_style_set_font(ctx, fonts[4].handle)
-- /* window flags */
ctx[0].style.window.header.align = header_align
-- window_flags = bit.bor(window_flags, nk.NK_WINDOW_TITLE)
-- if (border[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_BORDER) end
-- if (resize[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_SCALABLE) end
-- if (movable[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_MOVABLE) end
-- if (no_scrollbar[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_NO_SCROLLBAR) end
-- if (scale_left[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_SCALE_LEFT) end
-- if (minimizable[0] == true) then window_flags = bit.bor(window_flags, nk.NK_WINDOW_MINIMIZABLE) end
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})
if (nk.nk_begin(ctx, "rbuild", winrect[0], window_flags) == true) then
nk.nk_style_set_font(ctx, fonts[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
-- if (show_menu[0] == true) then
-- /* menubar */
local menu_states = { MENU_DEFAULT = 0, MENU_WINDOWS = 1}
nk.nk_menubar_begin(ctx)
-- local menu_states = { MENU_DEFAULT = 0, MENU_WINDOWS = 1}
-- nk.nk_menubar_begin(ctx)
project_panel(ctx)
-- -- /* menu #1 */
-- nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 40, 5)
-- nk.nk_layout_row_push(ctx, 40)
-- /* 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"])
-- nk.nk_image(ctx, pix["baboon"])
-- /*------------------------------------------------
-- * CONTEXTUAL
@ -297,10 +346,10 @@ local function main_ui(ctx)
-- nk.nk_contextual_end(ctx)
-- end
nk.nk_layout_row_end(ctx)
end
end
nk.nk_end(ctx)
-- nk.nk_layout_row_end(ctx)
-- end
-- nk.nk_end(ctx)
-- end
return not nk.nk_window_is_closed(ctx, "Overview")
end

View File

@ -0,0 +1,214 @@
local sapp = require("sokol_app")
local nk = sg
local hmm = require("hmm")
local stb = require("stb")
local ffi = require("ffi")
--------------------------------------------------------------------------------
local widgets = {}
--------------------------------------------------------------------------------
widgets.widget_panel_fixed = function (ctx, title, left, top, width, height, flags, panel_function, data)
local x = left
local y = top
flags = flags or 0
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
local winrect = nk.nk_rect(tonumber(x), tonumber(y), tonumber(width), tonumber(height))
local shown = false
if( nk.nk_begin(ctx, title, winrect, flags) == true) then
if(panel_function) then panel_function(data, left, top, width, height) end
shown = true
nk.nk_end(ctx)
end
return { show=shown, x=winrect.x, y=winrect.y, w=winrect.w, h=winrect.h }
end
--------------------------------------------------------------------------------
widgets.widget_pie_menu = function(ctx, left, top, radius, icons, item_count)
local ret = -1
local total_space = ffi.new("struct nk_rect")
local bounds = ffi.new("struct nk_rect")
local active_item = 0
-- /* pie menu popup */
local border = ctx.style.window.popup_border_color
local bgcolor = ctx.style.window.fixed_background.data.color
local bgtype = ctx.style.window.fixed_background.type
ctx.style.window.fixed_background.data.color.a = 0
ctx.style.window.popup_border_color = nk.nk_rgba(0,0,0,0)
total_space = nk.nk_window_get_content_region(ctx)
local spacing = nk.nk_vec2(ctx.style.window.spacing.x, ctx.style.window.spacing.y)
local padding = nk.nk_vec2(ctx.style.window.padding.x, ctx.style.window.padding.y)
ctx.style.window.spacing = nk.nk_vec2(0,0)
ctx.style.window.padding = nk.nk_vec2(0,0)
local flags = nk.NK_WINDOW_NO_SCROLLBAR
if (nk.nk_popup_begin(ctx, nk.NK_POPUP_STATIC, "piemenu", flags,
nk.nk_rect(left - total_space.x - radius, top - radius - total_space.y,
2*radius,2*radius)) == true) then
local i = 0
local out = nk.nk_window_get_canvas(ctx)
local nk_in = ctx.input
total_space = nk.nk_window_get_content_region(ctx)
ctx.style.window.spacing = nk.nk_vec2(4,4)
ctx.style.window.padding = nk.nk_vec2(8,8)
nk.nk_layout_row_dynamic(ctx, total_space.h, 1)
nk.nk_widget(bounds, ctx)
-- /* outer circle */
nk.nk_fill_circle(out, bounds, nk.nk_rgb(50,50,50))
do
-- /* circle buttons */
local step = (2 * 3.141592654) / (math.max(1,item_count))
local a_min = 0; local a_max = step
local center = nk.nk_vec2(bounds.x + bounds.w / 2.0, bounds.y + bounds.h / 2.0)
local drag = nk.nk_vec2(nk_in.mouse.pos.x - center.x, nk_in.mouse.pos.y - center.y)
local angle = math.atan2(drag.y, drag.x)
if (angle < -0.0) then angle = angle + 2.0 * 3.141592654 end
active_item = math.floor(angle/step)
for i = 0, item_count-1 do
local content = ffi.new("struct nk_rect")
local rgb = nk.nk_rgb(60,60,60)
if(active_item == i) then rgb = nk.nk_rgb(45,100,255) end
nk.nk_fill_arc(out, center.x, center.y, (bounds.w/2.0), a_min, a_max, rgb)
-- /* separator line */
local rx = bounds.w/2.0
local ry = 0
local dx = rx * math.cos(a_min) - ry * math.sin(a_min)
local dy = rx * math.sin(a_min) + ry * math.cos(a_min)
nk.nk_stroke_line(out, center.x, center.y, center.x + dx, center.y + dy, 1.0, nk.nk_rgb(50,50,50))
-- /* button content */
local a = a_min + (a_max - a_min)/2.0
local rx = bounds.w/2.5; ry = 0
content.w = 30; content.h = 30;
content.x = center.x + ((rx * math.cos(a) - ry * math.sin(a)) - content.w/2.0)
content.y = center.y + (rx * math.sin(a) + ry * math.cos(a) - content.h/2.0)
nk.nk_draw_image(out, content, icons[i], nk.nk_rgb(255,255,255))
a_min = a_max; a_max = a_max + step
end
end
do
-- /* inner circle */
local inner = ffi.new("struct nk_rect")
inner.x = bounds.x + bounds.w/2 - bounds.w/4
inner.y = bounds.y + bounds.h/2 - bounds.h/4
inner.w = bounds.w/2; inner.h = bounds.h/2
nk.nk_fill_circle(out, inner, nk.nk_rgb(45,45,45))
-- /* active icon content */
bounds.w = inner.w / 2.0
bounds.h = inner.h / 2.0
bounds.x = inner.x + inner.w/2 - bounds.w/2
bounds.y = inner.y + inner.h/2 - bounds.h/2
nk.nk_draw_image(out, bounds, icons[active_item], nk.nk_rgb(255,255,255))
end
nk.nk_layout_space_end(ctx);
if (nk.nk_input_is_mouse_released(ctx.input, nk.NK_BUTTON_RIGHT) == true) then
nk.nk_popup_close(ctx)
ret = active_item
end
else
ret = -2
end
nk.nk_popup_end(ctx)
ctx.style.window.spacing = spacing
ctx.style.window.padding = padding
ctx.style.window.fixed_background.type = bgtype
ctx.style.window.fixed_background.data.color.a = 255
ctx.style.window.popup_border_color = border
return ret
end
--------------------------------------------------------------------------------
-- returns struct nk_image
widgets.icon_load = function(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 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
print(" >>> activate_pie")
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
print(" >>> deactivate_pie")
print("piemenu selected: "..ret)
piemenu_active = 0
end
end
return ret
end
--------------------------------------------------------------------------------
return widgets
--------------------------------------------------------------------------------