add 'text-color' textbox property
This commit is contained in:
parent
d660880365
commit
801650824e
@ -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.
|
||||
|
||||
@ -106,6 +106,7 @@
|
||||
- `text-wrap` - разрешает автоматический перенос текста (работает только при multiline: "true")
|
||||
- `editable`- определяет возможность редактирования текста.
|
||||
- `error-color` - цвет при вводе некорректных данных (текст не проходит проверку валидатора). Тип: RGBA цвет.
|
||||
- `text-color` - цвет текста. Тип: RGBA цвет.
|
||||
- `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен.
|
||||
- `onup` - lua функция вызываемая при нажатии стрелки вверх.
|
||||
- `ondown` - lua функция вызываемая при нажатии стрелки вниз.
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<Label> label;
|
||||
/// @brief Current user input
|
||||
std::wstring input;
|
||||
@ -106,6 +107,9 @@ namespace gui {
|
||||
virtual void setFocusedColor(glm::vec4 color);
|
||||
virtual glm::vec4 getFocusedColor() const;
|
||||
|
||||
virtual void setTextColor(glm::vec4 color);
|
||||
virtual glm::vec4 getTextColor() const;
|
||||
|
||||
/// @brief Set color of textbox marked by validator as invalid
|
||||
virtual void setErrorColor(glm::vec4 color);
|
||||
|
||||
|
||||
@ -384,6 +384,9 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, const xml::xmlel
|
||||
if (element->has("error-color")) {
|
||||
textbox->setErrorColor(element->attr("error-color").asColor());
|
||||
}
|
||||
if (element->has("text-color")) {
|
||||
textbox->setTextColor(element->attr("text-color").asColor());
|
||||
}
|
||||
if (element->has("validator")) {
|
||||
textbox->setTextValidator(scripting::create_wstring_validator(
|
||||
reader.getEnvironment(),
|
||||
|
||||
@ -221,6 +221,13 @@ static int p_get_track_color(UINode* node, lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_text_color(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushcolor(L, box->getTextColor());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_is_valid(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushboolean(L, box->validate());
|
||||
@ -383,6 +390,7 @@ static int l_gui_getattr(lua::State* L) {
|
||||
{"step", p_get_step},
|
||||
{"trackWidth", p_get_track_width},
|
||||
{"trackColor", p_get_track_color},
|
||||
{"textColor", p_get_text_color},
|
||||
{"checked", p_is_checked},
|
||||
{"page", p_get_page},
|
||||
{"back", p_get_back},
|
||||
@ -497,6 +505,11 @@ static void p_set_track_color(UINode* node, lua::State* L, int idx) {
|
||||
bar->setTrackColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_text_color(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setTextColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_checked(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<CheckBox*>(node)) {
|
||||
box->setChecked(lua::toboolean(L, idx));
|
||||
@ -564,6 +577,7 @@ static int l_gui_setattr(lua::State* L) {
|
||||
{"step", p_set_step},
|
||||
{"trackWidth", p_set_track_width},
|
||||
{"trackColor", p_set_track_color},
|
||||
{"textColor", p_set_text_color},
|
||||
{"checked", p_set_checked},
|
||||
{"page", p_set_page},
|
||||
{"inventory", p_set_inventory},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user