Skip to content

Commit 43c1d44

Browse files
authored
Ensure custom button label is released correctly (#2446)
Ensure label is released correctly Minor code clean-up
1 parent a3e1c35 commit 43c1d44

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

core/ui/UIButton.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ namespace ax
3939
namespace ui
4040
{
4141

42-
static const int NORMAL_RENDERER_Z = (-2);
43-
static const int PRESSED_RENDERER_Z = (-2);
44-
static const int DISABLED_RENDERER_Z = (-2);
45-
static const int TITLE_RENDERER_Z = (-1);
46-
static const float ZOOM_ACTION_TIME_STEP = 0.05f;
42+
constexpr int NORMAL_RENDERER_Z = (-2);
43+
constexpr int PRESSED_RENDERER_Z = (-2);
44+
constexpr int DISABLED_RENDERER_Z = (-2);
45+
constexpr int TITLE_RENDERER_Z = (-1);
46+
constexpr float ZOOM_ACTION_TIME_STEP = 0.05f;
4747

4848
IMPLEMENT_CLASS_GUI_INFO(Button)
4949

@@ -68,18 +68,17 @@ Button::Button()
6868
, _normalTextureAdaptDirty(true)
6969
, _pressedTextureAdaptDirty(true)
7070
, _disabledTextureAdaptDirty(true)
71-
, _normalFileName("")
72-
, _clickedFileName("")
73-
, _disabledFileName("")
7471
, _normalTexType(TextureResType::LOCAL)
7572
, _pressedTexType(TextureResType::LOCAL)
7673
, _disabledTexType(TextureResType::LOCAL)
77-
, _fontName("")
7874
{
7975
setTouchEnabled(true);
8076
}
8177

82-
Button::~Button() {}
78+
Button::~Button()
79+
{
80+
AX_SAFE_RELEASE_NULL(_titleRenderer);
81+
}
8382

8483
Button* Button::create()
8584
{
@@ -161,7 +160,10 @@ bool Button::createTitleRendererIfNull()
161160

162161
void Button::createTitleRenderer()
163162
{
163+
AX_SAFE_RELEASE(_titleRenderer);
164164
_titleRenderer = Label::create();
165+
AX_SAFE_RETAIN(_titleRenderer);
166+
165167
_titleRenderer->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
166168
addProtectedChild(_titleRenderer, TITLE_RENDERER_Z, -1);
167169
}
@@ -722,7 +724,7 @@ void Button::setTitleAlignment(TextHAlignment hAlignment, TextVAlignment vAlignm
722724

723725
void Button::setTitleText(std::string_view text)
724726
{
725-
if (text.compare(getTitleText()) == 0)
727+
if (text == getTitleText())
726728
{
727729
return;
728730
}

0 commit comments

Comments
 (0)