textbox editable property fix
This commit is contained in:
parent
60cfe8595e
commit
1f3cf5ed53
@ -130,7 +130,6 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
|
||||
/// @brief Insert text at the caret. Also selected text will be erased
|
||||
/// @param text Inserting text
|
||||
void TextBox::paste(const std::wstring& text) {
|
||||
|
||||
eraseSelected();
|
||||
if (caret >= input.length()) {
|
||||
input += text;
|
||||
@ -203,7 +202,9 @@ void TextBox::setTextOffset(uint x) {
|
||||
}
|
||||
|
||||
void TextBox::typed(unsigned int codepoint) {
|
||||
paste(std::wstring({(wchar_t)codepoint}));
|
||||
if (editable) {
|
||||
paste(std::wstring({(wchar_t)codepoint}));
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::validate() {
|
||||
|
||||
@ -204,6 +204,13 @@ static int p_get_text(UINode* node) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_editable(UINode* node) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return state->pushboolean(box->isEditable());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_add(UINode* node) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return state->pushcfunction(l_container_add);
|
||||
@ -268,6 +275,7 @@ static int l_gui_getattr(lua_State* L) {
|
||||
{"placeholder", p_get_placeholder},
|
||||
{"valid", p_is_valid},
|
||||
{"text", p_get_text},
|
||||
{"editable", p_get_editable},
|
||||
{"value", p_get_value},
|
||||
{"min", p_get_min},
|
||||
{"max", p_get_max},
|
||||
@ -325,6 +333,11 @@ static void p_set_text(UINode* node, int idx) {
|
||||
box->setText(util::str2wstr_utf8(state->tostring(idx)));
|
||||
}
|
||||
}
|
||||
static void p_set_editable(UINode* node, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setEditable(state->toboolean(idx));
|
||||
}
|
||||
}
|
||||
static void p_set_value(UINode* node, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setValue(state->tonumber(idx));
|
||||
@ -397,6 +410,7 @@ static int l_gui_setattr(lua_State* L) {
|
||||
{"enabled", p_set_enabled},
|
||||
{"placeholder", p_set_placeholder},
|
||||
{"text", p_set_text},
|
||||
{"editable", p_set_editable},
|
||||
{"value", p_set_value},
|
||||
{"min", p_set_min},
|
||||
{"max", p_set_max},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user