Widgets Fixes (#190)

* CheckboxWidget: Check

* ImageWidget: Check

* LabelWidget: Delete uselessly overridden Layout

* ProgressBarWidget: Check
This commit is contained in:
S6066 2018-10-09 23:23:22 +02:00 committed by Jérôme Leclercq
parent a24944d103
commit 56922001ba
5 changed files with 6 additions and 21 deletions

View File

@ -26,8 +26,6 @@ namespace Ndk
//virtual ImageWidget* Clone() const = 0;
void ResizeToContent();
inline const Nz::Color& GetColor() const;
inline const Nz::TextureRef& GetTexture() const;
inline const Nz::Rectf& GetTextureCoords() const;

View File

@ -32,8 +32,6 @@ namespace Ndk
LabelWidget& operator=(LabelWidget&&) = default;
private:
void Layout() override;
EntityHandle m_textEntity;
Nz::TextSpriteRef m_textSprite;
};

View File

@ -112,20 +112,16 @@ namespace Ndk
{
BaseWidget::Layout();
Nz::Vector2f origin = Nz::Vector2f(0.f);
Nz::Vector2f checkboxSize = GetCheckboxSize();
Nz::Vector2f borderSize = GetCheckboxBorderSize();
m_checkboxBorderEntity->GetComponent<NodeComponent>().SetPosition(origin);
m_checkboxBackgroundEntity->GetComponent<NodeComponent>().SetPosition(origin + borderSize);
m_checkboxBackgroundEntity->GetComponent<NodeComponent>().SetPosition(borderSize);
Nz::Vector3f checkboxBox = m_checkboxContentSprite->GetBoundingVolume().obb.localBox.GetLengths();
m_checkboxContentEntity->GetComponent<NodeComponent>().SetPosition(origin.x + checkboxSize.x / 2.f - checkboxBox.x / 2.f,
origin.y + checkboxSize.y / 2.f - checkboxBox.y / 2.f);
m_checkboxContentEntity->GetComponent<NodeComponent>().SetPosition(checkboxSize.x / 2.f - checkboxBox.x / 2.f, checkboxSize.y / 2.f - checkboxBox.y / 2.f);
Nz::Vector3f textBox = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
m_textEntity->GetComponent<NodeComponent>().SetPosition(origin.x + checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin),
origin.y + checkboxSize.y / 2.f - textBox.y / 2.f);
m_textEntity->GetComponent<NodeComponent>().SetPosition(checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin), checkboxSize.y / 2.f - textBox.y / 2.f);
}
void CheckboxWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button)
@ -175,7 +171,7 @@ namespace Ndk
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
Nz::Vector2f checkboxSize = GetCheckboxSize();
Nz::Vector2f finalSize{ checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin) + textSize.x, std::max(textSize.y, checkboxSize.y) };
Nz::Vector2f finalSize { checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin) + textSize.x, std::max(textSize.y, checkboxSize.y) };
SetMinimumSize(finalSize);
SetPreferredSize(finalSize);
}

View File

@ -19,9 +19,4 @@ namespace Ndk
Layout();
}
void LabelWidget::Layout()
{
BaseWidget::Layout();
}
}

View File

@ -76,7 +76,6 @@ namespace Ndk
void ProgressBarWidget::Layout()
{
Nz::Vector2f origin = Nz::Vector2f(0.f);
Nz::Vector2f size = GetSize();
Nz::Vector2f progressBarSize = size;
@ -85,7 +84,7 @@ namespace Ndk
UpdateText();
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
m_textEntity->GetComponent<NodeComponent>().SetPosition(origin.x + size.x - textSize.x, origin.y + size.y / 2.f - textSize.y);
m_textEntity->GetComponent<NodeComponent>().SetPosition(size.x - textSize.x, size.y / 2.f - textSize.y);
progressBarSize -= { textSize.x + m_textMargin, 0.f };
}
@ -96,7 +95,6 @@ namespace Ndk
m_barBackgroundSprite->SetSize(progressBarSize - (borderSize * 2.f));
m_barSprite->SetSize((progressBarSize.x - (borderSize.x * 2.f)) / 100.f * static_cast<float>(m_value), progressBarSize.y - (borderSize.y * 2.f));
m_borderEntity->GetComponent<NodeComponent>().SetPosition(origin.x, origin.y);
m_barEntity->GetComponent<NodeComponent>().SetPosition(origin.x + borderSize.x, origin.y + borderSize.y);
m_barEntity->GetComponent<NodeComponent>().SetPosition(borderSize.x, borderSize.y);
}
}