From 801650824ecd00d0a9024701fb65b4d35b2f229b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 18 Nov 2024 14:03:30 +0300 Subject: [PATCH] add 'text-color' textbox property --- doc/en/xml-ui-layouts.md | 1 + doc/ru/xml-ui-layouts.md | 1 + src/graphics/ui/elements/TextBox.cpp | 11 ++++++++++- src/graphics/ui/elements/TextBox.hpp | 4 ++++ src/graphics/ui/gui_xml.cpp | 3 +++ src/logic/scripting/lua/libs/libgui.cpp | 14 ++++++++++++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index ac657e44..f4db96c6 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -105,6 +105,7 @@ Inner text - initially entered text - `text-wrap` - allows automatic text wrapping (works only with multiline: "true") - `editable` - determines whether the text can be edited. - `error-color` - color when entering incorrect data (the text does not pass the validator check). Type: RGBA color. +- `text-color` - text color. Type: RGBA color. - `validator` - lua function that checks text for correctness. Takes a string as input, returns true if the text is correct. - `onup` - lua function called when the up arrow is pressed. - `ondown` - lua function called when the down arrow is pressed. diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index bdf82f1b..adffcd73 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -106,6 +106,7 @@ - `text-wrap` - разрешает автоматический перенос текста (работает только при multiline: "true") - `editable`- определяет возможность редактирования текста. - `error-color` - цвет при вводе некорректных данных (текст не проходит проверку валидатора). Тип: RGBA цвет. +- `text-color` - цвет текста. Тип: RGBA цвет. - `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен. - `onup` - lua функция вызываемая при нажатии стрелки вверх. - `ondown` - lua функция вызываемая при нажатии стрелки вниз. diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index 9fe44327..a4e613d3 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -126,7 +126,7 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) { } void TextBox::refreshLabel() { - label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f)); + label->setColor(textColor * glm::vec4(input.empty() ? 0.5f : 1.0f)); label->setText(input.empty() && !hint.empty() ? hint : getText()); if (autoresize && font) { @@ -619,6 +619,15 @@ glm::vec4 TextBox::getFocusedColor() const { return focusedColor; } + +void TextBox::setTextColor(glm::vec4 color) { + this->textColor = color; +} + +glm::vec4 TextBox::getTextColor() const { + return textColor; +} + void TextBox::setErrorColor(glm::vec4 color) { this->invalidColor = color; } diff --git a/src/graphics/ui/elements/TextBox.hpp b/src/graphics/ui/elements/TextBox.hpp index 834f7a64..27b6e9c9 100644 --- a/src/graphics/ui/elements/TextBox.hpp +++ b/src/graphics/ui/elements/TextBox.hpp @@ -12,6 +12,7 @@ namespace gui { protected: glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f}; glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 1.0f}; + glm::vec4 textColor {1.0f, 1.0f, 1.0f, 1.0f}; std::shared_ptr