Removes JSON constructor from UI elements

This fixes the error: clang:optin.cplusplus.VirtualCall
When virtual methods are called during construction and destruction the polymorphism is restricted to the class that’s being constructed or destructed because the more derived contexts are either not yet initialized or already destructed.
This commit is contained in:
2026-02-14 14:32:16 +01:00
parent f58028a8a9
commit 2a76e13305
31 changed files with 38 additions and 61 deletions
+2 -1
View File
@@ -5,7 +5,8 @@ TEST(UI_button, to_from_json)
{
UI_button button("button_text", Color(255, 255, 255), Color(0, 0, 0), nullptr);
json j = button.to_json(0);
UI_button button2(j);
UI_button button2;
button2.from_json(j);
EXPECT_EQ(button.text(), button2.text());
EXPECT_EQ(button.fg_color(), button2.fg_color());
EXPECT_EQ(button.bg_color(), button2.bg_color());
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_checkbox, to_from_json)
{
UI_checkbox checkbox("checkbox_text", Color(255, 255, 255), Color(0, 0, 0));
json j = checkbox.to_json(0);
UI_checkbox checkbox2(j);
UI_checkbox checkbox2;
checkbox2.from_json(j);
EXPECT_EQ(checkbox.text(), checkbox2.text());
EXPECT_EQ(checkbox.fg_color(), checkbox2.fg_color());
EXPECT_EQ(checkbox.bg_color(), checkbox2.bg_color());
+8 -7
View File
@@ -2,11 +2,12 @@
TEST(UI_combobox, to_from_json)
{
UI_combobox checkbox(Color(255, 255, 255), Color(0, 0, 0), {"option1", "option2"});
json j = checkbox.to_json(0);
UI_combobox checkbox2(j);
EXPECT_EQ(checkbox.text(), checkbox2.text());
EXPECT_EQ(checkbox.fg_color(), checkbox2.fg_color());
EXPECT_EQ(checkbox.bg_color(), checkbox2.bg_color());
EXPECT_EQ(checkbox.selected(), checkbox2.selected());
UI_combobox combobox(Color(255, 255, 255), Color(0, 0, 0), {"option1", "option2"});
json j = combobox.to_json(0);
UI_combobox combobox2;
combobox2.from_json(j);
EXPECT_EQ(combobox.text(), combobox2.text());
EXPECT_EQ(combobox.fg_color(), combobox2.fg_color());
EXPECT_EQ(combobox.bg_color(), combobox2.bg_color());
EXPECT_EQ(combobox.selected(), combobox2.selected());
}
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_dial, to_from_json)
{
UI_dial dial("slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50);
json j = dial.to_json(0);
UI_dial dial2(j);
UI_dial dial2;
dial2.from_json(j);
EXPECT_EQ(dial.text(), dial2.text());
EXPECT_EQ(dial.fg_color(), dial2.fg_color());
EXPECT_EQ(dial.bg_color(), dial2.bg_color());
+2 -1
View File
@@ -10,7 +10,8 @@ TEST(UI_label, to_from_json)
EXPECT_EQ(j["fg_color"], "#000000FF");
EXPECT_EQ(j["bg_color"], "#FFFFFFFF");
UI_label label2(j);
UI_label label2;
label2.from_json(j);
EXPECT_EQ(label2.text(), "label_text");
EXPECT_EQ(label2.fg_color(), Color(0, 0, 0));
EXPECT_EQ(label2.bg_color(), Color(255, 255, 255));
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_led, to_from_json)
{
UI_led led("led_text", Color(0, 0, 0), Color(255, 255, 255));
json j = led.to_json(0);
UI_led led2(j);
UI_led led2;
led2.from_json(j);
EXPECT_EQ(led.text(), led2.text());
EXPECT_EQ(led.fg_color(), led2.fg_color());
EXPECT_EQ(led.bg_color(), led2.bg_color());
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_slider, to_from_json)
{
UI_slider slider("slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50, nullptr);
json j = slider.to_json(0);
UI_slider slider2(j);
UI_slider slider2;
slider2.from_json(j);
EXPECT_EQ(slider.text(), slider2.text());
EXPECT_EQ(slider.fg_color(), slider2.fg_color());
EXPECT_EQ(slider.bg_color(), slider2.bg_color());
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_textbox, to_from_json)
{
UI_textbox textbox("hint", Color(0, 0, 0), Color(255, 255, 255));
json j = textbox.to_json(0);
UI_textbox textbox2(j);
UI_textbox textbox2;
textbox2.from_json(j);
EXPECT_EQ(textbox.text(), textbox2.text());
EXPECT_EQ(textbox.fg_color(), textbox2.fg_color());
EXPECT_EQ(textbox.bg_color(), textbox2.bg_color());
+2 -1
View File
@@ -4,7 +4,8 @@ TEST(UI_thermo, to_from_json)
{
UI_thermo thermo("thermo_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50);
json j = thermo.to_json(0);
UI_thermo thermo2(j);
UI_thermo thermo2;
thermo2.from_json(j);
EXPECT_EQ(thermo.text(), thermo2.text());
EXPECT_EQ(thermo.fg_color(), thermo2.fg_color());
EXPECT_EQ(thermo.bg_color(), thermo2.bg_color());