Move to more memory safe implementation of widget holding
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "../json.hpp"
|
||||
#include <memory>
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ void WidgetRect::draw()
|
||||
}
|
||||
}
|
||||
|
||||
Widget* WidgetRect::builder(const nlohmann::json& j)
|
||||
std::unique_ptr<Widget> WidgetRect::builder(const nlohmann::json& j)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
@@ -115,7 +115,7 @@ Widget* WidgetRect::builder(const nlohmann::json& j)
|
||||
json_extract(j, "stroke", stroke_size);
|
||||
json_extract(j, "color", color);
|
||||
|
||||
return new WidgetRect(x, y, width, height, radius, stroke_size, color);
|
||||
return std::make_unique<WidgetRect>(x, y, width, height, radius, stroke_size, color);
|
||||
}
|
||||
|
||||
void WidgetRect::draw_circle_corner(int x, int y, int quadrant)
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
virtual void draw() override;
|
||||
|
||||
static Widget* builder(const nlohmann::json& j);
|
||||
static std::unique_ptr<Widget> builder(const nlohmann::json& j);
|
||||
|
||||
private:
|
||||
// x, y - center of circle
|
||||
|
||||
@@ -262,7 +262,7 @@ void WidgetText::draw()
|
||||
SDL_FreeSurface(txt_surface);
|
||||
}
|
||||
|
||||
Widget* WidgetText::builder(const nlohmann::json& j)
|
||||
std::unique_ptr<Widget> WidgetText::builder(const nlohmann::json& j)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
@@ -299,7 +299,7 @@ Widget* WidgetText::builder(const nlohmann::json& j)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new WidgetText(x, y, width, height,
|
||||
return std::make_unique<WidgetText>(x, y, width, height,
|
||||
text, fit, should_wrap,
|
||||
halign, valign,
|
||||
halign_via_visible, valign_via_visible,
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
virtual void draw() override;
|
||||
|
||||
static Widget* builder(const nlohmann::json& j);
|
||||
static std::unique_ptr<Widget> builder(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
#endif // WIDGET_TEXT_H_
|
||||
|
||||
Reference in New Issue
Block a user