Cache SetText

Apparently, gtk_button_set_label is very expensive to do. Now it is
only called when necessary.

This is the culprit for the mysterious high CPU usage and not the Hyprland
IPC as said in https://github.com/scorpion-26/gBar/issues/7 and https://github.com/scorpion-26/gBar/issues/8.
This commit is contained in:
scorpion-26 2023-03-03 17:02:59 +01:00
parent 6d3f1b64f4
commit 660e690195

View file

@ -524,11 +524,11 @@ void Button::Create()
void Button::SetText(const std::string& text) void Button::SetText(const std::string& text)
{ {
m_Text = text; if (m_Widget && text != m_Text)
if (m_Widget)
{ {
gtk_button_set_label((GtkButton*)m_Widget, m_Text.c_str()); gtk_button_set_label((GtkButton*)m_Widget, m_Text.c_str());
} }
m_Text = text;
} }
void Button::OnClick(Callback<Button>&& callback) void Button::OnClick(Callback<Button>&& callback)