MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / init

Method init

Source/TextButton.cpp:45–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45bool TextButton::init(std::string_view text, std::string_view font, float width, float height, std::string_view bgTexture, std::function<void(TextButton*)> callback) {
46 if (!MenuItemSprite::initWithNormalSprite(nullptr, nullptr, nullptr, nullptr)) return false;
47
48 this->m_pText = Label::createWithBMFont(font, text);
49
50 this->m_pBG = ui::Scale9Sprite::create(bgTexture);
51 m_pBG->setStretchEnabled(true);
52
53 this->m_pBG->setContentSize({
54 (width == 0) ? this->m_pText->getContentSize().width + 16 : width,
55 (height == 0) ? this->m_pText->getContentSize().height + 4 : height
56 });
57 this->addChild(this->m_pBG);
58 this->m_pBG->setPosition(this->m_pBG->getContentSize() / 2);
59 this->m_pBG->addChild(this->m_pText);
60
61 this->m_pText->setPosition(this->m_pBG->getContentSize() / 2);
62 this->m_pText->setScale((this->m_pBG->getContentSize().width - 16) / this->m_pText->getContentSize().width);
63
64 this->setContentSize(this->m_pBG->getContentSize());
65
66 this->setNewScale(1.15f);
67
68 this->m_fCallback = callback;
69
70 this->m_fWidth = width;
71 this->m_fHeight = height;
72
73 return true;
74}
75
76
77// Getters and Setters

Callers 1

createMethod · 0.45

Calls 3

createFunction · 0.85
setPositionMethod · 0.80
setScaleMethod · 0.80

Tested by

no test coverage detected