more window stuff

This commit is contained in:
nobody
2015-12-17 20:30:00 -05:00
parent e2602348df
commit 8dd46e2bbc
6 changed files with 68 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ local Backend = require 'luigi.backend'
local window = Layout {
type = 'window',
background = { 255, 255, 255 },
icon = 'logo.png',
title = 'Test window',
width = 300,
@@ -11,9 +12,37 @@ local window = Layout {
minheight = 100,
maxwidth = 640,
maxheight = 480,
{ type = 'button', id = 'maximize', text = 'Maximize' },
{ type = 'button', id = 'minimize', text = 'Minimize' },
{ type = 'button', id = 'restore', text = 'Restore' },
left = 400,
top = 400,
{ type = 'panel',
{
text = 'This is an example of the "window" widget type.',
align = 'middle center', wrap = true,
},
{ flow = 'x', height = 'auto',
{ type = 'button', id = 'maximize', text = 'Maximize' },
{ type = 'button', id = 'minimize', text = 'Minimize' },
{ type = 'button', id = 'restore', text = 'Restore' },
},
{ flow = 'x', height = 'auto',
{
{ type = 'label', text = 'Left' },
{ type = 'text', id = 'left' },
},
{
{ type = 'label', text = 'Top' },
{ type = 'text', id = 'top' },
},
{
{ type = 'label', text = 'Width' },
{ type = 'text', id = 'width' },
},
{
{ type = 'label', text = 'Height' },
{ type = 'text', id = 'height' },
},
},
}
}
window.maximize:onPress(function ()
@@ -25,6 +54,20 @@ end)
window.restore:onPress(function ()
window.root.maximized = false
end)
window:onReshape(function (event)
local w, h = Backend:getWindowSize()
-- use widget.attributes to do a raw update, avoid firing onChange
window.width.attributes.value = tostring(w)
window.height.attributes.value = tostring(h)
end)
window:onChange(function (event)
local target = event.target
if target.type ~= 'text' then return end
local id = target.id
if id and window.root.attributeDescriptors[id] then
window.root[id] = tonumber(event.value)
end
end)
window:show()