1. How print sequence of comma delimited numbers, in ROWS?

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.

I caused the sequences to be modified to have appropriate spaces in front of single digit numbers, in the hope that this would help, but this only helps if I use fixedsys font, which I'd rather not be restricted to.

Example of original sequences:
{"1,2,3,4,5,12,23,24,25,56,"}
{"1,2,3,4,5,4,3,2,1,5,"}

Example of modified sequences:

{"1,2,3,4,5,12,23,24,25,56,"} 
{"1,2,3,4,5, 4, 3, 2, 1, 5,"}   

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?

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.

Any ideas?

Dan

new topic     » topic index » view message » categorize

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

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 message » categorize

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

Thanks Matt, I'd hoped to post a <slapping self on head>, "never-mind", before anyone took the time to consider the question, as it finally occurred to me I'd just have to do it comma by comma instead of the whole thing at once. I already had run the sequences through some code to insert the spaces, but I was so focused on spitting the whole thing (or one line at a time) out at once that I never thought to just do the output one comma at a time along the line.

I like how you made a sequence of the extents, and I usually don't think to use sprintf much, so I had to look twice to see how your pseudo-code referenced commas, but I see it now, thanks!

I think (hope!) I learn some by seeing how actual programmers write code! smile

Dan

new topic     » goto parent     » topic index » view message » categorize

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

Just a hint, if you need redraw speed you should consider drawing first to a buffer and then outputing that to a window.

Regards,

Guillermo

new topic     » goto parent     » topic index » view message » categorize

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

gbonvehi said...

Just a hint, if you need redraw speed you should consider drawing first to a buffer and then outputing that to a window.

Regards,

Guillermo

Thanks Guillermo, that's a good suggestion, and, as chance would have it, I'm already doing that, although not for speed but rather because I'm putting stuff in a virtual window for scrolling.

Dan

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu