Simple GUI API

Discussion in 'ComputerCraft Programming' started by hsun324, May 7, 2013.

  1. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    This is a simple Lua and CC Advanced Computers and Montors Graphical User Interface API. It is Object Oriented, so you program "like" if it were using Swing in Lua.
    ATM, I don't have much time, but I will begin to make reference materials on this thread.

    Latest Stable Release: v0.1a

    How to Install:
    1. Download RAR archive and extract to computer.
    2. Upload to ROOT directory of computer using FTP.
    3. Use dofile with an argument pointing to the sGUIAPI.lua file within the sGUIAPI folder to load the API.
    Sample Program:
    Code:
    dofile("sGUIAPI/sGUIAPI.lua") -- Load API
    display = Display:new("left") -- Bind a display to the left side
     
    function slapPerson()
      -- Slap person here
    end
     
    epicButton = Button:new("Epic", Rectangle:new(10, 10, 10, 3),
      colors.white, colors.red, slapPerson) -- Make a epic button
    display:addChild(epicButton) -- Add the button to the display
     
    lameButton = Button:new("Lame", Rectangle:new(1, 1, 10, 3),
      colors.white, 0) -- Make a lame button
    lameButton.visible = false -- Hide the lame button
    display:addChild(lameButton)
     
    while true do
      display:render() -- Render everything
      local event, p1, p2, p3, p4, p5 = os.pullEventRaw() -- Get some events
      display:interceptEvent(event, p1, p2, p3, p4, p5) -- Send the events you don't want to the display
    end
    Known Bugs:
    • Bar label color cannot be omitted.
    • Random rounding errors. (Esp. w/ small numbers in the Progress Bar)
     
  2. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    Documentation:
    WIP

    Class List:
    • Rectangle
    • Display
    • Label
    • Button
    • Bar
    • Rule
    • Util
    Code:
    Rectangle:new(x, y, width, height)
     
    Display:new([side]) -- returns a display object bound to that side or term if not specified
    Display:render() -- render, call the render screen
    Display:interceptEvent(event, p1, p2, p3, p4, p5) -- event intercept, call to handle monitor touch events
    Display:addChild(component) -- adds a child
    Display:removeChild(child) -- removes a child
     
    Util:pointWithin(point, rectangle) -- is the point inside the rectangle?
     
    -- Generics for below
    *.visible -- visiblity
    *.callback -- callback
     
    Label:new(text, position, [textColor, bgColor, callback]) -- returns a new label component
    Label.text -- text of label
    Label.textColor -- color of label
    Label.bgColor -- color of background
     
    Button:new(label, position, [labelColor, buttonColor, callback]) -- returns a new button component
    Button.label -- label
    Button.labelColor -- color of label
    Button.buttonColor -- color of button
     
    Bar:new(label, unit, position, textColor, [barFGColor, barBGColor, callback]) -- returns a new progress bar component
    Bar.label -- label
    Bar.textColor -- color of label
    Bar.fgColor -- color of bar
    Bar.bgColor -- color of bar background
     
    Rule:new(kind, position, [color, callback]) -- returns a new rule component
    Rule.VERTICAL = 1 -- vertical rule kind
    Rule.HORIZONTAL = 2 -- horizontal rule kind
    Rule.color = -- rule color
    Notes:
    • Color parameters can be set to zero or omitted to be used as transparent.
    • Rules use the width parameter from Rectangle for their length.
    • No changes to component parameters will take effect until a re-render.
    • Display renders clear the screen.
    • All fields in classes are exposed, but it is of your best interest to not attempt to mess with them.
    • Make sure you use colons ( : ) for functions and periods ( . ) for fields in the classes. Classes go bonkers without it.
     
  3. mmsyrup123

    mmsyrup123 Gem Hunter

    Joined:
    Jan 20, 2012
    Messages:
    98
    Likes Received:
    7
    that's called a bump, friend.
     
  4. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    Since when did bumps occur a single minute after the initial post goes up?
     
    Magi1053 and Fluttermine like this.
  5. gknova61

    gknova61 Farbes Lover

    Joined:
    Mar 17, 2012
    Messages:
    1,238
    Likes Received:
    350
    Some function usage, info, etc. would be nice :)
     
  6. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    Edit: I posted some for you gk. :p
     
  7. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    Yay something to pull apart and mess around with
    Thank you =P