Code: Select all
-- require 'QSYS'
require('iuplua')
require('iupluacontrols')
-- https://www.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix_attrib.html#Cell_Attributes
-- local _C = {}
-- local cfp = ('%s%s'):format(__ipath.global(), '_C.dat')
-- cfp, _C = rtvTBL(cfp)
local _C =
{
[1] = {["name"] = "_black", ["S"] = 0, ["L"] = 0, ["H"] = 0, ["xrgb"] = "#000000", ["rgb"] = {[1] = 0, [2] = 0, [3] = 0,},},
[2] = {["name"] = "_Foreground", ["S"] = 0, ["L"] = 0, ["H"] = 0, ["xrgb"] = "#000000", ["rgb"] = {[1] = 0, [2] = 0, [3] = 0,},},
[3] = {["name"] = "black", ["S"] = 0, ["L"] = 0, ["H"] = 0, ["xrgb"] = "#000000", ["rgb"] = {[1] = 0, [2] = 0, [3] = 0,},},
[4] = {["name"] = " ", ["S"] = 0, ["L"] = 0.12156862745095, ["H"] = 0, ["xrgb"] = "#1F1F1F", ["rgb"] = {[1] = 31, [2] = 31, [3] = 31,},},
[5] = {["name"] = " ", ["S"] = 0, ["L"] = 0.1254901960784, ["H"] = 0, ["xrgb"] = "#202020", ["rgb"] = {[1] = 32, [2] = 32, [3] = 32,},},
[6] = {["name"] = " ", ["S"] = 0, ["L"] = 0.1647058823529, ["H"] = 0, ["xrgb"] = "#2A2A2A", ["rgb"] = {[1] = 42, [2] = 42, [3] = 42,},},
[7] = {["name"] = " ", ["S"] = 0, ["L"] = 0.17647058823525, ["H"] = 0, ["xrgb"] = "#2D2D2D", ["rgb"] = {[1] = 45, [2] = 45, [3] = 45,},},
[8] = {["name"] = " ", ["S"] = 0, ["L"] = 0.2117647058823, ["H"] = 0, ["xrgb"] = "#363636", ["rgb"] = {[1] = 54, [2] = 54, [3] = 54,},},
[9] = {["name"] = " ", ["S"] = 0, ["L"] = 0.22352941176465, ["H"] = 0, ["xrgb"] = "#393939", ["rgb"] = {[1] = 57, [2] = 57, [3] = 57,},},
[10] = {["name"] = " ", ["S"] = 0, ["L"] = 0.24705882352935, ["H"] = 0, ["xrgb"] = "#3F3F3F", ["rgb"] = {[1] = 63, [2] = 63, [3] = 63,},},
[11] = {["name"] = " ", ["S"] = 0, ["L"] = 0.2588235294117, ["H"] = 0, ["xrgb"] = "#424242", ["rgb"] = {[1] = 66, [2] = 66, [3] = 66,},},
[12] = {["name"] = " ", ["S"] = 0, ["L"] = 0.31764705882345, ["H"] = 0, ["xrgb"] = "#515151", ["rgb"] = {[1] = 81, [2] = 81, [3] = 81,},},
[13] = {["name"] = "_Red", ["S"] = 0, ["L"] = 0.3843137254901, ["H"] = 0, ["xrgb"] = "#626262", ["rgb"] = {[1] = 98, [2] = 98, [3] = 98,},},
[14] = {["name"] = "_grey", ["S"] = 0, ["L"] = 0.49803921568615, ["H"] = 0, ["xrgb"] = "#7f7f7f", ["rgb"] = {[1] = 127, [2] = 127, [3] = 127,},},
[15] = {["name"] = "_Green", ["S"] = 0, ["L"] = 0.5019607843136, ["H"] = 0, ["xrgb"] = "#808080", ["rgb"] = {[1] = 128, [2] = 128, [3] = 128,},},
[16] = {["name"] = "gray", ["S"] = 0, ["L"] = 0.5019607843136, ["H"] = 0, ["xrgb"] = "#808080", ["rgb"] = {[1] = 128, [2] = 128, [3] = 128,},},
[17] = {["name"] = "gray_2", ["S"] = 0, ["L"] = 0.59999999999985, ["H"] = 0, ["xrgb"] = "#999999", ["rgb"] = {[1] = 153, [2] = 153, [3] = 153,},},
[18] = {["name"] = "silver", ["S"] = 0, ["L"] = 0.7529411764704, ["H"] = 0, ["xrgb"] = "#C0C0C0", ["rgb"] = {[1] = 192, [2] = 192, [3] = 192,},},
[19] = {["name"] = " ", ["S"] = 0, ["L"] = 0.7999999999998, ["H"] = 0, ["xrgb"] = "#CCCCCC", ["rgb"] = {[1] = 204, [2] = 204, [3] = 204,},},
[20] = {["name"] = " ", ["S"] = 0, ["L"] = 0.8392156862743, ["H"] = 0, ["xrgb"] = "#D6D6D6", ["rgb"] = {[1] = 214, [2] = 214, [3] = 214,},},
[21] = {["name"] = " ", ["S"] = 0, ["L"] = 0.9176470588233, ["H"] = 0, ["xrgb"] = "#EAEAEA", ["rgb"] = {[1] = 234, [2] = 234, [3] = 234,},},
[22] = {["name"] = " ", ["S"] = 0, ["L"] = 0.93725490196055, ["H"] = 0, ["xrgb"] = "#EFEFEF", ["rgb"] = {[1] = 239, [2] = 239, [3] = 239,},},
[23] = {["name"] = " ", ["S"] = 0, ["L"] = 0.96862745098015, ["H"] = 0, ["xrgb"] = "#F7F7F7", ["rgb"] = {[1] = 247, [2] = 247, [3] = 247,},},
[24] = {["name"] = "white", ["S"] = 0, ["L"] = 0.99999999999975, ["H"] = 0, ["xrgb"] = "#FFFFFF", ["rgb"] = {[1] = 255, [2] = 255, [3] = 255,},},
[25] = {["name"] = "_Background", ["S"] = 0, ["L"] = 0.99999999999975, ["H"] = 0, ["xrgb"] = "#ffffff", ["rgb"] = {[1] = 255, [2] = 255, [3] = 255,},},
[26] = {["name"] = " ", ["S"] = 0.35849056603745, ["L"] = 0.68823529411748, ["H"] = 0, ["xrgb"] = "#CC9393", ["rgb"] = {[1] = 204, [2] = 147, [3] = 147,},},
[27] = {["name"] = " ", ["S"] = 0.44881889763734, ["L"] = 0.75098039215668, ["H"] = 0, ["xrgb"] = "#DCA3A3", ["rgb"] = {[1] = 220, [2] = 163, [3] = 163,},},
[28] = {["name"] = " ", ["S"] = 0.49999999999969, ["L"] = 0.59999999999985, ["H"] = 0, ["xrgb"] = "#CC6666", ["rgb"] = {[1] = 204, [2] = 102, [3] = 102,},},
[29] = {["name"] = "red_indian", ["S"] = 0.53051643192457, ["L"] = 0.58235294117633, ["H"] = 0, ["xrgb"] = "#CD5C5C", ["rgb"] = {[1] = 205, [2] = 92, [3] = 92,},},
[30] = {["name"] = "brown", ["S"] = 0.59420289855072, ["L"] = 0.40588235294108, ["H"] = 0, ["xrgb"] = "#A52A2A", ["rgb"] = {[1] = 165, [2] = 42, [3] = 42,},},
[31] = {["name"] = "firebrick", ["S"] = 0.67924528301887, ["L"] = 0.4156862745097, ["H"] = 0, ["xrgb"] = "#B22222", ["rgb"] = {[1] = 178, [2] = 34, [3] = 34,},},
[32] = {["name"] = "coral_light", ["S"] = 0.78873239436549, ["L"] = 0.7215686274508, ["H"] = 0, ["xrgb"] = "#F08080", ["rgb"] = {[1] = 240, [2] = 128, [3] = 128,},},
}
local mat = iup.matrix
{
numlin = #_C,
numlin_visible = math.floor(#_C/8),
numcol = 8,
numcol_visible = 8,
height0 = 10,
scrollbar = 'YES',
resizematrix = 'NO',
LIMITEXPAND = 'YES',
}
--[[
function mat:value_cb(lin, col)
-- title
if lin == 0 or col == 0 then return nil end
return data[lin][col]
end
function mat:value_edit_cb(lin, col, newvalue)
data[lin][col] = newvalue
end
function mat:drop_cb(drop, lin, col)
-- Test of Very Big String for Dropdown!'
if (lin == 3 and col == 1) then
drop[1] = '1'
drop[2] = '2'
drop[3] = '3'
drop[4] = '4'
drop[5] = '5'
drop[6] = '6'
drop[7] = '7'
drop[8] = nil
return iup.DEFAULT
end
return iup.IGNORE
end
-- Mouse-click on any cell to set its value and adjust its size
function mat:click_cb(lin, col, status)
mat:setcell(lin, col, ' new value entered \n on two lines ')
mat.FitToText = ('L%i'):format(lin)
mat.FitToText = ('C%i'):format(col)
return iup.IGNORE
end
function dlg:resize_cb(w, h)
iup.Refresh(dlg)
mat.rasterwidth1 = nil
mat.rasterwidth2 = nil
mat.rasterwidth3 = nil
mat.rasterwidth4 = nil
mat.rasterwidth5 = nil
mat.fittosize = 'columns'
return iup.IGNORE
end
function dlg:attr(lin, col, mask)
mat:setcell(lin, col, 'Only numbers')
mat['mask1:1'] = '/d*'
dlg = iup.dialog{mat}
end
]]
local btn_enter = iup.button{name = 'ENTER', title = 'ENTER', action = function(self) return iup.CLOSE end}
local btn_cancel = iup.button{name = 'CANCEL', title = 'CANCEL', action = function(self) return iup.CLOSE end}
local fn_keys = iup.hbox{btn_enter, btn_cancel}
local dlg = iup.dialog
{
iup.vbox
{
iup.vbox
{
mat,
},
},
iup.hbox{fn_keys},
margin = '10x10',
size = '360xHALF',
}
function bld_mat()
-- header
mat:setcell(0, 0, 'Color')
mat:setcell(0, 1, 'Name')
mat:setcell(0, 2, 'r')
mat:setcell(0, 3, 'g')
mat:setcell(0, 4, 'b')
mat:setcell(0, 5, 'h')
mat:setcell(0, 6, 's')
mat:setcell(0, 7, 'l')
mat:setcell(0, 8, 'xrgb')
mat['TYPE*:0'] = 'COLOR'
mat['ALIGNMENT1'] = 'ALEFT'
mat['ALIGNMENT5'] = 'ARIGHT'
mat['ALIGNMENT6'] = 'ARIGHT'
mat['ALIGNMENT7'] = 'ARIGHT'
mat['ALIGNMENT8'] = 'ALEFT'
mat['WIDTH1'] = 60
mat['WIDTH2'] = 12
mat['WIDTH3'] = 12
mat['WIDTH4'] = 12
mat['WIDTH5'] = 38
mat['WIDTH6'] = 38
mat['WIDTH7'] = 38
mat['WIDTH8'] = 48
for k, v in pairs(_C) do
local this = _C[k]
mat:setcell(k, 0, ('%i %i %i'):format(this.rgb[1], this.rgb[2], this.rgb[3]))
mat:setcell(k, 1, this.name)
mat:setcell(k, 2, this.rgb[1])
mat:setcell(k, 3, this.rgb[2])
mat:setcell(k, 4, this.rgb[3])
mat:setcell(k, 5, ('%3.5f'):format(this.H))
mat:setcell(k, 6, ('%1.7f'):format(this.S))
mat:setcell(k, 7, ('%1.7f'):format(this.L))
mat:setcell(k, 8, this.xrgb)
end
end
bld_mat()
dlg:showxy(iup.CENTER, iup.CENTER)if (iup.MainLoopLevel() == 0) then
iup.MainLoop()
end
I am surprised a bit at the amount of 'manual' code needed, most of it having to do with the fact that lua does not retain the layout of the table as I specify it.
anyway, down to two problems, the most important being my buttons do not show, i am sure I dont have the boxes correct, never quite understood that. the second less problematical is to disable the resize box on the gui.