Class: Button

rat.ui. Button

new Button(resourceopt, resourceHiopt, resourcePressedopt, resourceDisabledopt, extra1opt, extra2opt)

Parameters:
Name Type Attributes Description
resource string <optional>
resourceHi string <optional>
resourcePressed string <optional>
resourceDisabled string <optional>
extra1 Object <optional>
(optional - used for external image formats (see makeImage))
extra2 boolean <optional>
(optional - used for external image formats (see makeImage))
Source:

Extends

Members

place

Inherited From:
Source:
To Do:
  • replace with standard position tracker object... (pos + rot)

Methods

(static) setupFromData()

Handle setting this up from data
Source:

applyRecursively(func, arg)

Parameters:
Name Type Description
func ?
arg ?
Inherited From:
Source:

clampScroll(offsetopt)

// clamp scroll offset to keep from scrolling past edges of actual content, // based on contentSize being correct. // todo allow optional passing in a potential value, and clamp that instead of my current value.
Parameters:
Name Type Attributes Description
offset Object <optional>
Inherited From:
Source:

findBestStateMatch(_flags, _states)

Parameters:
Name Type Description
_flags ?
_states ?
Source:

findSubElementByID(id, recursiveopt)

Parameters:
Name Type Attributes Description
id ?
recursive boolean <optional>
Inherited From:
Source:

fireCustomTrigger(triggerName, triggerArgs)

Parameters:
Name Type Description
triggerName string
triggerArgs ?
Inherited From:
Source:

getGlobalPos(xopt, yopt)

// get global coordinates from local coordinates relative to me. Compare with getGlobalContentPos below. // this involves processing the chain from parent to parent, to the top level. // But we do that locally, instead of recursively, to avoid extra function calls and overhead.
Parameters:
Name Type Attributes Description
x number <optional>
y number <optional>
Inherited From:
Source:

getMatchingStateIndex(state, createNewopt)

Parameters:
Name Type Attributes Description
state ?
createNew boolean <optional>
Source:

getSubElement(index)

Parameters:
Name Type Description
index ?
Inherited From:
Source:

scrollToCenter(offsetopt)

scroll this point to center
Parameters:
Name Type Attributes Description
offset Object <optional>
Inherited From:
Source:

scrollToCenterContent(offsetopt)

Scroll to center my content automatically
Parameters:
Name Type Attributes Description
offset Object <optional>
Inherited From:
Source:

setAllStatesByField()

Set this explicit value for all states that currently exist. So, big assumption that a bunch of useful states exist, which would be the case if you used one of the built-in shape-based button types. Of course, you want different states to have some different values, so this is only useful for things that stay the same, like frame width or font properties or something.
Source:

setBounds(x, yopt, wopt, hopt)

Set the position and size of this element
Parameters:
Name Type Attributes Description
x number | Object
y number <optional>
w number <optional>
h number <optional>
Inherited From:
Source:

setCallback(callback, userInfoopt)

set function to call when triggered (see Trigger code) callback is called with (element, userInfo) args callback is expected to return a flag indicating if the event was handled. if you return false, we keep looking for other ways the event can be handled. so, generally you probably want to return true.
Parameters:
Name Type Attributes Description
callback function
userInfo * <optional>
Inherited From:
Source:

setCallbackInfo(userInfo)

Set the data provided with the callbacks
Parameters:
Name Type Description
userInfo ?
Inherited From:
Source:

setFlag()

Set (or clear) a flag in this element's flags structure works for setting multiple flags, too.
Overrides:
Source:

setFlagsChangedCallback(callback, userInfoopt)

set function to call when flags change, e.g. when element is highlighted callback is called with (oldflags, userInfo) args (and using element as 'this')
Parameters:
Name Type Attributes Description
callback function
userInfo * <optional>
Inherited From:
Source:

setFrame(frameWidth, frameColoropt, frameOutset)

Set the frame on this element
Parameters:
Name Type Attributes Description
frameWidth number how wide is the frame
frameColor Object <optional>
frameOutset ?
Inherited From:
Source:

setFrameWidth()

set frame width for all states
Source:

setStateColors()

same thing for base color
Source:

setStateFrameColors()

same thing for frame color
Source:

setStateFrameWidth()

and for frame width
Source:

setStateImages()

A very flexible way to set up images that match various possible button states. This will work for image buttons, bubble buttons, etc. This will add image info to any matching state, or create a new state if it needs to. We expect to be passed in an array of state+resource settings, like this: [ {state: rat.ui.Element.enabledFlag, resource: "normal.png"}, {state: rat.ui.Element.enabledFlag | rat.ui.Element.highlightedFlag, resource: "high.png"}, {state: rat.ui.Element.enabledFlag | rat.ui.Element.toggledFlag | rat.ui.Element.highlightedFlag, resource: "toggled_and_highlighted.png"}, ] Alternatively, provide in an imageRef directly, instead of a resource, and we'll use that. Or, set imageRef to null explicitly, if you want us to NOT draw an image in that state. Use "doUpdate" flag to control whether or not images are automatically updated by this button on each frame. This is useful, for instance, if you want to use the same image in multiple states, but only want it to be updated once. By default, doUpdate is set to true for state images, so all images update at the same time, which is nice for keeping state image animations in sync. If you want to NOT update each image, e.g. if you're reusing the same imageref, then be sure to set doUpdate to false in the data you pass in, e.g. { state: rat.ui.Element.enabledFlag, imageRef : myImage, doUpdate : false}, Or, alternatively, use multiple imagerefs, which is kinda what they're for. They're supposed to be lightweight. (which might be an argument for removing this "doUpdate" flag stuff entirely anyway)
Source:

setStateTextColors()

A very flexible way to set up text color states that match various possible button states. This will add text color info to any matching state, or create a new state if it needs to. We expect to be passed in an array of state+color pairs, like this: [ {state: rat.ui.Element.enabledFlag, textColor: rat.graphics.white}, {state: rat.ui.Element.enabledFlag | rat.ui.Element.highlightedFlag, textColor: new rat.graphics.Color(10,200,150)}, {state: rat.ui.Element.enabledFlag | rat.ui.Element.toggledFlag | rat.ui.Element.highlightedFlag | , textColor: rat.graphics.gray}, ]
Source:

setTextColors()

set text colors for this button This is the easy comfortable version, where you specify common colors. For more control, see setStateTextColors All args but the first are optional
Source:

setToolTip(toolTip, screen, placement, offsetopt, fromMouseopt)

Set this element as our current tooltip. could be anything - textbox, image, whatever. For an easier text-only function, use setTextToolTip
Parameters:
Name Type Attributes Description
toolTip Object
screen Object
placement string
offset Object <optional>
fromMouse boolean <optional>
Inherited From:
Source:

setupButton(resourceopt, resourceHiopt, resourcePressedopt, resourceDisabledopt, extra1opt, extra2opt)

Parameters:
Name Type Attributes Description
resource string <optional>
resourceHi string <optional>
resourcePressed string <optional>
resourceDisabled string <optional>
extra1 Object <optional>
(optional - used for external image formats (see makeImage))
extra2 boolean <optional>
(optional - used for external image formats (see makeImage))
Source: