Cocos Code research (UI) Widget learning Notes

Source: Internet
Author: User

Theoretical basis

The base class for the Widget class, all UI controls. This class inherits from Protectednode and Layoutparameterprotocol. If you want to implement your own UI control, you should inherit this class.

by Videoplayer, WebView, Abstractcheckbutton, Button, EditBox, ImageView, Layout, Loadingbar, Radiobuttongroup, RichText, Slider, Text, Textatlas, Textbmfont, and TextField inheritance.

Code Part public Property

Enum Focusdirection
The control focus direction.

Enum PositionType
The type of control location in the layout system.

Enum SizeType
The size type of the control in the layout system.

Enum Toucheventtype
Touch Event type.

Enum Texturerestype
The texture resource type. More...

Enum Brightstyle
The Highlight property of the control.

typedef std::function< VOID (REF *, widget::toucheventtype) > Ccwidgettouchcallback
Controls Touch event callbacks.

typedef std::function< VOID (REF *) > Ccwidgetclickcallback
Control Click event Callback.

typedef std::function< VOID (REF *, int) > Ccwidgeteventcallback
Controls user-customized event callbacks. It is primarily used in conjunction with Cocos Studio.

Public method

Static Widget * Create ()
Creates and returns a pointer to an empty control instance.

Widget (void)
Default constructor

Virtual ~widget ()
Default destructor

Widget * Clone ()
Creates a new copy of the control.

void Setactiontag (int tag)
Sets the label for the action.

int Getactiontag () const
Gets the action label.

Whether to enable related
virtual void setenabled (bool enabled)
Set whether the control is enabled

BOOL IsEnabled () const
Checks whether the control is enabled.

With the highlight.
void Setbright (bool bright)
Sets whether the control is highlighted, the default value is True, and if set to false, the control's appearance is dark.

BOOL Isbright () const
Returns whether the control is highlighted

BOOL IsHighlighted () const
Gets whether the highlight is displayed

void Setbrightstyle (Brightstyle style)
Sets the highlight style of the control.

void sethighlighted (bool hilight)
Set whether to highlight

In relation to the location
void Setpositionpercent (const VEC2 &percent)
Sets the percentage position of the control in the OpenGL coordinate system (x, Y)

Const VEC2 & Getpositionpercent ()
Gets the percentage position of the control in the OpenGL coordinate system (x, Y)

void Setpositiontype (PositionType type)
Set the position type of the control

PositionType Getpositiontype () const
Gets the location type of the control

Const VEC2 & Gettouchstartpos () const
Gets the start position of the contact when the control is selected.

Const VEC2 & gettouchbeganposition () const
Gets the start position of the contact when the control is selected.

Related to Size
virtual void setSize (const Size &size)
To set the size of a control

virtual void setcontentsize (const Size &contentsize) override
To set the size of a control

virtual void setsizepercent (const VEC2 &percent)
Set the percentage size of a control

void Setsizetype (SizeType type)
Change the size type of the control.

SizeType Getsizetype () const
Gets the size type of the control.

Const Size & GetSize () const
Get the dimensions of a control

Const Size & Getcustomsize () const
Gets the user-defined control dimensions.

Virtual Const Size & Getlayoutsize ()
Gets the size of the control.

Const VEC2 & Getsizepercent ()
Gets the percentage size of the control.

BOOL Isignorecontentadaptwithsize () const
Whether the query ignores user-defined control dimensions.

Have focus on
BOOL IsFocused () const
Whether the query control has focus.

void setfocused (bool focus)
Toggles whether the control has focus.

BOOL Isfocusenabled () const
Whether the query control has focus.

void setfocusenabled (bool enable)
Allows the control to accept focus.

void Requestfocus ()
When this method is called, the control immediately has the focus.

Widget * Getcurrentfocusedwidget (bool iswidget)
Gets the control that currently has focus. This method, regardless of which control object is called, returns the control that currently has focus.

Widget * Getcurrentfocusedwidget () const
Gets the control that currently has focus. This method, regardless of which control object is called, returns the control that currently has focus.

Related to control rollover
virtual void Setflippedx (bool flippedx)
Sets whether the control should be flipped horizontally.

virtual bool Isflippedx () const
Returns whether the control is flipped horizontally.

virtual void Setflippedy (bool flippedy)
Sets whether the control should be flipped vertically.

virtual bool Isflippedy () const
Returns whether the control is flipped vertically.

Related to scaling
virtual void Setscalex (float ScaleX) override
Sets the scale (x) of the node.

virtual void Setscaley (float ScaleY) override
Sets the scaling (y) of the node.

virtual void Setscale (float scale) override
Sets the scaling of the nodes (x, Y, z).

virtual void Setscale (float scalex, float ScaleY) override
Sets the scaling of the node (x, y).

Virtual float Getscalex () const override
Returns the scaling factor for the x-axis of the node.

Virtual float Getscaley () const override
Returns the scaling factor for the y-axis of the node.

Virtual float Getscale () const override
Gets the scaling factor for the node when the x-axis and y-axis have the same scaling factor.

Related to touch events
BOOL Istouchenabled () const
Gets whether touch is enabled

virtual void settouchenabled (bool enabled)
Sets whether to respond to touch events.

void Addtoucheventlistener (Ref *target, sel_touchevent selector)
Setting response selectors and targets for touch events

void Addtoucheventlistener (const ccwidgettouchcallback &callback)
Sets the callback function for the touch event.

void Setpropagatetouchevents (bool ispropagate)
Allows the control's touch events to propagate up to the parent node, and set to false to prevent upward propagation.

BOOL Ispropagatetouchevents () const
Returns whether the control allows touch events to propagate to its parent node

void Setswallowtouches (bool swallow)
Sets whether the control devours touch events.

BOOL Isswallowtouches () const
Queries whether the control devours touch events.

virtual bool Ontouchbegan (Touch *touch, Event *unusedevent)
The callback function at the beginning of the touch event.

virtual void ontouchmoved (Touch *touch, Event *unusedevent)
A callback function that touches the touch in an event.

virtual void ontouchended (Touch *touch, Event *unusedevent)
The callback function at the end of the touch event.

virtual void ontouchcancelled (Touch *touch, Event *unusedevent)
The callback function when the touch event is canceled.

Related to click events
void Addclickeventlistener (const ccwidgetclickcallback &callback)
Sets a callback function for a click event.

virtual void Addccseventlistener (const ccwidgeteventcallback &callback)
Sets a callback function for Cocos Studio event handling.

Related to node parent-child
BOOL Clippingparentareacontainpoint (const VEC2 &PT)
Checks whether a location point is within the parent node area.

virtual void visit (cocos2d::renderer *renderer, const MAT4 &parenttransform, uint32_t parentflags) override
Iterates through all child nodes, and loops recursively to send their rendering instructions.

Float getleftinparent ()
Gets the position of the left edge of this control in the parent node coordinate system.

float getleftboundary () const
Gets the position of the left edge of this control in the parent node coordinate system.

Float getbottominparent ()
Gets the position of the bottom boundary of this control in the parent node coordinate system.

float getbottomboundary () const
Gets the position of the bottom boundary of this control in the parent node coordinate system.

Float getrightinparent ()
Gets the position of the right boundary of this control in the parent node coordinate system.

float getrightboundary () const
Gets the position of the right boundary of this control in the parent node coordinate system.

Float gettopinparent ()
Gets the position of the top boundary of this control in the parent node coordinate system.

float gettopboundary () const
Gets the position of the top boundary of this control in the parent node coordinate system.

virtual bool HitTest (const VEC2 &pt, const Camera *camera, VEC3 *p) const
Checks whether a point is in the content space of the control. This function is the touch response area used to detect the control.

void Setlayoutparameter (Layoutparameter *parameter)
Sets a layout parameter (layoutparameter) for the control.

Layoutparameter * Getlayoutparameter () const override
Gets the layout parameters (Layoutparameter) of the control.

Layoutparameter * Getlayoutparameter (Layoutparameter::type Type)
Gets the layout parameters (Layoutparameter) of the control based on the type.

virtual void ignorecontentadaptwithsize (bool ignore)
Sets whether to ignore user-defined control dimensions set by Setcontentsize. Set to true ignores user-defined dimensions, meaning that the control dimension is always equal to the return value of Getvirtualrenderersize.

VEC2 getworldposition () const
Gets the position of the control in the world space.

Virtual Node * Getvirtualrenderer ()
The internal render node of the control. For example, a button's virtual render node is its texture node.

Virtual Size getvirtualrenderersize () const
Gets the size of the virtual render node.

Virtual std::string getdescription () const override
Returns a description of the control class.

void Updatesizeandposition ()
Updates the dimensions and positions of all child nodes recursively.

void Updatesizeandposition (const Size &parentsize)
Updates the dimensions and positions of all child nodes recursively.

Virtual Widget * Findnextfocusedwidget (focusdirection direction, Widget *current)
When a control is in a layout, you can call this method to get the next control in the specified direction, and the direction is divided up and down. If the control is not in the layout, it returns itself

void setunifysizeenabled (bool enable)
Sets whether to use normalized dimensions.

BOOL Isunifysizeenabled () const
Query whether to use normalized dimensions.

void Setcallbackname (const std::string &callbackname)
Sets the name of the callback function.

Const std::string & Getcallbackname () const
The name of the query callback function.

void Setcallbacktype (const std::string &callbacktype)
Sets the callback function type.

Const std::string & Getcallbacktype () const
The query callback function type.

void setlayoutcomponentenabled (bool enable)
Sets whether the layout component is enabled.

BOOL Islayoutcomponentenabled () const
Queries whether the layout component is enabled.

Cocos Code research (UI) Widget learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.