TextBox new properties

This commit is contained in:
MihailRis 2024-02-22 12:07:01 +03:00
parent cae0ceb8a3
commit c68e89038f
5 changed files with 55 additions and 0 deletions

View File

@ -355,6 +355,22 @@ void TextBox::setTextValidator(wstringchecker validator) {
this->validator = validator;
}
void TextBox::setFocusedColor(glm::vec4 color) {
this->focusedColor = color;
}
glm::vec4 TextBox::getFocusedColor() const {
return focusedColor;
}
void TextBox::setErrorColor(glm::vec4 color) {
this->invalidColor = color;
}
glm::vec4 TextBox::getErrorColor() const {
return invalidColor;
}
std::wstring TextBox::getText() const {
if (input.empty())
return placeholder;

View File

@ -118,6 +118,10 @@ namespace gui {
virtual void setTextConsumer(wstringconsumer consumer);
virtual void setTextValidator(wstringchecker validator);
virtual bool isFocuskeeper() const override {return true;}
virtual void setFocusedColor(glm::vec4 color);
virtual glm::vec4 getFocusedColor() const;
virtual void setErrorColor(glm::vec4 color);
virtual glm::vec4 getErrorColor() const;
/* Get TextBox content text or placeholder if empty */
virtual std::wstring getText() const;
/* Set TextBox content text */

View File

@ -228,6 +228,20 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
);
textbox->setTextSupplier(supplier);
}
if (element->has("focused-color")) {
textbox->setFocusedColor(element->attr("focused-color").asColor());
}
if (element->has("error-color")) {
textbox->setErrorColor(element->attr("error-color").asColor());
}
if (element->has("validator")) {
auto validator = scripting::create_wstring_validator(
reader.getEnvironment().getId(),
element->attr("validator").getText(),
reader.getFilename()+".lua"
);
textbox->setTextValidator(validator);
}
return textbox;
}

View File

@ -66,6 +66,21 @@ wstringsupplier scripting::create_wstring_supplier(
};
}
wstringchecker scripting::create_wstring_validator(
int env,
const std::string& src,
const std::string& file
) {
return [=](const std::wstring& x){
if (processCallback(env, src, file)) {
state->pushstring(util::wstr2str_utf8(x));
if (state->callNoThrow(1))
return state->toboolean(-1);
}
return false;
};
}
boolconsumer scripting::create_bool_consumer(
int env,
const std::string& src,

View File

@ -24,6 +24,12 @@ namespace scripting {
const std::string& file="<string>"
);
wstringchecker create_wstring_validator(
int env,
const std::string& src,
const std::string& file="<string>"
);
boolconsumer create_bool_consumer(
int env,
const std::string& src,