diff --git a/dl/base/dl_string.h b/dl/base/dl_string.h index 4dfbd6ab..3280f01a 100644 --- a/dl/base/dl_string.h +++ b/dl/base/dl_string.h @@ -388,6 +388,23 @@ inline void CvtPathSeparator(std::string& path) Every::Replace(path, '\\', '/'); } +/** +* @brief 换行符统一为\n +* @param[in] str 字符串 +*/ +inline std::string CvtLineBreak(std::string_view str) +{ + std::string ret; + for (auto& iter : str) + { + if(iter == '\r') + continue; + ret.push_back(iter); + } + return ret; +} + + /** * @brief 是否含有数字(十进制) */ diff --git a/dl/system/dl_system.cpp b/dl/system/dl_system.cpp index 23f4f324..8fc9f873 100644 --- a/dl/system/dl_system.cpp +++ b/dl/system/dl_system.cpp @@ -67,8 +67,15 @@ static void CallbackKey(GLFWwindow* window, int key, int scancode, int action, i if (action == GLFW_REPEAT || action == GLFW_PRESS) { - g_ui->_on_key(key, mods & GLFW_MOD_CONTROL); + g_ui->_on_key(key, + mods & GLFW_MOD_CONTROL); } + /*mods& GLFW_MOD_CONTROL, + mods& GLFW_MOD_SHIFT, + mods& GLFW_MOD_ALT, + mods& GLFW_MOD_SUPER, + mods& GLFW_MOD_CAPS_LOCK, + mods& GLFW_MOD_NUM_LOCK*/ #endif } static void CallbackChar(GLFWwindow* window, unsigned int codepoint) @@ -322,6 +329,19 @@ void System::SetCursorMode(CursorMode mode) #endif } +void System::SetClipboardString(std::string_view str) +{ + glfwSetClipboardString(nullptr, str.data()); +} + +std::string System::GetClipboardString() +{ + const char* str = glfwGetClipboardString(nullptr); + if (!str) + return {}; + return str; +} + const RenderInfo2D& System::GetRenderInfo2D() { return g_vk->GetRenderInfo2D(); diff --git a/dl/system/dl_system.h b/dl/system/dl_system.h index e3e0e856..555caa79 100644 --- a/dl/system/dl_system.h +++ b/dl/system/dl_system.h @@ -114,6 +114,14 @@ public: */ void SetCursorMode(CursorMode mode); + /** + * @brief 设置剪贴板 + */ + void SetClipboardString(std::string_view str); + /** + * @brief 返回剪贴板 + */ + std::string GetClipboardString(); SystemImp* GetImp() { return _imp; } private: diff --git a/dl/ui/dl_ui_edit_box.cpp b/dl/ui/dl_ui_edit_box.cpp index dc6385f7..c8c19499 100644 --- a/dl/ui/dl_ui_edit_box.cpp +++ b/dl/ui/dl_ui_edit_box.cpp @@ -71,6 +71,20 @@ void EditBox::_on_backspace() _refresh_select(); } +void EditBox::_on_string(std::string_view str) +{ + log_test0(str); + + std::u32string s = CodeCvt::Utf8ToUtf32(String::CvtLineBreak(str)); + _str.insert(_str.begin() + _iCursor, s.begin(), s.end()); + _iCursor += s.size(); + _bChange = true; + + _refresh_txt(); + _refresh_cursor(); + _refresh_select(); +} + bool EditBox::IsFocus() { return g_ui->GetFocusEditBox() == this; diff --git a/dl/ui/dl_ui_edit_box.h b/dl/ui/dl_ui_edit_box.h index 2d3cebc8..63edcdb0 100644 --- a/dl/ui/dl_ui_edit_box.h +++ b/dl/ui/dl_ui_edit_box.h @@ -142,6 +142,7 @@ public: void _on_char(char32_t ch); void _on_backspace();// 退格 + void _on_string(std::string_view str);// void _on_focus(bool focus); diff --git a/dl/ui/dl_ui_manager.cpp b/dl/ui/dl_ui_manager.cpp index 5a5dac3c..fcd9dae3 100644 --- a/dl/ui/dl_ui_manager.cpp +++ b/dl/ui/dl_ui_manager.cpp @@ -616,7 +616,12 @@ void Manager::_on_key(int action, bool ctrl) return; if (ctrl) { - + if ((KeyCode)action == KeyCode::C) + { + g_system->SetClipboardString(_edtFocus->GetString()); + } + else if ((KeyCode)action == KeyCode::V) + _edtFocus->_on_string(g_system->GetClipboardString()); } else {