feat: 'edited' property reset & add 'oncontrolkey' textbox callback
This commit is contained in:
@@ -564,7 +564,12 @@ bool TextBox::isEditable() const {
|
||||
}
|
||||
|
||||
bool TextBox::isEdited() const {
|
||||
return history->size() != 0 || !historian->isSynced();
|
||||
return history->size() != editedHistorySize || !historian->isSynced();
|
||||
}
|
||||
|
||||
void TextBox::setUnedited() {
|
||||
historian->sync();
|
||||
editedHistorySize = history->size();
|
||||
}
|
||||
|
||||
size_t TextBox::getSelectionStart() const {
|
||||
@@ -575,7 +580,6 @@ size_t TextBox::getSelectionEnd() const {
|
||||
return selectionEnd;
|
||||
}
|
||||
|
||||
|
||||
void TextBox::setOnEditStart(runnable oneditstart) {
|
||||
onEditStart = oneditstart;
|
||||
}
|
||||
@@ -849,7 +853,12 @@ void TextBox::keyPressed(keycode key) {
|
||||
if (editable) {
|
||||
performEditingKeyboardEvents(key);
|
||||
}
|
||||
if (Events::pressed(keycode::LEFT_CONTROL)) {
|
||||
if (Events::pressed(keycode::LEFT_CONTROL) && key != keycode::LEFT_CONTROL) {
|
||||
if (controlCombinationsHandler) {
|
||||
if (controlCombinationsHandler(static_cast<int>(key))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Copy selected text to clipboard
|
||||
if (key == keycode::C || key == keycode::X) {
|
||||
std::string text = util::wstr2str_utf8(getSelection());
|
||||
@@ -963,6 +972,10 @@ void TextBox::setTextValidator(wstringchecker validator) {
|
||||
this->validator = std::move(validator);
|
||||
}
|
||||
|
||||
void TextBox::setOnControlCombination(key_handler handler) {
|
||||
this->controlCombinationsHandler = std::move(handler);
|
||||
}
|
||||
|
||||
void TextBox::setFocusedColor(glm::vec4 color) {
|
||||
this->focusedColor = color;
|
||||
}
|
||||
@@ -999,6 +1012,7 @@ void TextBox::setText(const std::wstring& value) {
|
||||
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
||||
historian->reset();
|
||||
history->clear();
|
||||
editedHistorySize = 0;
|
||||
refreshSyntax();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace gui {
|
||||
LabelCache rawTextCache;
|
||||
std::shared_ptr<ActionsHistory> history;
|
||||
std::unique_ptr<TextBoxHistorian> historian;
|
||||
int editedHistorySize = 0;
|
||||
protected:
|
||||
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 1.0f};
|
||||
@@ -33,6 +34,7 @@ namespace gui {
|
||||
wstringconsumer subconsumer = nullptr;
|
||||
/// @brief Text validator returning boolean value
|
||||
wstringchecker validator = nullptr;
|
||||
key_handler controlCombinationsHandler = nullptr;
|
||||
/// @brief Function called on focus
|
||||
runnable onEditStart = nullptr;
|
||||
/// @brief Function called on up arrow pressed
|
||||
@@ -117,6 +119,8 @@ namespace gui {
|
||||
/// @param validator std::wstring consumer returning boolean
|
||||
virtual void setTextValidator(wstringchecker validator);
|
||||
|
||||
virtual void setOnControlCombination(key_handler handler);
|
||||
|
||||
virtual void setFocusedColor(glm::vec4 color);
|
||||
virtual glm::vec4 getFocusedColor() const;
|
||||
|
||||
@@ -205,6 +209,7 @@ namespace gui {
|
||||
virtual bool isEditable() const;
|
||||
|
||||
virtual bool isEdited() const;
|
||||
virtual void setUnedited();
|
||||
|
||||
virtual void setPadding(glm::vec4 padding);
|
||||
glm::vec4 getPadding() const;
|
||||
|
||||
@@ -493,6 +493,13 @@ static std::shared_ptr<UINode> read_text_box(
|
||||
reader.getFilename()
|
||||
));
|
||||
}
|
||||
if (element.has("oncontrolkey")) {
|
||||
textbox->setOnControlCombination(scripting::create_key_handler(
|
||||
reader.getEnvironment(),
|
||||
element.attr("oncontrolkey").getText(),
|
||||
reader.getFilename()
|
||||
));
|
||||
}
|
||||
if (auto onUpPressed = create_runnable(reader, element, "onup")) {
|
||||
textbox->setOnUpPressed(onUpPressed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user