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")
|
- `text-wrap` - allows automatic text wrapping (works only with multiline: "true")
|
||||||
- `editable` - determines whether the text can be edited.
|
- `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.
|
- `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.
|
- `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.
|
- `onup` - lua function called when the up arrow is pressed.
|
||||||
- `ondown` - lua function called when the down arrow is pressed.
|
- `ondown` - lua function called when the down arrow is pressed.
|
||||||
|
|||||||
@ -106,6 +106,7 @@
|
|||||||
- `text-wrap` - разрешает автоматический перенос текста (работает только при multiline: "true")
|
- `text-wrap` - разрешает автоматический перенос текста (работает только при multiline: "true")
|
||||||
- `editable`- определяет возможность редактирования текста.
|
- `editable`- определяет возможность редактирования текста.
|
||||||
- `error-color` - цвет при вводе некорректных данных (текст не проходит проверку валидатора). Тип: RGBA цвет.
|
- `error-color` - цвет при вводе некорректных данных (текст не проходит проверку валидатора). Тип: RGBA цвет.
|
||||||
|
- `text-color` - цвет текста. Тип: RGBA цвет.
|
||||||
- `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен.
|
- `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен.
|
||||||
- `onup` - lua функция вызываемая при нажатии стрелки вверх.
|
- `onup` - lua функция вызываемая при нажатии стрелки вверх.
|
||||||
- `ondown` - lua функция вызываемая при нажатии стрелки вниз.
|
- `ondown` - lua функция вызываемая при нажатии стрелки вниз.
|
||||||
|
|||||||
@ -126,7 +126,7 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::refreshLabel() {
|
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());
|
label->setText(input.empty() && !hint.empty() ? hint : getText());
|
||||||
|
|
||||||
if (autoresize && font) {
|
if (autoresize && font) {
|
||||||
@ -619,6 +619,15 @@ glm::vec4 TextBox::getFocusedColor() const {
|
|||||||
return focusedColor;
|
return focusedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TextBox::setTextColor(glm::vec4 color) {
|
||||||
|
this->textColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec4 TextBox::getTextColor() const {
|
||||||
|
return textColor;
|
||||||
|
}
|
||||||
|
|
||||||
void TextBox::setErrorColor(glm::vec4 color) {
|
void TextBox::setErrorColor(glm::vec4 color) {
|
||||||
this->invalidColor = color;
|
this->invalidColor = color;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ namespace gui {
|
|||||||
protected:
|
protected:
|
||||||
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
|
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 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;
|
std::shared_ptr<Label> label;
|
||||||
/// @brief Current user input
|
/// @brief Current user input
|
||||||
std::wstring input;
|
std::wstring input;
|
||||||
@ -106,6 +107,9 @@ namespace gui {
|
|||||||
virtual void setFocusedColor(glm::vec4 color);
|
virtual void setFocusedColor(glm::vec4 color);
|
||||||
virtual glm::vec4 getFocusedColor() const;
|
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
|
/// @brief Set color of textbox marked by validator as invalid
|
||||||
virtual void setErrorColor(glm::vec4 color);
|
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")) {
|
if (element->has("error-color")) {
|
||||||
textbox->setErrorColor(element->attr("error-color").asColor());
|
textbox->setErrorColor(element->attr("error-color").asColor());
|
||||||
}
|
}
|
||||||
|
if (element->has("text-color")) {
|
||||||
|
textbox->setTextColor(element->attr("text-color").asColor());
|
||||||
|
}
|
||||||
if (element->has("validator")) {
|
if (element->has("validator")) {
|
||||||
textbox->setTextValidator(scripting::create_wstring_validator(
|
textbox->setTextValidator(scripting::create_wstring_validator(
|
||||||
reader.getEnvironment(),
|
reader.getEnvironment(),
|
||||||
|
|||||||
@ -221,6 +221,13 @@ static int p_get_track_color(UINode* node, lua::State* L) {
|
|||||||
return 0;
|
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) {
|
static int p_is_valid(UINode* node, lua::State* L) {
|
||||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||||
return lua::pushboolean(L, box->validate());
|
return lua::pushboolean(L, box->validate());
|
||||||
@ -383,6 +390,7 @@ static int l_gui_getattr(lua::State* L) {
|
|||||||
{"step", p_get_step},
|
{"step", p_get_step},
|
||||||
{"trackWidth", p_get_track_width},
|
{"trackWidth", p_get_track_width},
|
||||||
{"trackColor", p_get_track_color},
|
{"trackColor", p_get_track_color},
|
||||||
|
{"textColor", p_get_text_color},
|
||||||
{"checked", p_is_checked},
|
{"checked", p_is_checked},
|
||||||
{"page", p_get_page},
|
{"page", p_get_page},
|
||||||
{"back", p_get_back},
|
{"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));
|
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) {
|
static void p_set_checked(UINode* node, lua::State* L, int idx) {
|
||||||
if (auto box = dynamic_cast<CheckBox*>(node)) {
|
if (auto box = dynamic_cast<CheckBox*>(node)) {
|
||||||
box->setChecked(lua::toboolean(L, idx));
|
box->setChecked(lua::toboolean(L, idx));
|
||||||
@ -564,6 +577,7 @@ static int l_gui_setattr(lua::State* L) {
|
|||||||
{"step", p_set_step},
|
{"step", p_set_step},
|
||||||
{"trackWidth", p_set_track_width},
|
{"trackWidth", p_set_track_width},
|
||||||
{"trackColor", p_set_track_color},
|
{"trackColor", p_set_track_color},
|
||||||
|
{"textColor", p_set_text_color},
|
||||||
{"checked", p_set_checked},
|
{"checked", p_set_checked},
|
||||||
{"page", p_set_page},
|
{"page", p_set_page},
|
||||||
{"inventory", p_set_inventory},
|
{"inventory", p_set_inventory},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user