This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
anonimo182's profile picture

Making a box with a header in it

Started by anonimo182, 09 November 2012 - 09:54 AM
anonimo182 #1
Posted 09 November 2012 - 10:54 AM
Hey guys:

I just wanted you learn the code to draw a box as big as you want, where you want, with a title in it!

CODE:
Spoiler


function drawBoxHeader(xlong, ylong, xpos, ypos, header)
  ywant = ylong
  xlong = xlong-2
  ylong = ylong-2
  ycurrent = ypos+1
  if #header % 2 == 0 then
          adder = 3
        else
          adder = 2
        end
  term.setCursorPos(xpos, ypos)
  term.write("+"..string.rep("-", xlong/2-#header+3)..header..string.rep("-", xlong/2-#header+adder).."+")
  repeat
    term.setCursorPos(xpos, ycurrent)
    term.write("|"..string.rep(" ", xlong).."|")
    ycurrent = ycurrent+1
  until ycurrent == ypos+ywant
  term.setCursorPos(xpos, ycurrent)
  term.write("+"..string.rep("-", xlong).."+")
end

http://pastebin.com/J1tJ2TUM

To download it to your computer type "pastebin get J1tJ2TUM boxdrawer" without the "'s and load it as a API and then run this code:

boxdrawer.drawBoxHeader(xpos, ypos, xlong, ylong, header)
Where:
xpos=Where you want it in X
ypos=Where you want it in Y
xlong=How big you want it in X
ylong=How tall you want it in Y
header=The title

Thanks for your attention!
Mandrake Fernflower #2
Posted 09 November 2012 - 10:59 AM
I would recomend adding this into a gui api. instead of a standalone
Leo Verto #3
Posted 09 November 2012 - 11:05 AM
Nice program, although I prefer adding the Header after drawing the border.
anonimo182 #4
Posted 09 November 2012 - 11:10 AM
Mandrake25: It was originally in MY API, but I just wanted o share :3
Leoverto: Is the same, just a bit more easier (And it is in the middle(the header!)!)
Mandrake Fernflower #5
Posted 09 November 2012 - 12:54 PM
Mandrake25: It was originally in MY API, but I just wanted o share :3
Leoverto: Is the same, just a bit more easier (And it is in the middle(the header!)!)

I would have to check with a admin, But isnt that kinda double posting?
anonimo182 #6
Posted 09 November 2012 - 01:49 PM
Mandrake25: It was originally in MY API, but I just wanted o share :3
Leoverto: Is the same, just a bit more easier (And it is in the middle(the header!)!)

I would have to check with a admin, But isnt that kinda double posting?
no, in my API fr WindOS, nothing else, sorry if you misunderstood