SDK/Console: Make use of ScrollAreaWidget

This commit is contained in:
Lynix 2019-07-05 22:26:22 +02:00
parent 42aa7ca355
commit 296b5459c6
2 changed files with 11 additions and 2 deletions

View File

@ -27,6 +27,7 @@ namespace Ndk
{
class Console;
class Entity;
class ScrollAreaWidget;
class TextAreaWidget;
using ConsoleHandle = Nz::ObjectHandle<Console>;
@ -69,6 +70,7 @@ namespace Ndk
std::size_t m_historyPosition;
std::vector<Nz::String> m_commandHistory;
std::vector<Line> m_historyLines;
ScrollAreaWidget* m_historyArea;
TextAreaWidget* m_history;
TextAreaWidget* m_input;
Nz::FontRef m_defaultFont;

View File

@ -48,6 +48,8 @@ namespace Ndk
m_history->SetReadOnly(true);
m_history->SetBackgroundColor(Nz::Color(80, 80, 160, 128));
m_historyArea = Add<ScrollAreaWidget>(m_history);
// Input
m_input = Add<TextAreaWidget>();
m_input->EnableBackground(true);
@ -102,6 +104,9 @@ namespace Ndk
{
m_historyLines.emplace_back(Line{ color, text });
m_history->AppendText(text + '\n');
m_history->Resize(m_history->GetPreferredSize());
m_historyArea->Resize(m_historyArea->GetSize());
m_historyArea->ScrollToRatio(1.f);
}
/*!
@ -113,6 +118,8 @@ namespace Ndk
{
m_historyLines.clear();
m_history->Clear();
m_history->Resize(m_history->GetPreferredSize());
m_historyArea->Resize(m_historyArea->GetSize());
m_input->SetText(s_inputPrefix);
}
@ -206,8 +213,8 @@ namespace Ndk
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
float diff = historyHeight - m_maxHistoryLines * lineHeight;
m_history->Resize({ size.x, historyHeight - diff - 4.f });
m_history->SetPosition(origin.x, origin.y + diff);
m_historyArea->SetPosition(origin.x, origin.y + diff);
m_historyArea->Resize({ size.x, historyHeight - diff - 4.f });
m_input->Resize({size.x, size.y - historyHeight});
m_input->SetPosition(origin.x, origin.y + historyHeight);