* IUP (tearing out non-extant hair)

For plugin authors to discuss plugin programming
Post Reply
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

IUP (tearing out non-extant hair)

Post by Ron Melby »

Code: Select all

quire('iuplua')
require('iupluacontrols')

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,},},
}

mlist = iup.matrixlist{}
mlist.count              = #_C -- count
mlist['VISIBLELINES']    = 4 -- math.floor(count/8)
mlist['EXPAND']          = 'YES'
mlist['COLUMNORDER']     = 'COLOR:IMAGE:LABEL'
mlist['EDITABLE']        = 'YES'
mlist['TITLE']           = 'IupMatrixList Colors'
mlist['BGCOLOR']         = '220 230 240'
mlist['FRAMECOLOR']      = '120 140 160'
mlist['ITEMBGCOLOR0']    = '120 140 160'  -- grey
mlist['ITEMFGCOLOR0']    = '255 255 255'

for k, _ in ipairs(_C) do
  local this = _C[k]
  -- color
  mlist[('COLOR%i'):format(k)]  = ('%i %i %i'):format(this.rgb[1], this.rgb[2], this.rgb[3])

  -- image
  mlist[('IMAGEACTIVE%i'):format(k)] = 'YES'
  mlist[('IMAGEVALUE%i'):format(k)] = 'OFF'
  mlist[('ITEMACTIVE%i'):format(k)] = 'YES'
  -- label
  mlist[tostring(k)] = ('%s  H: %s  S: %s  L: %s'):format(this.name, this.H, this.S, this.L)
  print(k)
end


local dlg = iup.dialog
{
  iup.vbox
  {
    iup.hbox
    {
      mlist,
      size  = 'FULLxFULL',
      expand = 'YES',
    HOMOGENOUS = 'YES',
--     margin = '10x10',
    },
    title = 'IupMatrixList Colors',
      size  = 'FULLxFULL',
    expand = 'YES',
    HOMOGENOUS = 'YES',
  },
}

dlg:showxy(iup.CENTER, iup.CENTER)

if (iup.MainLoopLevel() == 0) then iup.MainLoop() end
return
I have tried every different way I can think of, and been unsuccessful in getting the hbox to expand to the size of the vbox, as you can see some info is cut off, and I would just as soon have the hbox expand to the width of the dialog when I drag the box (it is obvs part of a larger program and going to work on addcol when this is done. what simple thing am I still misunderstanding here?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: IUP (tearing out non-extant hair)

Post by tatewise »

I don't think it is anything to do with the hbox or vbox or even the dialog.

The matrixlist appears to have fixed column widths for each of COLOR, IMAGE & LABEL regardless of how much text is assigned to the LABEL. The LABEL seems to be limited to about 24 characters.

BTW: matrixlist has no addcol attribute.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

well, drag me kicking and screaming into matrixes then. how can I make the color boxes in a matrix?
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

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,},},
}

local mat = iup.matrix
{
  numlin         =     #_C,
  numlin_visible =     math.floor(#_C/4),
  numcol         =     9,
  numcol_visible =     9,
  height0        =    10,
  widthdef       =   140,
  scrollbar      = 'YES',
  resizematrix   = '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 dlg = iup.dialog
{
  iup.vbox
  {
    mat,
    margin = '10x10'
  }
}

function bld_mat()
--[[
TYPEL:C: Type of the cell value in line L and column C.  (Since 3.9)
TYPE*:C: Type of column C.  (Since 3.9)
TYPEL:*: Type of line L.  (Since 3.9)


Can be TEXT, COLOR, FILL, or IMAGE. When type is COLOR the cell value is interpreted as a color and a rectangle with the color is drawn inside the cell instead of the text (the FGCOLOR of the cell is ignored). When type is FILL the cell value is interpreted as percentage and a rectangle showing the percentage in the FGCOLOR is drawn like in IupGauge and IupProgressBar. When type is IMAGE the cell value is interpreted as an image name, and if an image exist with that name is drawn (the name can NOT be of a Windows resource or GTK stock image). Only TEXT and IMAGE are affected by alignment attributes. Default: TEXT. (Since 3.9)
]]
-- header
  mat:setcell(0, 0, 'Color')
  mat:setcell(0, 1, 'Name')
  mat:setcell(0, 2, 'r')
  mat:setcell(0, 3, 'b')
  mat:setcell(0, 4, 'g')
  mat:setcell(0, 5, 'h')
  mat:setcell(0, 6, 's')
  mat:setcell(0, 7, 'l')
  mat:setcell(0, 8, 'xrbg')

  for k, v in pairs(_C) do
    local this = _C[k]
    mat:setcell(COLOR,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.rbg[1])
    mat:setcell(k, 3, this.rbg[1])
    mat:setcell(k, 4, this.rbg[1])
    mat:setcell(k, 5, this.H)
    mat:setcell(k, 6, this.S)
    mat:setcell(k, 7, this.L)
    mat:setcell(k, 8, this.xrbg)
  end
end

bld_mat()
dlg:showxy(iup.CENTER, iup.CENTER)
if (iup.MainLoopLevel() == 0) then
  iup.MainLoop()
end
I cannot form a correct COLOR statement (line 125) and to do it as I understand the documentation, it will not compile. I searched for a color statement, but could not find one in any plugin (there were candidates) but I don't understand it from the get go.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: IUP (tearing out non-extant hair)

Post by tatewise »

Ron, you are not following the instructions in the documentation.
You have even included the instructions for setting TYPE*:C: Type of column C.
But have not implemented that, so include the following statement:
e.g.
mat["TYPE*:0"] = 'COLOR' -- set the TYPE of column 0 to COLOR.

Then mat:setcell(k, 0, value) will work with value set to any iup color values.
They take the format red blue green without any commas.
e.g.
('%i %i %i'):format( red value, blue value, green value)

So the following will now work:
mat:setcell(k, 0, ('%i %i %i'):format(this.rgb[1], this.rgb[2], this.rgb[3]) )

Furthermore, you have not grasped the simplified format allowed for setting table values such as local _C.
e.g.
[1] = {["name"] = "_black", ["S"] = 0, ["L"] = 0, ["H"] = 0, ["xrgb"] = "#000000", ["rgb"] = {[1] = 0, [2] = 0, [3] = 0,},},
can be simplified to:
[1] = { name = "_black", S = 0, L = 0, H = 0, xrgb = "#000000", rgb = {[1] = 0, [2] = 0, [3] = 0,},},
As long as the names are alphanumeric they don't need [" "] brackets.

BTW: You have typos for:
mat:setcell(k, 2, this.rbg[1]) that should be mat:setcell(k, 2, this.rgb[1]) and [2] and [3].
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

the reason there is extra sugar in the array entries is they are copied out of the serialized table on disk.
I have corrected the other things, but it was never clear to me (and thats why I have the directions commented in there and asked the question here, how do I do color. So, it is a two step process, and I cannot do an overall, because I have column headers and must do each one separately.

thanks
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

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.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: IUP (tearing out non-extant hair)

Post by tatewise »

You are not reading the documentation again!
IupDialog
iup.dialog{child: ihandle}
child: Identifier of an interface element. The dialog has only one child.

Your script only renders the 1st child iup.vbox{...} and the 2nd child iup.hbox{fn_keys} is ignored.
It works if you place the buttons inside the 1st child iup.vbox{...}:

Code: Select all

local dlg = iup.dialog
{
  iup.vbox
  {
    iup.vbox
    {
      mat,
    },
    fn_keys,
  },
  margin = '10x10',
  size = '360xHALF',
}
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

Code: Select all

function crt_matrix()
-- header
  mat:setcell(0, 0, 'Slt')
  mat:setcell(0, 1, 'Color')
  mat:setcell(0, 2, 'Name')
  mat:setcell(0, 3, 'r')
  mat:setcell(0, 4, 'g')
  mat:setcell(0, 5, 'b')
  mat:setcell(0, 6, 'h')
  mat:setcell(0, 7, 's')
  mat:setcell(0, 8, 'l')
  mat:setcell(0, 9, 'xrgb')
  mat['BGCOLOR*:0'] = '255 255 255'
  mat['FGCOLOR*:0'] = '0 0 0'
  mat['TYPE*:0'] = 'TEXT'
  mat['MASK*:0'] = '%d'
  mat['TYPE*:1'] = 'COLOR'
  mat['ALIGNMENT2'] = 'ALEFT'
  mat['ALIGNMENT6'] = 'ARIGHT'
  mat['ALIGNMENT7'] = 'ARIGHT'
  mat['ALIGNMENT8'] = 'ARIGHT'
  mat['ALIGNMENT9'] = 'ALEFT'

  mat['WIDTH0'] = 12
  mat['WIDTH2'] = 60
  mat['WIDTH3'] = 12
  mat['WIDTH4'] = 12
  mat['WIDTH5'] = 12
  mat['WIDTH6'] = 38
  mat['WIDTH7'] = 38
  mat['WIDTH8'] = 38
  mat['WIDTH9'] = 40

  for k, v in pairs(_C) do
    local this = _C[k]
    mat:setcell(k, 0, '\00')
    mat:setcell(k, 1, ('%i %i %i'):format(this.rgb[1], this.rgb[2], this.rgb[3]))
    mat:setcell(k, 2, this.name)
    mat:setcell(k, 3, this.rgb[1])
    mat:setcell(k, 4, this.rgb[2])
    mat:setcell(k, 5, this.rgb[3])
    mat:setcell(k, 6, ('%3.5f'):format(this.H))
    mat:setcell(k, 7, ('%1.7f'):format(this.S))
    mat:setcell(k, 8, ('%1.7f'):format(this.L))
    mat:setcell(k, 9, this.xrgb)
  end
end

crt_matrix()

dlg = iup.dialog
{
  iup.vbox
  {
    mat,
    iup.hbox{btn_enter, btn_cancel},
    margin = '10x10',
    size = '368xHALF',
  },
}

dlg:showxy(iup.CENTER, iup.CENTER)if (iup.MainLoopLevel() == 0) then
  iup.MainLoop()
end
the issue here is cell at column 0 header Slt.

No matter what I have tried it is not input capable. and by accident it is display only, (which I would like other fields on that screen to be). I started without all the other type, mask and colors. what is going on now?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28436
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: IUP (tearing out non-extant hair)

Post by tatewise »

Typically, matrix line 0 and column 0 are Titles as stated in the documentation under Notes:
A matrix might have titles for lines and columns. Titles are always non scrollable, non editable and presented with a different default background color. A matrix will have a line of titles if an attribute of the "L:0" type is defined, where L is a line number, or if the HEIGHT0 attribute is defined. It will have a column of titles if an attribute of the "0:C" type is defined, where C is a column number, or if the WIDTH0 attribute is defined.
As it says, they are not editable.

You have defined mat:setcell(0, 0, 'Slt') and mat['WIDTH0'] = 12 so that forces column 0 to hold Titles.

So if you want a matrix without a Title column, then the columns must be numbered from 1 to n.

To inhibit editing of all cells there is the mat.READONLY = 'YES' attribute.
I think there should be a way of enabling EDITMODE on selected cells but I cannot get it to work.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: IUP (tearing out non-extant hair)

Post by Ron Melby »

From: Antonio Scuri 2008-10-29 12:57:36

Unfortunately yes, you have to do it in a callback.

Best,
scuri

> -----Original Message-----
> From: fla...@te... [mailto:fla...@te...]
> Sent: segunda-feira, 27 de outubro de 2008 15:01
> To: iup...@li...
> Subject: [Iup-users] IupMatrix Inactive cells
>
> Is there an easy way (attribute) to set only a few cells, lines or rows
> to
> be inactive?
> Or do we have to allways threat this in the callback?
>
> thanks
>
> Flavia

so that suitcases a great deal of its uselessness like everything iup
FH V.6.2.7 Win 10 64 bit
Post Reply