TextBox new properties
This commit is contained in:
@@ -355,6 +355,22 @@ void TextBox::setTextValidator(wstringchecker validator) {
|
|||||||
this->validator = 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 {
|
std::wstring TextBox::getText() const {
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return placeholder;
|
return placeholder;
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ namespace gui {
|
|||||||
virtual void setTextConsumer(wstringconsumer consumer);
|
virtual void setTextConsumer(wstringconsumer consumer);
|
||||||
virtual void setTextValidator(wstringchecker validator);
|
virtual void setTextValidator(wstringchecker validator);
|
||||||
virtual bool isFocuskeeper() const override {return true;}
|
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 */
|
/* Get TextBox content text or placeholder if empty */
|
||||||
virtual std::wstring getText() const;
|
virtual std::wstring getText() const;
|
||||||
/* Set TextBox content text */
|
/* Set TextBox content text */
|
||||||
|
|||||||
@@ -228,6 +228,20 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
);
|
);
|
||||||
textbox->setTextSupplier(supplier);
|
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;
|
return textbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(
|
boolconsumer scripting::create_bool_consumer(
|
||||||
int env,
|
int env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ namespace scripting {
|
|||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
wstringchecker create_wstring_validator(
|
||||||
|
int env,
|
||||||
|
const std::string& src,
|
||||||
|
const std::string& file="<string>"
|
||||||
|
);
|
||||||
|
|
||||||
boolconsumer create_bool_consumer(
|
boolconsumer create_bool_consumer(
|
||||||
int env,
|
int env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
|
|||||||
Reference in New Issue
Block a user