* Help with IUPMATRIX

For plugin authors to discuss plugin programming
Post Reply
avatar
shoshk
Superstar
Posts: 280
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Help with IUPMATRIX

Post by shoshk »

I'm working on a major upgrade to our data entry and sourcing plugin -- many improvements to the user interface.

I'm starting to use iupmatrix for the first time and am running into some problems. I'm about ready to throw in the towel and go back to iupgridbox.

For my first efforts, I'm using it to display string information to the user. So, my needs are pretty simple. I have 2 problems:
  • long lines - iupmatrix doesn't seem to have wordwrap
  • multiline text - can't figure out how to get cells to display multiple lines
Any suggestions?
Shosh Kalson
User avatar
ColeValleyGirl
Megastar
Posts: 5520
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Help with IUPMATRIX

Post by ColeValleyGirl »

I can offer nothing but sympathy. I threw in the towel on IupMatrix some time ago...

Now, if you have a solution for freezing (say) the two leftmost columns in an iupMatrix, I'd love to hear it.
User avatar
tatewise
Megastar
Posts: 28486
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with IUPMATRIX

Post by tatewise »

My Show Project Statistics plugin uses iup.matrix and the Data heading cells at the bottom of the Facts tab have two lines but I'd have to dig into the script to see how it achieves that.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
shoshk
Superstar
Posts: 280
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Help with IUPMATRIX

Post by shoshk »

I was afraid of that. On the surface, it’s so easy to use. But as soon as you want anything useful, it fails.

Oh well, back to gridbox…
Shosh Kalson
User avatar
ColeValleyGirl
Megastar
Posts: 5520
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Help with IUPMATRIX

Post by ColeValleyGirl »

Shosh, I've moved this to the Programming Technicalities Forum.
User avatar
tatewise
Megastar
Posts: 28486
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with IUPMATRIX

Post by tatewise »

I have experimented with iup.matrix and modified one of the example scripts as shown below.
It adjusts the line and column size according to cell contents.
So if a new cell value is set and the FitToText is applied it adjusts the sizes.

Code: Select all

require( "iuplua" )
require( "iupluacontrols" )

mat = iup.matrix {
    numcol=5, 
    numlin=3,
    numcol_visible=5, 
    numlin_visible=3, 
    resizematrix = "YES"}

mat:setcell(0,0,"Inflation")
mat:setcell(1,0,"Medicine")
mat:setcell(2,0,"Food")
mat:setcell(3,0,"Energy")
mat:setcell(0,1,"Jan 2000")
mat:setcell(0,2,"Feb 2000")
mat:setcell(0,3,"Mar 2000")
mat:setcell(0,4,"Apr 2000")
mat:setcell(0,5,"May 2000")
mat:setcell(1,1,"5.6")
mat:setcell(2,1,"2.2 \n with long text suffix")
mat:setcell(3,1,"7.2")
mat:setcell(1,2,"4.6\n\nend")
mat:setcell(2,2,"1.3")
mat:setcell(3,2,"1.4")

-- The following 8 lines adjust the size of each line & column to fit the text in cells
mat.FitToText = "L1"
mat.FitToText = "L2"
mat.FitToText = "L3"
mat.FitToText = "C1"
mat.FitToText = "C2"
mat.FitToText = "C3"
mat.FitToText = "C4"
mat.FitToText = "C5"

dlg = iup.dialog{iup.vbox{mat; margin="10x10"}; shrink="yes"}

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

function mat:click_cb(lin, col, status)	-- Mouse-click on any cell to set its value and adjust its size
	mat:setcell(lin,col," new value entered \n on two lines ")
	mat.FitToText = "L"..lin
	mat.FitToText = "C"..col
	return iup.IGNORE
end

if (iup.MainLoopLevel()==0) then
  iup.MainLoop()
end
Last edited by tatewise on 05 Sep 2023 21:03, edited 1 time in total.
Reason: Updated script to show setting a cell value
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
shoshk
Superstar
Posts: 280
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Help with IUPMATRIX

Post by shoshk »

I finally tore myself away from the computer and went to bed. I will try this out tomorrow. Thank you.
Shosh Kalson
avatar
shoshk
Superstar
Posts: 280
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Help with IUPMATRIX

Post by shoshk »

Works. Thank you.

Still, doesn't seem to be a wordwrap option...

Yes, yes, I know... I'm quite demanding. :D
Shosh Kalson
User avatar
tatewise
Megastar
Posts: 28486
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with IUPMATRIX

Post by tatewise »

Correct, but they have been adding Word Wrap and Text Wrap options to some controls in recent years.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
tatewise
Megastar
Posts: 28486
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with IUPMATRIX

Post by tatewise »

Here is a Lua function to perform word wrap that I found here:
http://www.computercraft.info/forums2/i ... -function/
that was derived from here: http://lua-users.org/wiki/StringRecipes
There are probably others...

I have modified it a little to also wrap on hyphen separators and reduce multiple spaces to one space.

I also have a variant that preserves existing newline characters and starts the wrapping again from that point.
Alternatively, the newline characters can be treated the same as space separators.

Code: Select all

-- Perform word wrap on space and hyphen separators.
function wrap(str, limit)
  limit = limit or 72
  local here = 1

  return ""..str:gsub("([%s%-]+)()([^%s%-]+)()",
    function(sep, beg, word, fin)
        if fin - here > limit then
          here = beg
          sep = sep:gsub("%s+","")
          return sep.."\n"..word
        end
        sep = sep:gsub("%s+"," ")
        return sep..word
    end )
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
shoshk
Superstar
Posts: 280
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Help with IUPMATRIX

Post by shoshk »

Thank you.
Shosh Kalson
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Help with IUPMATRIX

Post by Ron Melby »

Mike I would be very interested to see the function that also preserves newlines. thanks.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28486
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with IUPMATRIX

Post by tatewise »

Here it is:

Code: Select all

-- Perform word wrap on space and hyphen separators but preserve newlines.
function wrap(str, limit)
  limit = limit or 72
  local here = 1

  return ""..str:gsub("([%s%-\n\r]+)()([^%s%-\n\r]+)()",
    function(sep, beg, word, fin)
        if sep:match("[\n\r]") or fin - here > limit then
          here = beg
          sep = sep:gsub("%s+","")
          return sep.."\n"..word
        end
        sep = sep:gsub("%s+"," ")
        return sep..word
    end )
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Post Reply