Skip to content

Commit

Permalink
[example] Add ImageTextButton in widgets_example
Browse files Browse the repository at this point in the history
Fix `ImageTextButton`
  • Loading branch information
Jarod42 committed Sep 29, 2024
1 parent e3cb1e7 commit 9565056
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 43 deletions.
12 changes: 11 additions & 1 deletion examples/widgets_example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ namespace WidgetsExample
imageButton->setSize(220, 90);
imageButton->addActionListener(this);

imageTextButton = std::make_unique<gcn::ImageTextButton>("guisan-logo.png", "Change color");
imageTextButton->setSize(220, 100);
imageTextButton->setAlignment(gcn::ImageTextButton::TOP);
imageTextButton->addActionListener(this);

imageButton->setSize(220, 90);
imageButton->addActionListener(this);
inputBox = std::make_unique<gcn::InputBox>("Change name", " Set name of label ");

inputBox->setVisible(false);
Expand Down Expand Up @@ -141,6 +148,7 @@ namespace WidgetsExample
top->add(icon.get(), 10, 10);
top->add(button.get(), 325, 10);
top->add(imageButton.get(), 10, 290);
top->add(imageTextButton.get(), 10, 380);
top->add(textField.get(), 375, 10);
top->add(textBoxScrollArea.get(), 290, 50);
top->add(inputBox.get(), 270, 180);
Expand Down Expand Up @@ -170,7 +178,8 @@ namespace WidgetsExample
inputBox->setVisible(true);
top->moveToTop(inputBox.get());
}
else if (actionEvent.getSource() == imageButton.get())
else if (actionEvent.getSource() == imageButton.get()
|| actionEvent.getSource() == imageTextButton.get())
{
const gcn::Color colours[] = {gcn::Color(212, 255, 150, 190),
gcn::Color(212, 0, 0, 190),
Expand Down Expand Up @@ -216,6 +225,7 @@ namespace WidgetsExample
std::unique_ptr<gcn::Icon> icon; // An icon (image)
std::unique_ptr<gcn::Button> button; // A button
std::unique_ptr<gcn::ImageButton> imageButton; // An image button
std::unique_ptr<gcn::ImageTextButton> imageTextButton; // An image text button
std::unique_ptr<gcn::InputBox> inputBox; // An input box
std::unique_ptr<gcn::TextField> textField; // One-line text field
std::unique_ptr<gcn::TextBox> textBox; // Multi-line text box
Expand Down
24 changes: 1 addition & 23 deletions include/guisan/widgets/imagetextbutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,13 @@ namespace gcn
/**
* Destructor.
*/
~ImageTextButton() override;
~ImageTextButton() override = default;

/**
* Adjusts the size of the image button to fit the image.
*/
void adjustSize();

/**
* Sets the image to display.
*
* @param image The image to display.
*/
void setImage(Image* image);

/**
* Gets the image of the image button.
*
* @return The image of the image button.
*/
Image* getImage();

// Inherited from Widget

void draw(gcn::Graphics* graphics) override;
Expand Down Expand Up @@ -141,14 +127,6 @@ namespace gcn
};

protected:
gcn::Image* mImage = nullptr;

/**
* True if the image has been loaded internally, false otherwise.
* An image not loaded internally should not be deleted in the
* destructor.
*/
bool mInternalImage = false;
unsigned int mAlignment = ImageTextButton::BOTTOM;
};
}
Expand Down
19 changes: 0 additions & 19 deletions src/widgets/imagetextbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ namespace gcn
setHeight(mImage->getHeight() + mImage->getHeight() / 2);
}

ImageTextButton::~ImageTextButton()
{
if (mInternalImage)
delete mImage;
}

void ImageTextButton::adjustSize()
{
switch(getAlignment())
Expand All @@ -113,19 +107,6 @@ namespace gcn
}
}

void ImageTextButton::setImage(Image* image)
{
if (mInternalImage)
delete mImage;
mImage = image;
mInternalImage = false;
}

Image* ImageTextButton::getImage()
{
return mImage;
}

void ImageTextButton::draw(Graphics* graphics)
{
gcn::Color faceColor = getBaseColor();
Expand Down

0 comments on commit 9565056

Please sign in to comment.