* 剪贴板操作

This commit is contained in:
2024-02-23 10:46:21 +08:00
parent 8b643b0912
commit 55c65cccdb
6 changed files with 67 additions and 2 deletions
+17
View File
@@ -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 是否含有数字(十进制)
*/
+21 -1
View File
@@ -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();
+8
View File
@@ -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:
+14
View File
@@ -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;
+1
View File
@@ -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);
+6 -1
View File
@@ -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
{