Allow multiple contexts to persist at once

This commit is contained in:
Kevin Harrison 2016-12-19 22:27:42 -05:00
parent c2fefb0601
commit 47128fed66
8 changed files with 1748 additions and 1692 deletions

View file

@ -1,7 +1,5 @@
-- An overview of most of the supported widgets.
local nk = require 'nuklear'
local checkA = {value = false}
local checkB = {value = true}
local radio = {value = 'A'}
@ -14,93 +12,96 @@ local property = {value = 6}
local edit = {value = 'Edit text'}
local comboA = {value = 1, items = {'A', 'B', 'C'}}
return function ()
if nk.windowBegin('Overview', 100, 100, 600, 450, 'border', 'movable', 'title') then
nk.menubarBegin()
nk.layoutRow('dynamic', 30, 1)
if nk.menuBegin('Menu', nil, 120, 90) then
nk.layoutRow('dynamic', 40, 1)
nk.menuItem('Item A')
nk.menuItem('Item B')
nk.menuItem('Item C')
nk.menuEnd()
return function (ui)
if ui:windowBegin('Overview', 100, 100, 600, 450, 'border', 'movable', 'title') then
ui:menubarBegin()
ui:layoutRow('dynamic', 30, 1)
if ui:menuBegin('Menu', nil, 120, 90) then
ui:layoutRow('dynamic', 40, 1)
ui:menuItem('Item A')
ui:menuItem('Item B')
ui:menuItem('Item C')
ui:menuEnd()
end
nk.menubarEnd()
nk.layoutRow('dynamic', 400, 3)
nk.groupBegin('Group 1', 'border')
nk.layoutRow('dynamic', 30, 1)
nk.label('Left label')
nk.label('Centered label', 'centered')
nk.label('Right label', 'right')
nk.label('Colored label', 'left', '#ff0000')
if nk.treePush('tab', 'Tree Tab') then
if nk.treePush('node', 'Tree Node 1') then
nk.label('Label 1')
nk.treePop()
ui:menubarEnd()
ui:layoutRow('dynamic', 400, 3)
if ui:groupBegin('Group 1', 'border') then
ui:layoutRow('dynamic', 30, 1)
ui:label('Left label')
ui:label('Centered label', 'centered')
ui:label('Right label', 'right')
ui:label('Colored label', 'left', '#ff0000')
if ui:treePush('tab', 'Tree Tab') then
if ui:treePush('node', 'Tree Node 1') then
ui:label('Label 1')
ui:treePop()
end
if nk.treePush('node', 'Tree Node 2') then
nk.label('Label 2')
nk.treePop()
if ui:treePush('node', 'Tree Node 2') then
ui:label('Label 2')
ui:treePop()
end
nk.treePop()
ui:treePop()
end
nk.spacing(1)
if nk.button('Button') then
ui:spacing(1)
if ui:button('Button') then
print('button pressed!')
end
nk.spacing(1)
nk.checkbox('Checkbox A', checkA)
nk.checkbox('Checkbox B', checkB)
nk.groupEnd()
nk.groupBegin('Group 2', 'border')
nk.layoutRow('dynamic', 30, 1)
nk.label('Radio buttons:')
nk.layoutRow('dynamic', 30, 3)
nk.radio('A', radio)
nk.radio('B', radio)
nk.radio('C', radio)
nk.layoutRow('dynamic', 30, 1)
nk.selectable('Selectable A', selectA)
nk.selectable('Selectable B', selectB)
nk.layoutRow('dynamic', 30, {.35, .65})
nk.label('Slider:')
nk.slider(0, slider, 1, 0.05)
nk.label('Progress:')
nk.progress(progress, 10, true)
nk.layoutRow('dynamic', 30, 2)
nk.spacing(2)
nk.label('Color picker:')
nk.button(nil, colorPicker.value)
nk.layoutRow('dynamic', 90, 1)
nk.colorPicker(colorPicker)
nk.groupEnd()
nk.groupBegin('Group 3', 'border')
nk.layoutRow('dynamic', 30, 1)
nk.property('Property', 0, property, 10, 0.25, 0.05)
nk.spacing(1)
nk.label('Edit:')
nk.layoutRow('dynamic', 90, 1)
nk.edit('box', edit)
nk.layoutRow('dynamic', 5, 1)
nk.spacing(1)
nk.layoutRow('dynamic', 30, 1)
nk.label('Combobox:')
nk.combobox(comboA, comboA.items)
nk.layoutRow('dynamic', 5, 1)
nk.spacing(1)
nk.layoutRow('dynamic', 30, 1)
if nk.widgetIsHovered() then
nk.tooltip('Test tooltip')
ui:spacing(1)
ui:checkbox('Checkbox A', checkA)
ui:checkbox('Checkbox B', checkB)
ui:groupEnd()
end
if ui:groupBegin('Group 2', 'border') then
ui:layoutRow('dynamic', 30, 1)
ui:label('Radio buttons:')
ui:layoutRow('dynamic', 30, 3)
ui:radio('A', radio)
ui:radio('B', radio)
ui:radio('C', radio)
ui:layoutRow('dynamic', 30, 1)
ui:selectable('Selectable A', selectA)
ui:selectable('Selectable B', selectB)
ui:layoutRow('dynamic', 30, {.35, .65})
ui:label('Slider:')
ui:slider(0, slider, 1, 0.05)
ui:label('Progress:')
ui:progress(progress, 10, true)
ui:layoutRow('dynamic', 30, 2)
ui:spacing(2)
ui:label('Color picker:')
ui:button(nil, colorPicker.value)
ui:layoutRow('dynamic', 90, 1)
ui:colorPicker(colorPicker)
ui:groupEnd()
end
if ui:groupBegin('Group 3', 'border') then
ui:layoutRow('dynamic', 30, 1)
ui:property('Property', 0, property, 10, 0.25, 0.05)
ui:spacing(1)
ui:label('Edit:')
ui:layoutRow('dynamic', 90, 1)
ui:edit('box', edit)
ui:layoutRow('dynamic', 5, 1)
ui:spacing(1)
ui:layoutRow('dynamic', 30, 1)
ui:label('Combobox:')
ui:combobox(comboA, comboA.items)
ui:layoutRow('dynamic', 5, 1)
ui:spacing(1)
ui:layoutRow('dynamic', 30, 1)
if ui:widgetIsHovered() then
ui:tooltip('Test tooltip')
end
local x, y, w, h = nk.widgetBounds()
if nk.contextualBegin(100, 100, x, y, w, h) then
nk.layoutRow('dynamic', 30, 1)
nk.contextualItem('Item A')
nk.contextualItem('Item B')
nk.contextualEnd()
local x, y, w, h = ui:widgetBounds()
if ui:contextualBegin(100, 100, x, y, w, h) then
ui:layoutRow('dynamic', 30, 1)
ui:contextualItem('Item A')
ui:contextualItem('Item B')
ui:contextualEnd()
end
nk.label('Contextual (Right click me)')
nk.groupEnd()
ui:label('Contextual (Right click me)')
ui:groupEnd()
end
end
nk.windowEnd()
ui:windowEnd()
end