5.1 widget
Constructor:
example=widget.newWidget()
This sets up an empty widget called example with does nothing.
Functions and Fields:
example:run()
runs the GUI with this widget as the screen; stops when widget.quit is true
example:onClick()
defines what the widget does when clicked; by default does nothing
example:draw()
draws the widget; This is useful if the widget needs to be redrawn. by default does nothing
example:processEvent(event,side,x,y)
processes an event, ignoring events other than monitor touch and mouse click
example.vWeight
specifies the height of the widget compared to a standard widget; For example, if vWeight was 0.5, this widget would ask for half as much room as a vWeight=1 widget.
example.hWeight
specifies the width of the widget compared to a standard widget One might ask why this even exists, since it is a blank widget which does nothing. The answer is that all other interface elements (buttons, progress bars, et c.) are also widgets, and get to run these functions as well. In programmer terminology all widget classes (such as button) derive from this class. So while you’ll probably never use the newWidget function, every widget you create will have access to the run and onClick functions. And you can overwrite the onClick function of any widget to make it do whatever you want when you click it.
5.2 row
Constructor:
example=widget.newRow()
Functions and Fields:
example:add(widget)
adds a widget to the row
example.hSpacingWeight
specifies how large the horizontal spacing should be relative to a standard widget; only affects rows
5.3 column
Constructor:
example=widget.newColumn()
Functions and Fields:
example:add(widget)
adds a widget to the column
example.vSpacingWeight
specifies how large the vertical spacing should be relative to a standard widget; only affects columns
5.4 button
Constructor:
example=widget.newButton(”label”)
where “label” should be the label of the button.
Functions and Fields:
example:drawFull()
draws the button as a solid, labeled block
example:drawOutline()
draws the button a hollow, labeled block
example:blink()
draws the button as an outline, then solid again a moment later; This can give feedback to the user that the button was really clicked.
example.label
the label of the button
5.5 toggle button
Constructor:
example=newToggleButton(”label”)
A toggle button is derived from button, and so can use all of a button’s functions and field. In addition it will either draw as a solid or outline depending on its state.
Functions and Fields:
example:toggle()
switched the button between the on and off states
example.state
true iff the button is on
5.6 label
Constructor:
example=widget.newLabel(”text”)
This creates a label called example which displays the word “text”. Functions and Fields:
example.text
what text the label is displaying
5.7 slider
Constructor:
example=widget.newSlider(1,10)
creates a slider called example which goes between 1 and 10 inclusive
Functions and Fields:
example.value
the value of the slider
example.foregroundColor
the color of the filled slider portion
example.backgroundColor
the color of the unfilled slider portion
5.8 flag monitor
Constructor:
example=widget.newFlagMonitor(”top”)
creates a flag monitor called example which monitors and sets the redstone bundled signal out the top of the computer:
Functions and Fields:
example:get(i)
returns the i’th color of the output
example:set(i,value)
sets the i’th color of the output to value; if value is absent or nil, it is treated as true
example:clear(i)
sets the i’th color of the output to off
example:toggle(i)
sets the i’th color of the output to whatever it was not before; If it was on previously, it will be off. If it was off previously, it will be on.
example.flags
a 16-bit integer representing the state of the bundled output
5.9 chooser
Constructor:
example=widget.newChooser(”axe”,”pick”,”axe”,”fish”)
will create a chooser called example which allows the user to pick between “pick”, “axe” and “fish”. It will initially be set to “axe”. Note that chooser derives from button, so it has all the functionality of a button as well.
Functions and Fields:
example:choose
brings up a page to allow the user to choose one of the possible choices
example.label
the current choice
5.10 progress bar
Constructor:
example=newProgressBar(15)
will create a progress bar called example which will be full when it reaches a value of 15.
Functions and Fields:
example.value
the current value of the progress bar
example.foreground
the color of the filled portion
example.background
the color of the unfilled portion