Here is some very early work of a little project I thought of starting. The idea is to eventually have a parser that supports limited HTML. This snippet demonstrates tables and wrapping text inside cells. Much still needs to be done.
GLOBAL TABLE_BORDER = 6
GLOBAL TABLE_WIDTH = 400
GLOBAL TABLE_COLUMNS = 3
GLOBAL TABLE_HEIGHT = 300
TYPE TD
width as integer
value as string
ENDTYPE
type corner
x as integer
y as integer
x2 as integer
y2 as integer
endtype
global thing as corner
dim cells() as TD
addCell(TABLE_WIDTH/TABLE_COLUMNS,"Testing some junk")
addCell(TABLE_WIDTH/TABLE_COLUMNS,"foo bar!!!!")
addCell(TABLE_WIDTH/TABLE_COLUMNS,"Yo my people, what is up! This here be DJ White Boy and im bout to bust out some noise up in this here hizouse!")
sync on
repeat
cls
drawTable()
ink rgb(255,0,0),0
box thing.x, thing.y, thing.x2, thing.y2
ink rgb(255,255,255),0
gosub resize_table
sync
until spacekey()
resize_table:
mx = mousex()
my = mousey()
if mx>thing.x and mx<thing.x2
if my>thing.y and my<thing.y2
if mouseclick() = 1
if flag = 0
flag = 1
old_height = TABLE_HEIGHT
old_width = TABLE_WIDTH
mxt = mousex()
myt = mousey()
endif
TABLE_WIDTH = old_width + (mx - mxt)
TABLE_HEIGHT = old_height + (my - myt)
else
flag = 0
endif
endif
endif
RETURN
function drawTable()
x = 12
y = 12
outlineBox(x,y,TABLE_WIDTH,TABLE_HEIGHT,TABLE_BORDER, TABLE_COLUMNS)
rows = array count(cells())/TABLE_COLUMNS + 1
cell = 0
cw = TABLE_WIDTH/TABLE_COLUMNS
for r = 1 to rows
for c = 1 to TABLE_COLUMNS
if cell <= array count(cells())
ox = (c-1)*cw + (c-1)*TABLE_BORDER
oy = (r-1)*20
wrapText(x+ox,y+oy,cells(cell).value,cw)
inc cell, 1
else
exit
endif
next c
next r
endfunction
function wrapText(x as integer, y as integer, s as string, width as integer)
repeat
length = len(s)
for i = 1 to length
if text width(left$(s,i)) > width
exit
endif
next i
text x,y,left$(s,i-1)
y = y + text height(s)
s = right$(s,length-(i-1))
until len(s) = 0
endfunction
function addCell(width as integer, value as string)
c as TD
c.width = width
c.value = value
array insert at bottom cells()
i = array count(cells())
cells(i) = c
endfunction
function outlineBox(x as integer, y as integer, width as integer, height as integer, border as integer, columns as integer)
dec width, 1
offset = border * (columns-1)
box x-border,y-border,offset+x+width+border,y
box x-border,y,x,y+height
box offset+x+width,y,offset+x+width+border,y+height
box x-border,y+height,offset+x+width+border,y+height+border
area = 10
thing.x = offset+x+width+border-area
thing.y = y+height+border-area
thing.x2 = offset+x+width+border+area
thing.y2 = y+height+border+area
cw = width/columns
for t = 1 to columns-1
box (t-1)*border+x+cw*t,y,(t-1)*border+x+cw*t+border,y+height
next t
endfunction
