Fantastic examples. Thanks a lot.
Based on your tutorials I added some functions (most of them utterly useless...

mainly to get a hang on how to read or set the states of checkboxes, buttons, etc.
Code: Select all
local ui = fu.UIManager
local disp = bmd.UIDispatcher(ui)
local width,height = 400,400
function rgbToHex(rgb)
hexadecimal = '0x'
for key, value in pairs(rgb) do
local hex = ''
while(value > 0)do
local index = math.fmod(value, 16) + 1
value = math.floor(value / 16)
hex = string.sub('0123456789abcdef', index, index) .. hex
end
if(string.len(hex) == 0)then
hex = '00'
elseif(string.len(hex) == 1)then
hex = '0' .. hex
end
hexadecimal = hexadecimal .. hex
end
print(hexadecimal)
return hexadecimal
end
win = disp:AddWindow({
ID = 'MyWin',
WindowTitle = 'My First Window',
Geometry = { 100, 100, width, height },
Spacing = 10,
ui:VGroup{
ID = 'root',
-- Add your GUI elements here:
ui:HGroup{
Margin = 20, -- defines left/right margin
ui:Button{ ID = 'B', Text = 'The Button Label' },
ui:Button{ ID = 'C', Text = 'The Other Button' },
},
-- Add your GUI elements here:
ui:HGroup{
Margin = 20, -- defines left/right margin
ui:CheckBox{ ID = 'D', Text = 'The Checkbox Label' },
},
-- Add your GUI elements here:
ui:HGroup{
Margin = 10, -- defines left/right margin
ui:ColorPicker{ ID = 'Color' },
},
ui:HGroup{
Margin = 10, -- defines left/right margin
ui:Label{ ID = 'L', Text = 'This is a Label', Alignment = { AlignHCenter = true, AlignTop = true }, },
ui:Label{ ID = 'L2', Text = 'This is another Label', Alignment = { AlignHCenter = true, AlignTop = true }, },
},
},
})
clicks = 0
choices = {"Don't click him..", "You never listen, do you?", "Seriously?", "You did it again" }
-- The window was closed
function win.On.MyWin.Close(ev)
disp:ExitLoop()
end
-- Add your GUI element based event functions here:
itm = win:GetItems()
function win.On.B.Clicked(ev)
print('Button A Clicked')
disp:ExitLoop()
end
function win.On.C.Clicked(ev)
print('Button B Clicked')
--disp:ExitLoop()
choice = clicks%4 + 1
print("choice: " .. choice)
itm.B.Text = choices[choice]
clicks = clicks + 1
print(itm.Color.Color.R)
--dump(itm.Color.Color)
itm.L.Text = "R: " .. string.format("%.3f",itm.Color.Color.R) .. " | G: " .. string.format("%.3f",itm.Color.Color.G) .. " | B: " .. string.format("%.3f",itm.Color.Color.B)
myRgb = {math.floor(itm.Color.Color.R*256), math.floor(itm.Color.Color.G*256), math.floor(itm.Color.Color.B*256)}
rgbToHex(myRgb) -- triggers grbToHex function correctly
itm.L2.Text = "Hex: " .. hexadecimal
end
function win.On.D.Clicked(ev)
theState = itm.D.CheckState
print(theState)
if theState == "Checked" then
itm.D.Text = "Gosh, I am HOT!"
else
itm.D.Text = "How boring..."
end
end
function win.On.Color.changeColor(ev)
print('Did some color')
end
win:Show()
disp:RunLoop()
win:Hide()
While looking up checkbox in the QT documentation helped, neither "colorSelected" nor "currentColorChanged" seems to yield any event..
Code: Select all
function win.On.Color.changeColor(ev)
print('Did some color')
end