diff --git a/SDK/include/NDK/Console.hpp b/SDK/include/NDK/Console.hpp index 75f4d48f9..cb79fcbee 100644 --- a/SDK/include/NDK/Console.hpp +++ b/SDK/include/NDK/Console.hpp @@ -27,6 +27,7 @@ namespace Ndk { class Console; class Entity; + class ScrollAreaWidget; class TextAreaWidget; using ConsoleHandle = Nz::ObjectHandle; @@ -69,6 +70,7 @@ namespace Ndk std::size_t m_historyPosition; std::vector m_commandHistory; std::vector m_historyLines; + ScrollAreaWidget* m_historyArea; TextAreaWidget* m_history; TextAreaWidget* m_input; Nz::FontRef m_defaultFont; diff --git a/SDK/src/NDK/Console.cpp b/SDK/src/NDK/Console.cpp index a6ad6d38a..84d9b08e4 100644 --- a/SDK/src/NDK/Console.cpp +++ b/SDK/src/NDK/Console.cpp @@ -48,6 +48,8 @@ namespace Ndk m_history->SetReadOnly(true); m_history->SetBackgroundColor(Nz::Color(80, 80, 160, 128)); + m_historyArea = Add(m_history); + // Input m_input = Add(); 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(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);