Re: How print sequence of comma delimited numbers, in ROWS?

new topic     » goto parent     » topic index » view thread      » older message » newer message
DanM said...

In a Win32Lib program, I have two sequences of numbers which have commas between each number, some of which are single digit and some are two digits, and could be more later. I'd like to display the two one above the other in a line, with each corresponding comma in line with one another, so each number is directly above/below the its corresponding number.

The easiest thing may be to use something like EuGrid, rather than drawing the text to your window directly.

DanM said...

While the above shows in this forum as I would like it to show, it does not show that way in a proportional font when I wPuts them to a window in my program. How does this forum software cause it to look "right"? Is it using a not proportional font?

Yes, using the markup that you used, the forum uses a fixed width font.

DanM said...

I can break longer sequences so as to only print as much as will fit into a line on a window, using getTextExtent(), but I can't yet figure out how to line up the commas.

You'll need to do each 'cell' of your display separately. The easiest scenario is if you know the max size of your numbers, and if you are happy with a fixed width for each column (i.e., where you use the same amount of space for a single digit number as for a double digit number).

It's more complex if you don't know ahead of time how large each number will be, and if you want the columns to be just big enough to fit the data. Here's a sorta-pseudocode example of what should work (the syntax is 4.0, and I don't know the syntax for the appropriate win32lib routines):

-- calculate the sizes 
sequence extents = repeat( repeat( 0, length( data[1] ) ), length( data ) ) 
sequence max_extent = repeat( 0, length( data[1] ) ) 
for r = 1 to length(data) do 
    sequence row = data[r] 
    for c = 1 to length(row) do 
        integer extent = getExtent( sprintf("%d,", row[c] ) ) 
        extents[r][c] = extent 
        if extent > max_extents[c] then 
            max_extents[c] = extent 
        end if 
    end for 
end for 
 
-- now draw the data 
integer y = start_y 
for r = 1 to length(data) do 
    sequence row = data[r] 
    x = left_coord 
    for c = 1 to length(row) do 
        x += max_extents[c] 
        wPuts( x - extents[r][c], y, sprintf("%d,") ) 
    end for 
    y += row_height 
end for 

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu