Skip to content

Commit 1d367b0

Browse files
Fixed crash by adding nullptr checks.
1 parent 3d49d76 commit 1d367b0

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

lib/gui/src/elements/Button.hpp

+45-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace gui::elements
1414
{
15+
/**
16+
* @todo Move source code to .cpp.
17+
*/
1518
class Button final : public ElementBase
1619
{
1720
public:
@@ -24,14 +27,50 @@ namespace gui::elements
2427
void setText(std::string text);
2528
void setIcon(storage::Path path);
2629

27-
void setBorderColor(color_t color){m_label->setBorderColor(color);}
28-
void setFontSize(uint16_t r){m_label->setFontSize(r);}
30+
void setBorderColor(color_t color) {
31+
if (m_label == nullptr) {
32+
return;
33+
}
34+
35+
m_label->setBorderColor(color);
36+
}
37+
void setFontSize(uint16_t r) {
38+
if (m_label == nullptr) {
39+
return;
40+
}
41+
42+
m_label->setFontSize(r);
43+
}
2944

30-
void setBackgroundColor(color_t color){ m_label->setBackgroundColor(color);}
45+
void setBackgroundColor(color_t color) {
46+
if (m_label == nullptr) {
47+
return;
48+
}
49+
50+
m_label->setBackgroundColor(color);
51+
}
52+
53+
void setVerticalAlignment(Label::Alignement alignment) {
54+
if (m_label == nullptr) {
55+
return;
56+
}
57+
58+
m_label->setVerticalAlignment(alignment);
59+
}
60+
void setHorizontalAlignment(Label::Alignement alignment) {
61+
if (m_label == nullptr) {
62+
return;
63+
}
64+
65+
m_label->setHorizontalAlignment(alignment);
66+
}
67+
void setTextColor(color_t color) {
68+
if (m_label == nullptr) {
69+
return;
70+
}
3171

32-
void setVerticalAlignment(Label::Alignement alignment){ m_label->setVerticalAlignment(alignment); }
33-
void setHorizontalAlignment(Label::Alignement alignment){ m_label->setHorizontalAlignment(alignment); }
34-
void setTextColor(color_t color){ m_label->setTextColor(color); }
72+
m_label->setTextColor(color);
73+
}
3574

3675

3776
std::string getText();

0 commit comments

Comments
 (0)