From 7286f01035d88b7e6be364be70ddce416f05f932 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Sat, 4 Apr 2026 22:28:33 +0300 Subject: [PATCH] Fixed GUI textbox moving cursor on layout --- .../Tools/EditTools/TextBoxEditTool.cpp | 2 -- src/GUIStuff/Elements/TextBox.decl.hpp | 1 + src/GUIStuff/Elements/TextBox.impl.hpp | 13 +++++++++---- src/GlobalConfig.hpp | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp index 06c044c..00c88f2 100644 --- a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp @@ -303,8 +303,6 @@ void TextBoxEditTool::right_click_popup_gui(Vector2f popupPos) { } }); }); - - } void TextBoxEditTool::hold_undo_data(const std::string& undoName, TextBoxCanvasComponent& a) { diff --git a/src/GUIStuff/Elements/TextBox.decl.hpp b/src/GUIStuff/Elements/TextBox.decl.hpp index 69d4165..71ae946 100644 --- a/src/GUIStuff/Elements/TextBox.decl.hpp +++ b/src/GUIStuff/Elements/TextBox.decl.hpp @@ -52,6 +52,7 @@ template class TextBox : public Element { bool update_data(); bool is_selected() const; + bool isHeld = false; std::optional edit; std::optional oldData; diff --git a/src/GUIStuff/Elements/TextBox.impl.hpp b/src/GUIStuff/Elements/TextBox.impl.hpp index a79b1f9..a8d1db2 100644 --- a/src/GUIStuff/Elements/TextBox.impl.hpp +++ b/src/GUIStuff/Elements/TextBox.impl.hpp @@ -106,6 +106,8 @@ template void TextBox::input_text_callback(const InputManager::T template void TextBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { auto& io = gui.io; + isHeld = false; + if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) { if(button.down) { if(mouseHovering) { @@ -117,7 +119,8 @@ template void TextBox::input_mouse_button_callback(const InputMa if(userInfo.onSelect) userInfo.onSelect(); }); } - textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); + isHeld = true; + textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, isHeld, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); } else if(is_selected()) { gui.io.input->remove_text_box(edit.value().textboxInputID); @@ -131,14 +134,14 @@ template void TextBox::input_mouse_button_callback(const InputMa } } else { - textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); + textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, isHeld, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); } } } template void TextBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { if(boundingBox.has_value()) - textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); + textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, isHeld, gui.io.input->key(InputManager::KEY_GENERIC_LSHIFT).held); } template void TextBox::init_textbox(UpdateInputData& io) { @@ -153,7 +156,9 @@ template void TextBox::init_textbox(UpdateInputData& io) { template void TextBox::reset_textbox_text() { textbox->set_string(userInfo.toStr(*userInfo.data)); - cur->pos = cur->selectionBeginPos = cur->selectionEndPos = {0, 0}; + cur->pos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->pos); + cur->selectionBeginPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionBeginPos); + cur->selectionEndPos = textbox->move(RichText::TextBox::Movement::NOWHERE, cur->selectionEndPos); } template bool TextBox::update_data() { diff --git a/src/GlobalConfig.hpp b/src/GlobalConfig.hpp index 33ac607..5b45350 100644 --- a/src/GlobalConfig.hpp +++ b/src/GlobalConfig.hpp @@ -43,7 +43,7 @@ class GlobalConfig { NONE, SKIA, DYNAMIC_MSAA - } antialiasing = AntiAliasing::DYNAMIC_MSAA; + } antialiasing = AntiAliasing::SKIA; std::string displayName; bool flipZoomToolDirection = false;