Skip to content

UIElement

YinLijun edited this page Mar 3, 2015 · 1 revision

UIElement is the base class of all UI controls.

Any attributes.methods not listed here maybe changed in future, access them is at your own risk!


Attributes


  • x The x position of the element in its parent.

  • y The y position of the element in its parent.

  • w The width of the element.

  • h The height of the element.

  • type The type of the element. (readonly)

  • name The name of the element.

  • visible true if visible to user.

  • enable true if react to user input.

  • style The style of the element. See Style

  • scale The scale of the element.

  • rotation The rotation of the element.

  • opacity The opacity(alpha) of the element.

  • children The children of the element.

  • parentShape The parent of the element.

Methods


  • setText(text) Set the text content of the element.

  • getText() Get the text content of the element.

  • setV(x, y) Set linear velocity of element(only if is is body).

  • setPosition(x, y) set the position of the element.

  • setValue(value) Set the value of the element. For most elements, its value is its text content.

  • getValue() Get the value of the element.

  • setName(name) Set the name of the element. The name can be used to find an element by call the method findChildByName.

  • getName() Get the name of the element.

  • find(name, recursive) find a child by its name.

  • animate(config) animate the element.

    • config.duration
    • config.xStart
    • config.yStart
    • config.wStart
    • config.hStart
    • config.xEnd
    • config.yEnd
    • config.wEnd
    • config.hEnd
    • config.opacityStart
    • config.opacityEnd
    • config.rotationStart
    • config.rotationEnd
    • config.scaleStart
    • config.scaleEnd
    • config.onDone
  • postRedraw(rect) Request the system to redraw and update UI.

    • rect The rectangle that need to be updated.
  • addChild(child) Add an element into this element as a child.

    • child The element to add.
  • dupChild(name) duplicate a child.

    • name the name of the child.
  • removeChild(child) Remove an element from the children array.

    • child The element to remove.
  • getWindow() Get the window of current element. Generally, you need get the window, and then you can find other element in the window.

  • openWindow(name, onWindowClose, closeCurrent, initData) Open a new window.

    • name The name of new window.
    • onWindowClose Callback function, it will be called when new window closed.
    • closeCurrent If close current window before open new window.
    • initData The init data for new window, you can get it in the event onOpen/onBeforeOpen Event of window.

Example:

To open the window named "win-bonus" in the onClick event handler of a button.

this.openWindow("win-bonus", 
	function (retInfo) {console.log("window closed.");});
  • closeWindow(retInfo) Close current window.
    • retInfo The parameter will be passed to callback function of onWindowClose specified when openWindow.

Example:

To close current window in the onClick event handler of a button.

var retCode = 0;
this.closeWindow(retCode);

Events


Clone this wiki locally