add simple quote message context menu

This commit is contained in:
Green Sky 2023-09-01 21:13:36 +02:00
parent d131b5a02f
commit 0b46b891c2
No known key found for this signature in database
2 changed files with 27 additions and 7 deletions

View File

@ -72,8 +72,6 @@ void ChatGui4::render(void) {
if (_selected_contact) { if (_selected_contact) {
const std::string chat_label = "chat " + std::to_string(entt::to_integral(*_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)) { if (ImGui::BeginChild(chat_label.c_str(), {0, 0}, true)) {
static std::string text_buffer;
if (_cr.all_of<Contact::Components::ParentOf>(*_selected_contact)) { if (_cr.all_of<Contact::Components::ParentOf>(*_selected_contact)) {
const auto sub_contacts = _cr.get<Contact::Components::ParentOf>(*_selected_contact).subs; const auto sub_contacts = _cr.get<Contact::Components::ParentOf>(*_selected_contact).subs;
if (!sub_contacts.empty()) { if (!sub_contacts.empty()) {
@ -83,7 +81,7 @@ void ChatGui4::render(void) {
for (const auto& c : sub_contacts) { for (const auto& c : sub_contacts) {
// TODO: can a sub be selected? no // TODO: can a sub be selected? no
if (renderSubContactListContact(c, _selected_contact.has_value() && *_selected_contact == c)) { if (renderSubContactListContact(c, _selected_contact.has_value() && *_selected_contact == c)) {
text_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": "); _text_input_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": ");
} }
} }
} }
@ -257,10 +255,10 @@ void ChatGui4::render(void) {
ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_NoHorizontalScroll |
ImGuiInputTextFlags_CtrlEnterForNewLine; 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); //_mm.sendMessage(*_selected_contact, MessageType::TEXT, text_buffer);
_rmm.sendText(*_selected_contact, text_buffer); _rmm.sendText(*_selected_contact, _text_input_buffer);
text_buffer.clear(); _text_input_buffer.clear();
evil_enter_looses_focus_hack = true; 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::PushStyleColor(ImGuiCol_FrameBg, {0.f, 0.f, 0.f, 0.f}); // remove text input box
ImGui::InputTextMultiline( ImGui::InputTextMultiline(
"", "##text",
const_cast<char*>(msgtext.c_str()), // ugly const cast const_cast<char*>(msgtext.c_str()), // ugly const cast
msgtext.size() + 1, // needs to include '\0' msgtext.size() + 1, // needs to include '\0'
text_size, text_size,
ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll
); );
if (ImGui::BeginPopupContextItem("##text")) {
if (ImGui::MenuItem("quote")) {
//text_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": ");
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::PopStyleColor();
ImGui::PopStyleVar(); ImGui::PopStyleVar();

View File

@ -26,6 +26,9 @@ class ChatGui4 {
std::optional<Contact3> _selected_contact; std::optional<Contact3> _selected_contact;
// TODO: per contact
std::string _text_input_buffer;
bool _show_chat_extra_info {true}; bool _show_chat_extra_info {true};
float TEXT_BASE_WIDTH {1}; float TEXT_BASE_WIDTH {1};