Merge branch 'main' into devtools

This commit is contained in:
MihailRis
2024-05-16 06:44:27 +03:00
8 changed files with 132 additions and 16 deletions
+35
View File
@@ -320,6 +320,41 @@ int TextBox::calcIndexAt(int x, int y) const {
return std::min(offset+label->getTextLineOffset(line), input.length());
}
inline std::wstring get_alphabet(wchar_t c) {
std::wstring alphabet {c};
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
return L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
} else if (c >= '0' && c <= '9') {
return L"0123456789";
}
return alphabet;
}
void TextBox::tokenSelectAt(int index) {
int left = index;
int right = index;
std::wstring alphabet = get_alphabet(input.at(index));
while (left >= 0) {
if (alphabet.find(input.at(left)) == std::wstring::npos) {
break;
}
left--;
}
while (static_cast<size_t>(right) < input.length()) {
if (alphabet.find(input.at(right)) == std::wstring::npos) {
break;
}
right++;
}
select(left+1, right);
}
void TextBox::doubleClick(GUI* gui, int x, int y) {
UINode::doubleClick(gui, x, y);
tokenSelectAt(normalizeIndex(calcIndexAt(x, y)-1));
}
void TextBox::click(GUI*, int x, int y) {
int index = normalizeIndex(calcIndexAt(x, y));
selectionStart = index;
+2
View File
@@ -52,6 +52,7 @@ namespace gui {
bool eraseSelected();
void resetSelection();
void extendSelection(int index);
void tokenSelectAt(int index);
size_t getLineLength(uint line) const;
/// @brief Get total length of the selection
@@ -151,6 +152,7 @@ namespace gui {
virtual void onFocus(GUI*) override;
virtual void refresh() override;
virtual void doubleClick(GUI*, int x, int y) override;
virtual void click(GUI*, int, int) override;
virtual void mouseMove(GUI*, int x, int y) override;
virtual bool isFocuskeeper() const override {return true;}
+14
View File
@@ -64,10 +64,24 @@ UINode* UINode::listenAction(onaction action) {
return this;
}
UINode* UINode::listenDoubleClick(onaction action) {
doubleClickCallbacks.push_back(action);
return this;
}
void UINode::click(GUI*, int, int) {
pressed = true;
}
void UINode::doubleClick(GUI* gui, int x, int y) {
pressed = true;
if (isInside(glm::vec2(x, y))) {
for (auto callback : doubleClickCallbacks) {
callback(gui);
}
}
}
void UINode::mouseRelease(GUI* gui, int x, int y) {
pressed = false;
if (isInside(glm::vec2(x, y))) {
+4
View File
@@ -88,6 +88,8 @@ namespace gui {
vec2supplier sizefunc = nullptr;
/// @brief 'onclick' callbacks
std::vector<onaction> actions;
/// @brief 'ondoubleclick' callbacks
std::vector<onaction> doubleClickCallbacks;
UINode(glm::vec2 size);
public:
@@ -138,8 +140,10 @@ namespace gui {
int getZIndex() const;
virtual UINode* listenAction(onaction action);
virtual UINode* listenDoubleClick(onaction action);
virtual void onFocus(GUI*) {focused = true;}
virtual void doubleClick(GUI*, int x, int y);
virtual void click(GUI*, int x, int y);
virtual void clicked(GUI*, mousecode button) {}
virtual void mouseMove(GUI*, int x, int y) {};