Core/Node: Refactor interface

- Removed overloads taking multiple scalars
- Removed CoordSys parameter (functions exists in two sets, local and global)
This commit is contained in:
SirLynix
2024-02-18 22:16:54 +01:00
committed by Jérôme Leclercq
parent 194dba5002
commit 63c526cecc
23 changed files with 444 additions and 462 deletions

View File

@@ -42,7 +42,7 @@ namespace Nz
gfxComponent.AttachRenderable(m_textSprite, GetCanvas()->GetRenderMask());
auto& textNode = registry.get<NodeComponent>(m_textEntity);
textNode.SetPosition(s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight);
textNode.SetPosition({ s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight });
SetCursor(SystemCursor::Text);
@@ -84,7 +84,7 @@ namespace Nz
const AbstractTextDrawer& textDrawer = GetTextDrawer();
auto& textNode = GetRegistry().get<NodeComponent>(m_textEntity);
Vector2f textPosition = Vector2f(textNode.GetPosition(CoordSys::Local));
Vector2f textPosition = Vector2f(textNode.GetPosition());
x -= textPosition.x;
y -= textPosition.y;
@@ -627,19 +627,19 @@ namespace Nz
float glyphWidth = (lastGlyph) ? lastGlyph->bounds.width : 0.f;
auto& textNode = registry.get<NodeComponent>(m_textEntity);
float textPosition = textNode.GetPosition(CoordSys::Local).x - s_textAreaPaddingWidth;
float textPosition = textNode.GetPosition().x - s_textAreaPaddingWidth;
float cursorPosition = glyphPos + textPosition + ((overshooting) ? glyphWidth : 0.f);
float width = GetWidth();
if (width <= textDrawer.GetBounds().width)
{
if (cursorPosition + glyphWidth > width)
textNode.Move(width - cursorPosition - glyphWidth - s_textAreaPaddingWidth, 0.f);
textNode.Move({ width - cursorPosition - glyphWidth - s_textAreaPaddingWidth, 0.f });
else if (cursorPosition - glyphWidth < 0.f)
textNode.Move(-cursorPosition + glyphWidth - s_textAreaPaddingWidth, 0.f);
textNode.Move({ -cursorPosition + glyphWidth - s_textAreaPaddingWidth, 0.f });
}
else
textNode.Move(-textPosition, 0.f); //< Reset text position if we have enough room to show everything
textNode.Move({ -textPosition, 0.f }); //< Reset text position if we have enough room to show everything
// Create/destroy cursor entities and sprites
std::size_t selectionLineCount = m_cursorPositionEnd.y - m_cursorPositionBegin.y + 1;
@@ -697,14 +697,14 @@ namespace Nz
cursor.sprite->SetSize(Vector2f(spriteSize, lineInfo.bounds.height));
registry.get<NodeComponent>(cursor.entity).SetPosition(beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
registry.get<NodeComponent>(cursor.entity).SetPosition({ beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height });
}
else
{
// Full line selection
cursor.sprite->SetSize(Vector2f(lineInfo.bounds.width, lineInfo.bounds.height));
registry.get<NodeComponent>(cursor.entity).SetPosition(0.f, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
registry.get<NodeComponent>(cursor.entity).SetPosition({ 0.f, textHeight - lineInfo.bounds.y - lineInfo.bounds.height });
}
}
}
@@ -724,6 +724,6 @@ namespace Nz
Vector2f textSize = Vector2f(m_textSprite->GetAABB().GetLengths());
auto& textNode = GetRegistry().get<NodeComponent>(m_textEntity);
textNode.SetPosition(s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight - textSize.y);
textNode.SetPosition({ s_textAreaPaddingWidth, GetHeight() - s_textAreaPaddingHeight - textSize.y });
}
}

View File

@@ -306,7 +306,7 @@ namespace Nz
Rectf BaseWidget::GetScissorRect() const
{
Vector2f widgetPos = Vector2f(GetPosition(CoordSys::Global));
Vector2f widgetPos = Vector2f(GetGlobalPosition());
Vector2f widgetSize = GetSize();
Rectf widgetRect(widgetPos.x, widgetPos.y, widgetSize.x, widgetSize.y);

View File

@@ -25,7 +25,7 @@ namespace Nz
{
float contentPosition = (GetHeight() - m_content->GetHeight()) * (1.f - newValue);
m_content->SetPosition(0.f, contentPosition);
m_content->SetPosition({ 0.f, contentPosition });
m_content->SetRenderingRect(Nz::Rectf(-std::numeric_limits<float>::infinity(), -contentPosition, std::numeric_limits<float>::infinity(), GetHeight()));
});
@@ -78,7 +78,7 @@ namespace Nz
if (m_isScrollbarEnabled)
m_horizontalScrollbar->Show();
m_horizontalScrollbar->SetPosition(contentSize.x, 0.f);
m_horizontalScrollbar->SetPosition({ contentSize.x, 0.f, 0.f });
m_horizontalScrollbar->Resize({ scrollBarWidth, GetHeight() });
ScrollToRatio(m_horizontalScrollbar->GetValue());

View File

@@ -108,19 +108,19 @@ namespace Nz
{
m_scrollBackButton->Resize({ size.y, size.y });
m_scrollNextButton->Resize({ size.y, size.y });
m_scrollNextButton->SetPosition({ GetWidth() - m_scrollNextButton->GetWidth(), 0.f, 0.f });
m_scrollNextButton->SetPosition({ GetWidth() - m_scrollNextButton->GetWidth(), 0.f });
float start = m_scrollBackButton->GetWidth();
float remaining = size.x - start - m_scrollNextButton->GetWidth();
float centerPosition = start + invValuePct * (remaining - remaining * stepPct);
m_scrollCenterButton->Resize({ remaining * stepPct, size.y });
m_scrollCenterButton->SetPosition(start + centerPosition, 0.f);
m_scrollCenterButton->SetPosition({ start + centerPosition, 0.f });
}
else
{
m_scrollBackButton->Resize({ size.x, size.x });
m_scrollBackButton->SetPosition({ 0.f, GetHeight() - m_scrollBackButton->GetHeight(), 0.f });
m_scrollBackButton->SetPosition({ 0.f, GetHeight() - m_scrollBackButton->GetHeight() });
m_scrollNextButton->Resize({ size.x, size.x });
float start = m_scrollBackButton->GetHeight();
@@ -128,7 +128,7 @@ namespace Nz
float centerPosition = start + invValuePct * (remaining - remaining * stepPct);
m_scrollCenterButton->Resize({ size.x, remaining * stepPct });
m_scrollCenterButton->SetPosition(0.f, centerPosition);
m_scrollCenterButton->SetPosition({ 0.f, centerPosition });
}
m_style->Layout(size);

View File

@@ -56,7 +56,7 @@ namespace Nz
entt::registry& registry = GetRegistry();
Boxf textBox = m_textSprite->GetAABB();
registry.get<NodeComponent>(m_textEntity).SetPosition(size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f);
registry.get<NodeComponent>(m_textEntity).SetPosition({ size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f });
}
void SimpleButtonWidgetStyle::OnHoverBegin()
@@ -150,7 +150,7 @@ namespace Nz
Vector2f checkSize = size * 0.66f;
m_checkSprite->SetSize(checkSize);
GetRegistry().get<NodeComponent>(m_checkEntity).SetPosition(size.x / 2.f - checkSize.x / 2.f, size.y / 2.f - checkSize.y / 2.f);
GetRegistry().get<NodeComponent>(m_checkEntity).SetPosition({ size.x / 2.f - checkSize.x / 2.f, size.y / 2.f - checkSize.y / 2.f });
}
void SimpleCheckboxWidgetStyle::OnHoverBegin()
@@ -363,7 +363,7 @@ namespace Nz
entt::registry& registry = GetRegistry();
Boxf textBox = m_textSprite->GetAABB();
registry.get<NodeComponent>(m_entity).SetPosition(size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f);
registry.get<NodeComponent>(m_entity).SetPosition({ size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f });
}
void SimpleLabelWidgetStyle::OnHoverBegin()
@@ -426,7 +426,7 @@ namespace Nz
m_barEntity = CreateGraphicsEntity();
registry.get<GraphicsComponent>(m_barEntity).AttachRenderable(m_progressBarSprite, renderMask);
registry.get<NodeComponent>(m_barEntity).SetPosition(m_barOffset, m_barOffset);
registry.get<NodeComponent>(m_barEntity).SetPosition({ m_barOffset, m_barOffset });
}
void SimpleProgressBarWidgetStyle::Layout(const Vector2f& size)