PuzzleSDK
LabelSystemFontTest类 参考

#include <LabelTestNew.h>

+ 类 LabelSystemFontTest 继承关系图:
+ LabelSystemFontTest 的协作图:

Public 成员函数

 CREATE_FUNC (LabelSystemFontTest)
 
 LabelSystemFontTest ()
 
void initToggleCheckboxes ()
 
void onChangedRadioButtonSelect (cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
- Public 成员函数 继承自 LabelLayoutBaseTest
 LabelLayoutBaseTest ()
 
void updateDrawNodeSize (const cocos2d::Size &drawNodeSize)
 
cocos2d::extension::ControlStepper * makeControlStepper ()
 
void valueChanged (cocos2d::Ref *sender, cocos2d::extension::Control::EventType controlEvent)
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
virtual void onEnter () override
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 成员函数 继承自 LabelLayoutBaseTest
void setAlignmentLeft (cocos2d::Ref *sender)
 
void setAlignmentCenter (cocos2d::Ref *sender)
 
void setAlignmentRight (cocos2d::Ref *sender)
 
void setAlignmentTop (cocos2d::Ref *sender)
 
void setAlignmentMiddle (cocos2d::Ref *sender)
 
void setAlignmentBottom (cocos2d::Ref *sender)
 
void initWrapOption (const cocos2d::Size &size)
 
void initToggleLabelTypeOption (const cocos2d::Size &size)
 
void initAlignmentOption (const cocos2d::Size &size)
 
void initFontSizeChange (const cocos2d::Size &size)
 
void initSliders (const cocos2d::Size &size)
 
void initTestLabel (const cocos2d::Size &size)
 
void initDrawNode (const cocos2d::Size &size)
 
- Protected 属性 继承自 LabelLayoutBaseTest
cocos2d::DrawNode * _drawNode
 
cocos2d::Label * _label
 
int _labelType
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 LabelTestNew.h788 行定义.

构造及析构函数说明

◆ LabelSystemFontTest()

LabelSystemFontTest::LabelSystemFontTest ( )

在文件 LabelTestNew.cpp2812 行定义.

2813{
2814 _label->setLineSpacing(5);
2815 _label->setVerticalAlignment(TextVAlignment::CENTER);
2816 _label->setOverflow(Label::Overflow::NONE);
2817 _label->setSystemFontName("Hiragino Sans GB");
2818 _label->setSystemFontSize(20);
2819 _label->enableOutline(Color4B::RED, 1.0);
2820 _label->setString("This is a very\n 我爱你中国\n long sentence");
2821 _labelType = 2;
2822
2823 auto stepper = (ControlStepper*)this->getChildByName("stepper");
2824 stepper->setEnabled(true);
2825
2826 auto checkbox = (CheckBox*)(this->getChildByName("toggleType"));
2827 checkbox->setEnabled(false);
2828
2829 this->updateDrawNodeSize(_label->getContentSize());
2830
2831 auto slider1 = (ui::Slider*)this->getChildByTag(1);
2832
2833 auto winSize = Director::getInstance()->getVisibleSize();
2834 slider1->addEventListener([=](Ref* ref, Slider::EventType event){
2835 float percent = slider1->getPercent();
2836 auto drawNodeSize = Size(percent / 100.0 * winSize.width,_label->getContentSize().height);
2837 if(drawNodeSize.height <= 0){
2838 drawNodeSize.height = 0.1f;
2839 }
2840 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2841 this->updateDrawNodeSize(drawNodeSize);
2842 });
2843
2844
2845 auto label = Label::createWithSystemFont("char Line break:", "Arial", 10);
2846 label->setColor(Color3B::WHITE);
2847 label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
2848 this->addChild(label);
2849
2850 CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
2851 "cocosui/check_box_normal_press.png",
2852 "cocosui/check_box_active.png",
2853 "cocosui/check_box_normal_disable.png",
2854 "cocosui/check_box_active_disable.png");
2855 checkBox->setPosition(Vec2(winSize.width * 0.2f , winSize.height * 0.8f));
2856 checkBox->setScale(0.5);
2857 checkBox->setSelected(false);
2858 checkBox->setName("LineBreak");
2859
2860 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2861 if (event == CheckBox::EventType::SELECTED) {
2862 _label->setLineBreakWithoutSpace(true);
2863 }else{
2864 _label->setLineBreakWithoutSpace(false);
2865 }
2866 this->updateDrawNodeSize(_label->getContentSize());
2867 });
2868 this->addChild(checkBox);
2869
2870 this->initToggleCheckboxes();
2871
2872 auto checkboxToggleWrap = (CheckBox*)(this->getChildByName("toggleWrap"));
2873 checkboxToggleWrap->setEnabled(true);
2874}
void updateDrawNodeSize(const cocos2d::Size &drawNodeSize)
cocos2d::Label * _label
Definition: LabelTestNew.h:705

引用了 LabelLayoutBaseTest::_label, LabelLayoutBaseTest::_labelType, initToggleCheckboxes() , 以及 LabelLayoutBaseTest::updateDrawNodeSize().

+ 函数调用图:

成员函数说明

◆ CREATE_FUNC()

LabelSystemFontTest::CREATE_FUNC ( LabelSystemFontTest  )

◆ initToggleCheckboxes()

void LabelSystemFontTest::initToggleCheckboxes ( )

在文件 LabelTestNew.cpp2876 行定义.

2877{
2878 const float BUTTON_WIDTH = 100;
2879 float startPosX = 0;
2880 Size winSize = Director::getInstance()->getVisibleSize();
2881
2882 // Create a radio button group
2883 auto radioButtonGroup = RadioButtonGroup::create();
2884 this->addChild(radioButtonGroup);
2885
2886 // Create the radio buttons
2887 static const int NUMBER_OF_BUTTONS = 4;
2888 startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1 ) * 0.5 * BUTTON_WIDTH - 30;
2889 std::vector<std::string> labelTypes = {"Normal", "Clamp", "Shrink", "RESIZE"};
2890
2891 for(int i = 0; i < NUMBER_OF_BUTTONS; ++i)
2892 {
2893
2894 RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");
2895 float posX = startPosX + BUTTON_WIDTH * i;
2896 radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
2897 radioButton->setScale(1.2f);
2898 radioButton->addEventListener(CC_CALLBACK_2(LabelSystemFontTest::onChangedRadioButtonSelect, this));
2899 radioButton->setTag(i);
2900 radioButtonGroup->addRadioButton(radioButton);
2901 this->addChild(radioButton);
2902
2903 auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20);
2904 label->setPosition(radioButton->getPosition() + Vec2(50.0f,0.0f));
2905 this->addChild(label);
2906 }
2907}
static float startPosX
static const float BUTTON_WIDTH
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)

引用了 BUTTON_WIDTH, onChangedRadioButtonSelect() , 以及 startPosX.

被这些函数引用 LabelSystemFontTest().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onChangedRadioButtonSelect()

void LabelSystemFontTest::onChangedRadioButtonSelect ( cocos2d::ui::RadioButton *  radioButton,
cocos2d::ui::RadioButton::EventType  type 
)

在文件 LabelTestNew.cpp2920 行定义.

2921{
2922 if(radioButton == nullptr)
2923 {
2924 return;
2925 }
2926
2927 switch (type)
2928 {
2929 case RadioButton::EventType::SELECTED:
2930 {
2931 switch (radioButton->getTag()) {
2932 case 0:
2933 _label->setOverflow(Label::Overflow::NONE);
2934 break;
2935 case 1:
2936 _label->setOverflow(Label::Overflow::CLAMP);
2937 break;
2938 case 2:
2939 _label->setOverflow(Label::Overflow::SHRINK);
2940 break;
2941 case 3:
2942 _label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
2943 break;
2944 default:
2945 break;
2946 }
2947 break;
2948 }
2949 default:
2950 break;
2951 }
2952 this->updateDrawNodeSize(_label->getContentSize());
2953}

引用了 LabelLayoutBaseTest::_label , 以及 LabelLayoutBaseTest::updateDrawNodeSize().

被这些函数引用 initToggleCheckboxes().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ subtitle()

std::string LabelSystemFontTest::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 LabelTestNew.cpp2914 行定义.

2915{
2916 return "";
2917}

◆ title()

std::string LabelSystemFontTest::title ( ) const
overridevirtual

重载 TestCase .

在文件 LabelTestNew.cpp2909 行定义.

2910{
2911 return "System Font Test";
2912}

该类的文档由以下文件生成: