SDK/Console: Make use of ScrollAreaWidget
This commit is contained in:
parent
42aa7ca355
commit
296b5459c6
|
|
@ -27,6 +27,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
class Console;
|
class Console;
|
||||||
class Entity;
|
class Entity;
|
||||||
|
class ScrollAreaWidget;
|
||||||
class TextAreaWidget;
|
class TextAreaWidget;
|
||||||
|
|
||||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||||
|
|
@ -69,6 +70,7 @@ namespace Ndk
|
||||||
std::size_t m_historyPosition;
|
std::size_t m_historyPosition;
|
||||||
std::vector<Nz::String> m_commandHistory;
|
std::vector<Nz::String> m_commandHistory;
|
||||||
std::vector<Line> m_historyLines;
|
std::vector<Line> m_historyLines;
|
||||||
|
ScrollAreaWidget* m_historyArea;
|
||||||
TextAreaWidget* m_history;
|
TextAreaWidget* m_history;
|
||||||
TextAreaWidget* m_input;
|
TextAreaWidget* m_input;
|
||||||
Nz::FontRef m_defaultFont;
|
Nz::FontRef m_defaultFont;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ namespace Ndk
|
||||||
m_history->SetReadOnly(true);
|
m_history->SetReadOnly(true);
|
||||||
m_history->SetBackgroundColor(Nz::Color(80, 80, 160, 128));
|
m_history->SetBackgroundColor(Nz::Color(80, 80, 160, 128));
|
||||||
|
|
||||||
|
m_historyArea = Add<ScrollAreaWidget>(m_history);
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
m_input = Add<TextAreaWidget>();
|
m_input = Add<TextAreaWidget>();
|
||||||
m_input->EnableBackground(true);
|
m_input->EnableBackground(true);
|
||||||
|
|
@ -102,6 +104,9 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
m_historyLines.emplace_back(Line{ color, text });
|
m_historyLines.emplace_back(Line{ color, text });
|
||||||
m_history->AppendText(text + '\n');
|
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_historyLines.clear();
|
||||||
m_history->Clear();
|
m_history->Clear();
|
||||||
|
m_history->Resize(m_history->GetPreferredSize());
|
||||||
|
m_historyArea->Resize(m_historyArea->GetSize());
|
||||||
m_input->SetText(s_inputPrefix);
|
m_input->SetText(s_inputPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,8 +213,8 @@ namespace Ndk
|
||||||
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
|
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
|
||||||
float diff = historyHeight - m_maxHistoryLines * lineHeight;
|
float diff = historyHeight - m_maxHistoryLines * lineHeight;
|
||||||
|
|
||||||
m_history->Resize({ size.x, historyHeight - diff - 4.f });
|
m_historyArea->SetPosition(origin.x, origin.y + diff);
|
||||||
m_history->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->Resize({size.x, size.y - historyHeight});
|
||||||
m_input->SetPosition(origin.x, origin.y + historyHeight);
|
m_input->SetPosition(origin.x, origin.y + historyHeight);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue