mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-19 17:39:50 -04:00
fix behaviour on empty label
This commit is contained in:
parent
f5f2a6450d
commit
b1fff19908
1 changed files with 18 additions and 7 deletions
|
@ -36,18 +36,23 @@ bool IconButtonSprite::init(
|
|||
void IconButtonSprite::updateLayout() {
|
||||
static constexpr float const PAD = 7.5f;
|
||||
|
||||
bool hasText = m_label->getString() && strlen(m_label->getString());
|
||||
|
||||
auto size = CCSize { 20.f, 20.f };
|
||||
if (m_label->getString() && strlen(m_label->getString())) {
|
||||
if (hasText) {
|
||||
m_label->limitLabelWidth(100.f, .6f, .1f);
|
||||
size.width += m_label->getScaledContentSize().width;
|
||||
if (m_icon) {
|
||||
size.width += PAD;
|
||||
}
|
||||
}
|
||||
if (m_icon) {
|
||||
limitNodeSize(m_icon, size, 1.f, .1f);
|
||||
limitNodeSize(m_icon, { 20, 20 }, 1.f, .1f);
|
||||
}
|
||||
size.height += 15.f;
|
||||
|
||||
if (m_icon) {
|
||||
size.width += m_icon->getScaledContentSize().width + PAD;
|
||||
size.width += m_icon->getScaledContentSize().width;
|
||||
}
|
||||
|
||||
this->setContentSize(size);
|
||||
|
@ -55,10 +60,16 @@ void IconButtonSprite::updateLayout() {
|
|||
m_bg->setPosition(m_obContentSize / 2);
|
||||
|
||||
if (m_icon) {
|
||||
m_label->setPosition(
|
||||
size.height / 2 + m_icon->getScaledContentSize().width / 2 + PAD, size.height / 2 + 1.f
|
||||
);
|
||||
m_icon->setPosition(size.height / 2, size.height / 2);
|
||||
if (hasText) {
|
||||
m_label->setPosition(
|
||||
size.height / 2 + m_icon->getScaledContentSize().width / 2 + PAD,
|
||||
size.height / 2 + 1.f
|
||||
);
|
||||
m_icon->setPosition(size.height / 2, size.height / 2);
|
||||
}
|
||||
else {
|
||||
m_icon->setPosition(size.width / 2, size.height / 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_label->setPosition(size.height / 2, size.height / 2);
|
||||
|
|
Loading…
Reference in a new issue