Console: Add support for text color

This commit is contained in:
Lynix 2019-09-22 13:07:00 +02:00 committed by Jérôme Leclercq
parent 8e4df4cadc
commit 1ea653ab5b
4 changed files with 7 additions and 6 deletions

View File

@ -285,6 +285,7 @@ Nazara Development Kit:
- ⚠️ Console class is no longer bound to a LuaState and now has a OnCommand signal
- ⚠️ Made AbstractTextAreaWidget which is inherited by TextAreaWidget
- ⚠️ Added RichTextAreaWidget
- ⚠️ Console now supports text color in history
# 0.4:

View File

@ -27,6 +27,7 @@ namespace Ndk
class AbstractTextAreaWidget;
class Console;
class Entity;
class RichTextAreaWidget;
class ScrollAreaWidget;
class TextAreaWidget;
@ -46,7 +47,7 @@ namespace Ndk
void ClearFocus();
inline unsigned int GetCharacterSize() const;
inline const TextAreaWidget* GetHistory() const;
inline const RichTextAreaWidget* GetHistory() const;
inline const TextAreaWidget* GetInput() const;
inline const Nz::FontRef& GetTextFont() const;
@ -73,7 +74,7 @@ namespace Ndk
std::vector<Nz::String> m_commandHistory;
std::vector<Line> m_historyLines;
ScrollAreaWidget* m_historyArea;
TextAreaWidget* m_history;
RichTextAreaWidget* m_history;
TextAreaWidget* m_input;
Nz::FontRef m_defaultFont;
unsigned int m_characterSize;

View File

@ -19,7 +19,7 @@ namespace Ndk
* \return History of the console
*/
inline const TextAreaWidget* Console::GetHistory() const
inline const RichTextAreaWidget* Console::GetHistory() const
{
return m_history;
}

View File

@ -10,8 +10,6 @@
#include <NDK/Widgets.hpp>
#include <NDK/World.hpp>
///TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so
namespace Ndk
{
namespace
@ -42,7 +40,7 @@ namespace Ndk
m_maxHistoryLines(200)
{
// History
m_history = Add<TextAreaWidget>();
m_history = Add<RichTextAreaWidget>();
m_history->EnableBackground(true);
m_history->EnableLineWrap(true);
m_history->SetReadOnly(true);
@ -112,6 +110,7 @@ namespace Ndk
m_historyLines.erase(m_historyLines.begin());
m_historyLines.emplace_back(Line{ color, text });
m_history->SetTextColor(color);
m_history->AppendText(text + '\n');
m_history->Resize(m_history->GetPreferredSize());
m_historyArea->Resize(m_historyArea->GetSize());