add 'edited' read-only textbox property

This commit is contained in:
MihailRis
2025-03-12 02:32:41 +03:00
parent 433c12a17a
commit 93f20b1746
5 changed files with 30 additions and 4 deletions
+18 -4
View File
@@ -141,10 +141,7 @@ namespace gui {
auto action =
std::make_unique<InputAction>(getTextBoxWeakptr(), pos, string);
history.store(std::move(action), erasing);
pos = -1;
length = 0;
ss = {};
erasing = false;
reset();
}
void undo() {
@@ -160,6 +157,17 @@ namespace gui {
history.redo();
locked = false;
}
void reset() {
pos = -1;
length = 0;
erasing = false;
ss = {};
}
bool isSynced() const {
return length == 0;
}
private:
TextBox& textBox;
ActionsHistory& history;
@@ -556,6 +564,10 @@ bool TextBox::isEditable() const {
return editable;
}
bool TextBox::isEdited() const {
return history->size() != 0 || !historian->isSynced();
}
size_t TextBox::getSelectionStart() const {
return selectionStart;
}
@@ -986,6 +998,8 @@ const std::wstring& TextBox::getText() const {
void TextBox::setText(const std::wstring& value) {
this->input = value;
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
historian->reset();
history->clear();
refreshSyntax();
}
+2
View File
@@ -204,6 +204,8 @@ namespace gui {
/// @brief Check if text editing feature is enabled
virtual bool isEditable() const;
virtual bool isEdited() const;
virtual void setPadding(glm::vec4 padding);
glm::vec4 getPadding() const;
+8
View File
@@ -294,6 +294,13 @@ static int p_get_editable(UINode* node, lua::State* L) {
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) {
if (auto box = dynamic_cast<TextBox*>(node)) {
return lua::pushboolean(L, box->isShowLineNumbers());
@@ -451,6 +458,7 @@ static int l_gui_getattr(lua::State* L) {
{"caret", p_get_caret},
{"text", p_get_text},
{"editable", p_get_editable},
{"edited", p_get_edited},
{"lineNumbers", p_get_line_numbers},
{"lineAt", p_get_line_at},
{"linePos", p_get_line_pos},