Skip to content

Element Attributes

trubblegum edited this page Mar 26, 2012 · 5 revisions

Unless otherwise stated, this refers to this element.

Table of Contents

Common values

The following common values may be get and set.

element.label = string
A label to display for the element. Used for any text directly associated with an element.
element.pos = Gspot:pos()
A positioning table, which inherits from Gspot.pos_mt
pos.x is an element's horizontal position, originating in the top-left corner, and relative to element.parent.pos.x if set.
pos.y is an element's vertical position, originating in the top-left corner, and relative to element.parent.pos.y if set.
pos.w is an element's width.
pos.h is an element's height.
pos.r is an element's radius. Not fully implemented.
element.style = table
A style table which inherits from element.parent.style or Gspot.style. This is initialized without values, and is used to set independent styles.
style.unit is a standard unit, used to maintain consistency. Default 16px.
style.font is used to render text.
style.fg is the foreground colour, used to render text.
style.bg is the background colour, used to render group backgrounds.
style.default is the default button colour.
style.hilite is the button hilight colour, used when the mouse is over the element.
style.focus is used to render selected options.
element.tip = 'string'
Displays string in a box when the mouse is over the element.

Reserved values

The following common values may be get but not set.

element.Gspot
A reference to the instance which contains this element.
element.parent
A reference to this element's parent element, or nil. This element will be positioned relative to parent's position.
use element:addchild(this) and this.parent:remchild(this) to allow relative positioning, where :
element is any element
this is the element to add or remove from parent's children.
element.children
A table containing references to this element's children. See above for usage.
element.display
true if the element is to be shown, false if hidden.
use element:show() and element:hide() to show and hide an element along with its children.
element.dt
Time in seconds since element.uptade() was called, if element.update is set.

Behaviours

The following behaviours may be set for any element.

ToDo :
functions enter, leave, wheelup, wheeldown
exceptions
element.update = function(this, dt)
Calls element:update(dt) every update, or as specified by element.updateinterval
dt is passed along by the call to Gspot:update(dt)
element.updateinterval = seconds
Sets an interval at which to call element:update(dt)
element.click = function(this)
Called when the element is clicked with the left mouse button.
element.rclick = function(this)
As above, but applies to the right mouse button.
element.drag = true
Allows this element to be dragged with the mouse, and calls element:drop(bucket) when released.
Gspot.drag will be a reference to the element while it is being dragged.
element.rdrag = true(this)
As above, but applies to the right mouse button.
element.drag = function(this)
As above, and will be called every update until released.
this is this element.
element.rdrag = function(this)
As above, but applies to the right mouse button.
element.drop = function(this, bucket)
If set, will be called when this element is dropped.
this is this element.
bucket is the topmost element under this element, or false.
element.rdrop = function(this, bucket)
As above, but applies to the right mouse button.
element.catch = function(this, ball)
If set, will be called when an element is dropped onto this element.
this is this element.
ball is the element being dropped.
element.rcatch = function(this, ball)
As above, but applies to the right mouse button.
element.keypress = function(this, key, code)
If set, will be called when a key is pressed while this element has focus. Use Gspot:setfocus(this)Gspot:unfocus() to set and clear focus, and Gspot.focus to get the element which has focus, or false.
key, code passed along by the call to Gspot:keypress(key, code)

Element-specific values

The following common values may be get and set.

element.value
The value associated with an option element, or
The value of the selected option, if this element is the parent of an option element.
bool indicating the state of a checkbox element
element.values
Values associated with a scrollbar element.
element.values.min is the minimum value for this scrollbar.
element.values.max is the maximum value for this scrollbar. If this scrollbar is attached to a scrollgroup, this will be automatically updated when a child is added to the scrollgroup.
element.values.current is the current value for this scrollbar.
element.values.step is the amount by which to step the value of this scrollbar when scrolling with the mouse wheel.
element.img
The image associated with an image or imgbutton element.
use element.img = element:loadimage('path or image') to change the image associated with one of these elements.

Clone this wiki locally