From 0b46b891c2957288ba0695e9ba462151403ebcf4 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 1 Sep 2023 21:13:36 +0200 Subject: [PATCH] add simple quote message context menu --- src/chat_gui4.cpp | 31 ++++++++++++++++++++++++------- src/chat_gui4.hpp | 3 +++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 628928ed..24c6d665 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -72,8 +72,6 @@ void ChatGui4::render(void) { if (_selected_contact) { const std::string chat_label = "chat " + std::to_string(entt::to_integral(*_selected_contact)); if (ImGui::BeginChild(chat_label.c_str(), {0, 0}, true)) { - static std::string text_buffer; - if (_cr.all_of(*_selected_contact)) { const auto sub_contacts = _cr.get(*_selected_contact).subs; if (!sub_contacts.empty()) { @@ -83,7 +81,7 @@ void ChatGui4::render(void) { for (const auto& c : sub_contacts) { // TODO: can a sub be selected? no if (renderSubContactListContact(c, _selected_contact.has_value() && *_selected_contact == c)) { - text_buffer.insert(0, (_cr.all_of(c) ? _cr.get(c).name : "") + ": "); + _text_input_buffer.insert(0, (_cr.all_of(c) ? _cr.get(c).name : "") + ": "); } } } @@ -257,10 +255,10 @@ void ChatGui4::render(void) { ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_CtrlEnterForNewLine; - if (ImGui::InputTextMultiline("##text_input", &text_buffer, {-0.001f, -0.001f}, input_flags)) { + if (ImGui::InputTextMultiline("##text_input", &_text_input_buffer, {-0.001f, -0.001f}, input_flags)) { //_mm.sendMessage(*_selected_contact, MessageType::TEXT, text_buffer); - _rmm.sendText(*_selected_contact, text_buffer); - text_buffer.clear(); + _rmm.sendText(*_selected_contact, _text_input_buffer); + _text_input_buffer.clear(); evil_enter_looses_focus_hack = true; } } @@ -315,12 +313,31 @@ void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) { ImGui::PushStyleColor(ImGuiCol_FrameBg, {0.f, 0.f, 0.f, 0.f}); // remove text input box ImGui::InputTextMultiline( - "", + "##text", const_cast(msgtext.c_str()), // ugly const cast msgtext.size() + 1, // needs to include '\0' text_size, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll ); + if (ImGui::BeginPopupContextItem("##text")) { + if (ImGui::MenuItem("quote")) { + //text_buffer.insert(0, (_cr.all_of(c) ? _cr.get(c).name : "") + ": "); + if (!_text_input_buffer.empty()) { + _text_input_buffer += "\n"; + } + + _text_input_buffer += "> "; + + for (const char c : msgtext) { + _text_input_buffer += c; + + if (c == '\n') { + _text_input_buffer += "> "; + } + } + } + ImGui::EndPopup(); + } ImGui::PopStyleColor(); ImGui::PopStyleVar(); diff --git a/src/chat_gui4.hpp b/src/chat_gui4.hpp index d1145ee1..f1b8af0d 100644 --- a/src/chat_gui4.hpp +++ b/src/chat_gui4.hpp @@ -26,6 +26,9 @@ class ChatGui4 { std::optional _selected_contact; + // TODO: per contact + std::string _text_input_buffer; + bool _show_chat_extra_info {true}; float TEXT_BASE_WIDTH {1};