need advise on grid like control...

MisterX b.xavier at internet.lu
Wed Aug 25 00:59:17 EDT 2004


Meitnik at aol.com wrote:

> -- UM, what a minute. If RR gave me all the tools to do it, yeah, I
> would rool my own. But after so many years, I have yet seen anyone
> really make a true data grid that general enough as a tool for all to
> customize. I think 100 pluse votes says much.

Well, it's been available in my DiscreteBrowser since last year!
It's as easy as
set the tabstops of fld myfieldname to FindTabStops(myfieldname)

And the stack source is still opened! Unfortunately due to a serie of
issues with GM, html-based images, unfinished features, stack corruption
I havent released an upgrade. Im in the process of retesting a newer
browser.

Here it is a self configuring self sizing tabstop finder
I created it to translate the HTML Tables in the discrete browser
to a RR grid depending on the formattedwidth of the text in these
columns.

http://monsieurx.com/modules.php?name=Downloads&d_op=getit&lid=44

I've commented the function for the occasion.
Look in the comments for what is configurable.

  -- tool using this should check that maxfwt is ok
  -- in case the field had no tab characters
  -- example
  put FindTabStops(myfieldname) into maxfwt
  if maxfwt is not empty and item 1 of maxfwt is not 0
  then set the tabStops of fld fldname to maxfwt

function FindTabStops fldname
  local maxfw=0,txtsize
  local fldwidthdiv2, sourcelines
  local ht
  local maxtabs=2, maxtabline=1
  local ftxtsize

  put the textheight of fld fldname into txtsize
  put the width of fld fldname div 2 into fldwidthdiv2
  put the number of lines in fld fldname into sourcelines

  put fld fldname into ht

  set the itemdelimiter to tab
  -- find the largest formattedwidths for each column and line
   repeat with y = 1 to sourcelines
    get the number of items in line y of ht
    if it > maxtabs then
      put y into maxtabline
      put it into maxtabs
    end if
  end repeat

  -- you can customize the default width of your columns here.
  -- note the local variable "defaultwidth" created problems with
  -- RR script compiler before 2.5

  local defaltwidth=100, lcount

  -- optional auto configuration for defaultwidth
  --put (the width of fld fldname) div maxtabs-1 into defaltwidth
  put the fontsize of fld fldname into ftxtsize
  if ftxtsize is empty then put 12 into ftxtsize
  repeat with x = 1 to maxtabs
    put defaltwidth into item x of maxfw
  end repeat
  -- now, for each line
  repeat with y = 1 to sourcelines
    --set cursor to busy -- slows things down on large scripts
    put the number of items in line y of ht into lcount
    if lcount < 2 then next repeat
    -- for each item, find the best or custom fit
    repeat with l = 1 to lcount
      get the formattedwidth of item l of line y of fld fldname
      if it < defaltwidth then get defaltwidth
      if it > item l of maxfw then
        put it into item l of maxfw
      end if
    end repeat
  end repeat

  -- if a column is suposed to be center or right adjusted
  -- you can put a loop per line to pad with spaces here.

  local maxfwt,maxitems,lastit
  put the number of items in maxfw into maxitems
  put 0 into lastit
  repeat with x = 1 to maxitems
   -- note the different settings you can have in this loop
   -- this is the where you define if a column is fixed or not.
   get item x of maxfw
    if x = 1 then
      put it+10 & comma after maxfwt -- here we set a fixed width if we know
the column
      --put it & comma after maxfwt -- a small offset can help
      else if x = maxitems then
      put it + 1000 after maxfwt -- last item has a larger width so it is
not visible
    else
      get it + 12 + lastit -- normal width
      put it & comma after maxfwt
    end if
    put it into lastit
  end repeat
  -- delete last char of maxfwt
  return maxfwt
end FindTabStops

-- FindTabstops will always return a list of items equal to the number
   of tab delimited columns as found in the field in question.
-- Some columns may not be correctly set - Im aware of this issue and
   despite tweaking this function for each app, it remains a mistery why.
   I suspect a formattedWidth problem - an explanation is truely welcome!
--
So instead of wasting votes on RR non-issues, please vote for my bugs and
if you can explain the reason why Form...Wid.. is not always correct, im
interested! ;)

The other solution and surely it's been explored in the list is to create
vertical column fields which you can directly align left right center which
is even better.

The last solution is to use the format function - but it doesn't respect
alignment either.

If you check most of my tool including WinN2O, pieControl, etc... they all
use the same 2 fields, autotabstops, and autosort columns.

Why customize when you can automate?

cheers
Xavier

--
http://MonsieurX.com
A virtual garage for revolutionary tools
RR Plugins, applications, links and tips
--



More information about the use-livecode mailing list