Cocos Code Research (+) widget sub-class Radiobuttongroup learning notes

Source: Internet
Author: User
Tags addchild

Theoretical basis

Radiobuttongroup can organize the specified radio buttons to form a group so that they interact with each other. In a radiobuttongroup, there is only one or no RadioButton can be in the selected state. Inherit from widget.

Code practices

Radiobuttongroup can organize the specified radio buttons to form a group so that they interact with each other. In a radiobuttongroup, there is only one or no RadioButton can be in the selected state. Inherit from widget.

Static Radiobuttongroup * Create ()
Creates and returns a Radiobuttongroup instance.

Add Delete radio button
virtual void AddRadioButton (RadioButton *radiobutton)
Add a radio button to this group.

virtual void Removeradiobutton (RadioButton *radiobutton)
Remove a radio button from this group.

virtual void removeallradiobuttons ()
Removes all radio buttons from this group.

ssize_t getnumberofradiobuttons () const
Gets the number of radio buttons within the group.

is related to the selected state
RadioButton * GETRADIOBUTTONBYINDEX (int index) const
In a group of radio buttons, select by index.

virtual int Getselectedbuttonindex () const
Gets the index of the selected radio button.

virtual void Setselectedbutton (int index)
A radio button is selected by setting the index.

virtual void Setselectedbutton (RadioButton *radiobutton)
A radio button is selected with the pointer set.

virtual void setselectedbuttonwithoutevent (int index)
Set the selected state by the radio button's index inside the group, but this method does not respond to event handling

virtual void setselectedbuttonwithoutevent (RadioButton *radiobutton)
The selected state is set by a pointer to a radio button, but this method does not respond to event handling

void AddEventListener (const ccradiobuttongroupcallback &callback)
Add a callback function that will be called when the radio button is selected or canceled.

void Setallowednoselection (bool allowednoselection)
Set a tag to allow the non-selected function to appear within the group. If it is allowed, you do not have to select the radio button. If it is not allowed, then every moment must select a radio button, except that it is empty. The default is not allowed.

BOOL Isallowednoselection () const
Whether a query allows a group to exist without a choice.

Instance:

        //Create a radio button groupradiobuttongroup* Radiobuttongroup =radiobuttongroup::create (); _uilayer-AddChild (Radiobuttongroup); //Create the radio buttons        Static Const intNumber_of_buttons =3; floatSTARTPOSX = widgetsize.width/2.0f-((Number_of_buttons-1) /2.0f) *Buttonwidth;  for(inti =0; i < number_of_buttons; ++i) {Auto Filepathnormal= Stringutils::format ("Cocosui/btn_exercise%02d_n.png", i +1); Auto filepathselected= Stringutils::format ("Cocosui/btn_exercise%02d_p.png", i +1); RadioButton* RadioButton =radiobutton::create (Filepathnormal, filepathselected); floatPosX = startposx + buttonwidth *i; RadioButton->setposition (VEC2 (PosX, Widgetsize.height/2.0f)); RadioButton-Setscale (Button_scale); RadioButton->setzoomscale (0.05f); Radiobuttongroup-AddRadioButton (RadioButton); _uilayer-AddChild (RadioButton); } Radiobuttongroup->setselectedbutton (0);

Cocos Code Research (+) widget sub-class Radiobuttongroup 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.