From 61df7bc827230f6168afc6de28bf05f5d9d8ce16 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Thu, 2 Jul 2015 15:20:06 +0900 Subject: [PATCH] Add class documentation --- cocos/ui/UIRadioButton.cpp | 16 +++++----- cocos/ui/UIRadioButton.h | 63 +++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/cocos/ui/UIRadioButton.cpp b/cocos/ui/UIRadioButton.cpp index 75d4406428..fa46cfc133 100644 --- a/cocos/ui/UIRadioButton.cpp +++ b/cocos/ui/UIRadioButton.cpp @@ -188,8 +188,8 @@ void RadioButtonGroup::addRadioButton(RadioButton* radioButton) { if(radioButton != nullptr) { - CCASSERT(!radioButton->_group, "It already belongs to a group!"); - radioButton->_group = this; + CCASSERT(!radioButton->_group, "It already belongs to a group!"); + radioButton->_group = this; _radioButtons.pushBack(radioButton); if(!_allowedNoSelection && _selectedRadioButton == nullptr) @@ -270,12 +270,12 @@ void RadioButtonGroup::setSelectedButton(RadioButton* radioButton) { return; } - if(!_radioButtons.contains(radioButton)) - { - CCLOGERROR("The radio button does not belong to this group!"); - return; - } - + if(!_radioButtons.contains(radioButton)) + { + CCLOGERROR("The radio button does not belong to this group!"); + return; + } + deselect(); _selectedRadioButton = radioButton; if(_selectedRadioButton != nullptr) diff --git a/cocos/ui/UIRadioButton.h b/cocos/ui/UIRadioButton.h index 0712f0be21..2e51820851 100644 --- a/cocos/ui/UIRadioButton.h +++ b/cocos/ui/UIRadioButton.h @@ -38,6 +38,10 @@ namespace ui { class RadioButtonGroup; +/** + * RadioButton is a specific type of two-states button that is similar to CheckBox. + * Additionally, it can be used together with RadioButtonGroup to interact with other radio buttons. + */ class CC_GUI_DLL RadioButton : public AbstractCheckButton { @@ -126,12 +130,16 @@ protected: virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; - + ccRadioButtonCallback _radioButtonEventCallback; RadioButtonGroup* _group; }; +/** + * RadioButtonGroup groups designated radio buttons to make them interact to each other. + * In one RadioButtonGroup, only one or no RadioButton can be checked. + */ class CC_GUI_DLL RadioButtonGroup : public Widget { friend class RadioButton; @@ -175,18 +183,71 @@ public: */ void addEventListener(const ccRadioButtonGroupCallback& callback); + /** + * Get the index of selected radio button. + * + * @return the selected button's index. Returns -1 if no button is selected. + */ virtual int getSelectedButtonIndex() const; + /** + * Select a radio button by index. + * + * @param index of the radio button + */ virtual void setSelectedButton(int index); + + /** + * Select a radio button by instance. + * + * @param radio button instance + */ virtual void setSelectedButton(RadioButton* radioButton); + /** + * Add a radio button into this group. + * + * @param radio button instance + */ virtual void addRadioButton(RadioButton* radioButton); + + /** + * Remove a radio button from this group. + * + * @param radio button instance + */ virtual void removeRadioButton(RadioButton* radioButton); + /** + * Get the number of radio buttons in this group. + * + * @return the number of radio buttons in this group + */ ssize_t getNumberOfRadioButtons() const; + + /** + * Get a radio button in this group by index. + * + * @param index of the radio button + * @return radio button instance. Returns nullptr if out of index. + */ RadioButton* getRadioButtonByIndex(int index) const; + /** + * Set a flag for allowing no-selection feature. + * If it is allowed, no radio button can be selected. + * If it is not allowed, one radio button must be selected all time except it is empty. + * Default is not allowed. + * + * @param true means allowing no-selection, false means disallowing no-selection. + */ void setAllowedNoSelection(bool allowedNoSelection); + + /** + * Query whether no-selection is allowed or not. + * + * @param true means no-selection is allowed, false means no-selection is not allowed. + */ bool isAllowedNoSelection() const; virtual std::string getDescription() const override;