add 'edited' read-only textbox property
This commit is contained in:
parent
433c12a17a
commit
93f20b1746
@ -79,6 +79,7 @@ Properties:
|
|||||||
| hint | string | yes | yes | text to display when nothing is entered |
|
| hint | string | yes | yes | text to display when nothing is entered |
|
||||||
| caret | int | yes | yes | carriage position. `textbox.caret = -1` will set the position to the end of the text |
|
| caret | int | yes | yes | carriage position. `textbox.caret = -1` will set the position to the end of the text |
|
||||||
| editable | bool | yes | yes | text mutability |
|
| editable | bool | yes | yes | text mutability |
|
||||||
|
| edited | bool | yes | no | is text edited since the last set (history is not empty) |
|
||||||
| multiline | bool | yes | yes | multiline support |
|
| multiline | bool | yes | yes | multiline support |
|
||||||
| lineNumbers | bool | yes | yes | display line numbers |
|
| lineNumbers | bool | yes | yes | display line numbers |
|
||||||
| textWrap | bool | yes | yes | automatic text wrapping (only with multiline: "true") |
|
| textWrap | bool | yes | yes | automatic text wrapping (only with multiline: "true") |
|
||||||
|
|||||||
@ -79,6 +79,7 @@ document["worlds-panel"]:clear()
|
|||||||
| hint | string | да | да | текст, отображаемый, когда ничего не введено |
|
| hint | string | да | да | текст, отображаемый, когда ничего не введено |
|
||||||
| caret | int | да | да | позиция каретки. `textbox.caret = -1` установит позицию в конец текста |
|
| caret | int | да | да | позиция каретки. `textbox.caret = -1` установит позицию в конец текста |
|
||||||
| editable | bool | да | да | изменяемость текста |
|
| editable | bool | да | да | изменяемость текста |
|
||||||
|
| edited | bool | да | нет | был ли изменён текст с последней установки (история не пуста) |
|
||||||
| multiline | bool | да | да | поддержка многострочности |
|
| multiline | bool | да | да | поддержка многострочности |
|
||||||
| lineNumbers | bool | да | да | отображение номеров строк |
|
| lineNumbers | bool | да | да | отображение номеров строк |
|
||||||
| textWrap | bool | да | да | автоматический перенос текста (только при multiline: "true") |
|
| textWrap | bool | да | да | автоматический перенос текста (только при multiline: "true") |
|
||||||
|
|||||||
@ -141,10 +141,7 @@ namespace gui {
|
|||||||
auto action =
|
auto action =
|
||||||
std::make_unique<InputAction>(getTextBoxWeakptr(), pos, string);
|
std::make_unique<InputAction>(getTextBoxWeakptr(), pos, string);
|
||||||
history.store(std::move(action), erasing);
|
history.store(std::move(action), erasing);
|
||||||
pos = -1;
|
reset();
|
||||||
length = 0;
|
|
||||||
ss = {};
|
|
||||||
erasing = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void undo() {
|
void undo() {
|
||||||
@ -160,6 +157,17 @@ namespace gui {
|
|||||||
history.redo();
|
history.redo();
|
||||||
locked = false;
|
locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
pos = -1;
|
||||||
|
length = 0;
|
||||||
|
erasing = false;
|
||||||
|
ss = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSynced() const {
|
||||||
|
return length == 0;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
TextBox& textBox;
|
TextBox& textBox;
|
||||||
ActionsHistory& history;
|
ActionsHistory& history;
|
||||||
@ -556,6 +564,10 @@ bool TextBox::isEditable() const {
|
|||||||
return editable;
|
return editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TextBox::isEdited() const {
|
||||||
|
return history->size() != 0 || !historian->isSynced();
|
||||||
|
}
|
||||||
|
|
||||||
size_t TextBox::getSelectionStart() const {
|
size_t TextBox::getSelectionStart() const {
|
||||||
return selectionStart;
|
return selectionStart;
|
||||||
}
|
}
|
||||||
@ -986,6 +998,8 @@ const std::wstring& TextBox::getText() const {
|
|||||||
void TextBox::setText(const std::wstring& value) {
|
void TextBox::setText(const std::wstring& value) {
|
||||||
this->input = value;
|
this->input = value;
|
||||||
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
||||||
|
historian->reset();
|
||||||
|
history->clear();
|
||||||
refreshSyntax();
|
refreshSyntax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -204,6 +204,8 @@ namespace gui {
|
|||||||
/// @brief Check if text editing feature is enabled
|
/// @brief Check if text editing feature is enabled
|
||||||
virtual bool isEditable() const;
|
virtual bool isEditable() const;
|
||||||
|
|
||||||
|
virtual bool isEdited() const;
|
||||||
|
|
||||||
virtual void setPadding(glm::vec4 padding);
|
virtual void setPadding(glm::vec4 padding);
|
||||||
glm::vec4 getPadding() const;
|
glm::vec4 getPadding() const;
|
||||||
|
|
||||||
|
|||||||
@ -294,6 +294,13 @@ static int p_get_editable(UINode* node, lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int p_get_edited(UINode* node, lua::State* L) {
|
||||||
|
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||||
|
return lua::pushboolean(L, box->isEdited());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int p_get_line_numbers(UINode* node, lua::State* L) {
|
static int p_get_line_numbers(UINode* node, lua::State* L) {
|
||||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||||
return lua::pushboolean(L, box->isShowLineNumbers());
|
return lua::pushboolean(L, box->isShowLineNumbers());
|
||||||
@ -451,6 +458,7 @@ static int l_gui_getattr(lua::State* L) {
|
|||||||
{"caret", p_get_caret},
|
{"caret", p_get_caret},
|
||||||
{"text", p_get_text},
|
{"text", p_get_text},
|
||||||
{"editable", p_get_editable},
|
{"editable", p_get_editable},
|
||||||
|
{"edited", p_get_edited},
|
||||||
{"lineNumbers", p_get_line_numbers},
|
{"lineNumbers", p_get_line_numbers},
|
||||||
{"lineAt", p_get_line_at},
|
{"lineAt", p_get_line_at},
|
||||||
{"linePos", p_get_line_pos},
|
{"linePos", p_get_line_pos},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user