Skip to content

Commit

Permalink
[fix][cleanup] Use std::unique_ptr for TextField, and so fix memo…
Browse files Browse the repository at this point in the history
…ryleak.
  • Loading branch information
Jarod42 committed Oct 15, 2024
1 parent 9e3b776 commit 5715219
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion include/guisan/widgets/textfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "guisan/platform.hpp"
#include "guisan/widget.hpp"

#include <memory>
#include <string>

namespace gcn
Expand Down Expand Up @@ -90,6 +91,11 @@ namespace gcn
*/
TextField(const std::string& text);

/**
* Destructor.
*/
~TextField() override;

/**
* Sets the text of the text field.
*
Expand Down Expand Up @@ -190,7 +196,7 @@ namespace gcn
/**
* Holds the text of the text field.
*/
Text* mText = nullptr;
std::unique_ptr<Text> mText;

/**
* Holds the amount scrolled in x. If a user types more characters than
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/textfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

namespace gcn
{
TextField::TextField() : mText(new Text())
TextField::TextField() : mText(std::make_unique<Text>())
{
setFocusable(true);

Expand All @@ -78,7 +78,7 @@ namespace gcn
adjustHeight();
}

TextField::TextField(const std::string& text) : mText(new Text(text))
TextField::TextField(const std::string& text) : mText(std::make_unique<Text>(text))
{
setFocusable(true);

Expand All @@ -88,6 +88,8 @@ namespace gcn
adjustSize();
}

TextField::~TextField() = default;

void TextField::setText(const std::string& text)
{
mText->setRow(0, text);
Expand Down

0 comments on commit 5715219

Please sign in to comment.