Fixed an issue where resizing in SwitchComponent would not reposition the image.

This commit is contained in:
Leon Styhre 2021-10-23 15:30:35 +02:00
parent 114c91679e
commit 022f8c7e8b
2 changed files with 11 additions and 1 deletions

View file

@ -49,6 +49,16 @@ void SwitchComponent::render(const glm::mat4& parentTrans)
renderChildren(trans);
}
void SwitchComponent::setResize(float width, float height)
{
// Reposition the switch after resizing to make it centered.
const glm::vec2 oldSize = mImage.getSize();
mImage.setResize(width, height);
const float xDiff = oldSize.x - mImage.getSize().x;
const float yDiff = oldSize.y - mImage.getSize().y;
mImage.setPosition(mImage.getPosition().x + xDiff, mImage.getPosition().y + yDiff / 2.0f);
}
void SwitchComponent::setState(bool state)
{
mState = state;

View file

@ -22,7 +22,7 @@ public:
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override { mImage.setSize(mSize); }
void setResize(float width, float height) override { mImage.setResize(width, height); }
void setResize(float width, float height) override;
bool getState() const { return mState; }
void setState(bool state);