Class ccui.Widget

Class Summary
Constructor Attributes Constructor Name and Description
 
Base class for ccui.Widget

Method Summary

Class Detail

ccui.Widget()
Base class for ccui.Widget

Field Detail

{Number} actionTag
- The action tag of the widget
{Boolean} bright
- Indicate whether the widget is bright
{Boolean} enabled
- Indicate whether the widget is enabled
{Boolean} focused
- Indicate whether the widget is focused
{Number} heightPercent
- Height in percentage of parent height
{String} name
- The name of the widget
onFocusChanged

When a widget lose/get focus, this method will be called. Be Caution when you provide your own version,
you must call widget.setFocused(true/false) to change the focus state of the current focused widget;

onNextFocusedWidget
use this function to manually specify the next focused widget regards to each direction
{ccui.Widget.SIZE_ABSOLUTE|ccui.Widget.SIZE_PERCENT} sizeType
- The size type of the widget
{Boolean} touchEnabled
- Indicate whether touch events are enabled
{Boolean} updateEnabled
- Indicate whether the update function is scheduled
{ccui.Widget} widgetParent
- <@readonly> The direct parent when it's a widget also, otherwise equals null
{ccui.Widget.TYPE_WIDGET|ccui.Widget.TYPE_CONTAINER} widgetType
- <@readonly> The type of the widget
{Number} widthPercent
- Width in percentage of parent width
{Number} xPercent
- Position x in percentage of width
{Number} yPercent
- Position y in percentage of height

Method Detail

  • addNode(node, zOrder, tag)
    add node for widget
    Parameters:
    {cc.Node} node
    {Number} zOrder
    {Number} tag
  • addTouchEventListener(selector, target)
    Sets the touch event target/selector of the menu item
    Parameters:
    {Function} selector
    {Object} target
  • checkChildInfo(handleState, sender, touchPoint)
    Sends the touch event to widget's parent
    Parameters:
    {number} handleState
    {ccui.Widget} sender
    {cc.Point} touchPoint
  • {Boolean} clippingParentAreaContainPoint(pt)
    Checks a point if in parent's area.
    Parameters:
    {cc.Point} pt
    Returns:
    {Boolean}
  • <static> {ccui.Widget} ccui.Widget.create()
    allocates and initializes a UIWidget.
    // example
    var uiWidget = ccui.Widget.create();
    Returns:
    {ccui.Widget}
  • didNotSelectSelf()
    A call back function when widget lost of focus.
  • dispatchFocusEvent(widgetLostFocus, widgetGetFocus)
    Dispatch a EventFocus through a EventDispatcher
    Parameters:
    {ccui.Widget} widgetLostFocus
    {ccui.Widget} widgetGetFocus
  • enableDpadNavigation(enable)
    call this method with parameter true to enable the Android Dpad focus navigation feature
    Parameters:
    {Boolean} enable
    set true to enable dpad focus navigation, otherwise disable dpad focus navigation
  • findNextFocusedWidget(direction, current)

    When a widget is in a layout, you could call this method to get the next focused widget within a specified direction.
    If the widget is not in a layout, it will return itself

    Parameters:
    direction
    the direction to look for the next focused widget in a layout
    current
    the current focused widget
    Returns:
    the next focused widget in a layout
  • {number} getBottomBoundary()
    Gets the bottom boundary position of this widget.
    Returns:
    {number}
  • {cc.Color} getColor()
    Get color
    Returns:
    {cc.Color}
  • {cc.Size} getContentSize()
    Gets the content size of widget.
    Returns:
    {cc.Size}
  • getCurrentFocusedWidget()
    no matter what widget object you call this method on , it will return you the exact one focused widget
  • {cc.Size} getCustomSize()
    Get custom size of widget
    Returns:
    {cc.Size}
  • {string} getDescription()
    Returns the "class name" of widget.
    Returns:
    {string}
  • {ccui.LayoutParameter} getLayoutParameter(type)
    Gets layout parameter
    Parameters:
    {ccui.LayoutParameter.NONE|ccui.LayoutParameter.LINEAR|ccui.LayoutParameter.RELATIVE} type
    Returns:
    {ccui.LayoutParameter}
  • {number} getLeftBoundary()
    Gets the left boundary position of this widget.
    Returns:
    {number}
  • {string} getName()
    Gets the name of widget
    Returns:
    {string}
  • {cc.Node} getNodeByTag(tag)
    get node by tag
    Parameters:
    {Number} tag
    Returns:
    {cc.Node}
  • {Array} getNodes()
    get all node
    Returns:
    {Array}
  • {Number} getOpacity()
    Get opacity
    Returns:
    {Number}
  • {cc.Point} getPositionPercent()
    Gets the percent (x,y) of the widget
    Returns:
    {cc.Point} The percent (x,y) of the widget in OpenGL coordinates
  • {Number} getPositionType()
    Gets the position type of the widget
    Returns:
    {Number} the position type of widget
  • {number} getRightBoundary()
    Gets the right boundary position of this widget.
    Returns:
    {number}
  • {cc.Size} getSize()
    Returns size of widget
    Returns:
    {cc.Size}
  • {cc.Point} getSizePercent()
    Returns size percent of widget
    Returns:
    {cc.Point}
  • {ccui.Widget.SIZE_ABSOLUTE|ccui.Widget.SIZE_PERCENT} getSizeType()
    Gets the size type of widget.
    Returns:
    {ccui.Widget.SIZE_ABSOLUTE|ccui.Widget.SIZE_PERCENT} that is widget's size type
  • {number} getTopBoundary()
    Gets the top boundary position of this widget.
    Returns:
    {number}
  • {cc.Point} getTouchEndPos()
    Gets the touch end point of widget when widget is selected.
    Returns:
    {cc.Point} the touch end point.
  • {cc.Point} getTouchMovePos()
    Gets the touch move point of widget when widget is selected.
    Returns:
    {cc.Point} the touch move point.
  • {cc.Point} getTouchStartPos()
    Gets the touch began point of widget when widget is selected.
    Returns:
    {cc.Point} the touch began point.
  • {ccui.Widget} getVirtualRenderer()
    Gets the Virtual Renderer of widget.
    Returns:
    {ccui.Widget}
  • getVirtualRendererSize()
    Gets the content size of widget. Content size is widget's texture size.
  • {ccui.Widget.TYPE_WIDGET|ccui.Widget.TYPE_CONTAINER} getWidgetType()
    get widget type
    Returns:
    {ccui.Widget.TYPE_WIDGET|ccui.Widget.TYPE_CONTAINER}
  • {cc.Point} getWorldPosition()
    Gets world position of widget.
    Returns:
    {cc.Point} world position of widget.
  • {boolean} hitTest(pt)
    Checks a point if is in widget's space
    Parameters:
    {cc.Point} pt
    Returns:
    {boolean} true if the point is in widget's space, false otherwise.
  • ignoreContentAdaptWithSize(ignore)
    Ignore the widget size
    Parameters:
    {Boolean} ignore
    true that widget will ignore it's size, use texture size, false otherwise. Default value is true.
  • {boolean} init()
    initializes state of widget.
    Returns:
    {boolean}
  • initRenderer()
    initializes renderer of widget.
  • interceptTouchEvent(eventType, sender, touch)
    Sends the touch event to widget's parent
    Parameters:
    {Number} eventType
    {ccui.Widget} sender
    {cc.Touch} touch
  • {boolean} isBright()
    Determines if the widget is bright
    Returns:
    {boolean} true if the widget is bright, false if the widget is dark.
  • {boolean} isEnabled()
    Determines if the widget is enabled
    Returns:
    {boolean}
  • {Boolean} isFlippedX()

    Returns the flag which indicates whether the widget is flipped horizontally or not.
    It only flips the texture of the widget, and not the texture of the widget's children.
    Also, flipping the texture doesn't alter the anchorPoint.
    If you want to flip the anchorPoint too, and/or to flip the children too use:
    widget.setScaleX(sprite.getScaleX() * -1);

    Returns:
    {Boolean} true if the widget is flipped horizontally, false otherwise.
  • {Boolean} isFlippedY()

    Return the flag which indicates whether the widget is flipped vertically or not.
    It only flips the texture of the widget, and not the texture of the widget's children.
    Also, flipping the texture doesn't alter the anchorPoint.
    If you want to flip the anchorPoint too, and/or to flip the children too use:
    widget.setScaleY(widget.getScaleY() * -1);

    Returns:
    {Boolean} true if the widget is flipped vertically, false otherwise.
  • {boolean} isFocused()
    Determines if the widget is on focused
    Returns:
    {boolean} whether the widget is focused or not
  • {boolean} isFocusEnabled()
    returns whether the widget could accept focus.
    Returns:
    {boolean} true represent the widget could accept focus, false represent the widget couldn't accept focus
  • {boolean} isHighlighted()
    Determines if the widget is highlighted
    Returns:
    {boolean} true if the widget is highlighted, false if the widget is not highlighted .
  • {boolean} isIgnoreContentAdaptWithSize()
    Gets the widget if is ignore it's size.
    Returns:
    {boolean} true that widget will ignore it's size, use texture size, false otherwise.
  • {boolean} isTouchEnabled()
    To set the bright style of widget.
    Returns:
    {boolean} true if the widget is touch enabled, false if the widget is touch disabled.
  • {boolean} isUpdateEnabled()
    is the "update" method scheduled.
    Returns:
    {boolean}
  • onFocusChange(widgetLostFocus, widgetGetFocus)
    This method is called when a focus change event happens
    Parameters:
    {ccui.Widget} widgetLostFocus
    {ccui.Widget} widgetGetFocus
  • onPressStateChangedToDisabled()
    call back function called widget's state changed to dark.
  • onPressStateChangedToNormal()
    call back function called widget's state changed to normal.
  • onPressStateChangedToPressed()
    call back function called widget's state changed to selected.
  • onSizeChanged()
    call back function called when size changed.
  • onTouchCancelled(touchPoint)
    A call back function called when widget is selected, and on touch canceled.
    Parameters:
    {cc.Point} touchPoint
  • onTouchLongClicked(touchPoint)
    A call back function called when widget is selected, and on touch long clicked.
    Parameters:
    {cc.Point} touchPoint
  • removeAllNodes()
    remove all node
  • removeNode(node, cleanup)
    remove node
    Parameters:
    {cc.Node} node
    {Boolean} cleanup
  • removeNodeByTag(tag, cleanup)
    remove node by tag
    Parameters:
    {Number} tag
    {Boolean} cleanup
  • requestFocus()
    when a widget calls this method, it will get focus immediately.
  • setBright(bright)
    Sets whether the widget is bright. The default value is true, a widget is default to bright
    Parameters:
    {Boolean} bright
    true if the widget is bright, false if the widget is dark.
  • setBrightStyle(style)
    To set the bright style of widget.
    Parameters:
    {Number} style
    BRIGHT_NORMAL the widget is normal state, BRIGHT_HIGHLIGHT the widget is height light state.
  • setEnabled(enabled)

    Sets whether the widget is enabled
    true if the widget is enabled, widget may be touched , false if the widget is disabled, widget cannot be touched.
    The default value is true, a widget is default to enabled

    Parameters:
    {Boolean} enabled
  • setFlippedX(flipX)
    Sets whether the widget should be flipped horizontally or not.
    Parameters:
    {Boolean} flipX
    true if the widget should be flipped horizontally, false otherwise.
  • setFlippedY(flipY)
    Sets whether the widget should be flipped vertically or not.
    Parameters:
    {Boolean} flipY
    true if the widget should be flipped vertically, false otherwise.
  • setFocused(focus)
    Sets whether the widget is on focused The default value is false, a widget is default to not on focused
    Parameters:
    {boolean} focus
    pass true to let the widget get focus or pass false to let the widget lose focus
  • setFocusEnabled(enable)
    sets whether the widget could accept focus.
    Parameters:
    {Boolean} enable
    true represent the widget could accept focus, false represent the widget couldn't accept focus
  • setHighlighted(highlight)
    Sets whether the widget is highlighted. The default value is false, a widget is default to not highlighted
    Parameters:
    highlight
    true if the widget is highlighted, false if the widget is not highlighted.
  • setLayoutParameter(parameter)
    Gets LayoutParameter of widget.
    Parameters:
    {ccui.LayoutParameter} parameter
  • setName(name)
    Sets the name of widget
    Parameters:
    {String} name
  • setOpacity(opacity)
    Set opacity
    Parameters:
    {Number} opacity
  • setPosition(pos, posY)
    Changes the position (x,y) of the widget . The original point (0,0) is at the left-bottom corner of screen.
    Parameters:
    {cc.Point||Number} pos
    {Number} posY Optional
  • setPositionPercent(percent)
    Changes the position (x,y) of the widget
    Parameters:
    {cc.Point} percent
  • setPositionType(type)
    Changes the position type of the widget
    Parameters:
    {Number} type
    the position type of widget
  • setSize(size)
    Changes the size that is widget's size
    Parameters:
    {cc.Size} size
    that is widget's size
  • setSizePercent(percent)
    Changes the percent that is widget's percent size
    Parameters:
    {cc.Point} percent
    that is widget's percent size
  • setSizeType(type)
    TEXTURE_RES_TYPE Changes the size type of widget.
    Parameters:
    {ccui.Widget.SIZE_ABSOLUTE|ccui.Widget.SIZE_PERCENT} type
    that is widget's size type
  • setTouchEnabled(enable)
    Sets whether the widget is touch enabled. The default value is false, a widget is default to touch disabled
    Parameters:
    {Boolean} enable
    true if the widget is touch enabled, false if the widget is touch disabled.
  • setUpdateEnabled(enable)
    Schedules the "update" method.
    Parameters:
    enable
  • updateSizeAndPosition(parentSize)
    update size and position
    Parameters:
    {cc.Size} parentSize Optional
    parent size