diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6636b62b..033f6bf2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,6 +80,8 @@ target_sources(tomato PUBLIC ./chat_gui/icons/group.cpp ./chat_gui/contact_list.hpp ./chat_gui/contact_list.cpp + ./chat_gui/contact_tree.hpp + ./chat_gui/contact_tree.cpp ./chat_gui/file_selector.hpp ./chat_gui/file_selector.cpp ./chat_gui/send_image_popup.hpp diff --git a/src/chat_gui/contact_tree.cpp b/src/chat_gui/contact_tree.cpp new file mode 100644 index 00000000..99bf7ea4 --- /dev/null +++ b/src/chat_gui/contact_tree.cpp @@ -0,0 +1,97 @@ +#include "./contact_tree.hpp" + +#include + +#include "./contact_list.hpp" +#include "entt/entity/entity.hpp" + +#include + +namespace Components { + struct TagTreeViewOpen {}; +}; + +ContactTreeWindow::ContactTreeWindow(Contact3Registry& cr, Theme& theme, ContactTextureCache& ctc) : _cr(cr), _theme(theme), _ctc(ctc) { +} + +void ContactTreeWindow::render(void) { + //{ // main window menubar injection + // // assumes the window "tomato" was rendered already by cg + // if (ImGui::Begin("tomato")) { + // if (ImGui::BeginMenuBar()) { + // ImGui::Separator(); + // if (ImGui::BeginMenu("Settings")) { + // if (ImGui::MenuItem("settings window", nullptr, _show_window)) { + // _show_window = !_show_window; + // } + // ImGui::EndMenu(); + // } + // ImGui::EndMenuBar(); + // } + // } + // ImGui::End(); + //} + + if (_show_window) { + if (ImGui::Begin("ContactTreeWindow", &_show_window)) { + + if (ImGui::BeginTable("##table", 1, ImGuiTableFlags_None)) { + // first we need all root nodes + for (const auto [cv_root] : _cr.view().each()) { + ImGui::TableNextRow(); + ImGui::PushID(entt::to_integral(cv_root)); + + ImGui::TableNextColumn(); + + Contact3Handle c_root {_cr, cv_root}; + bool open = c_root.all_of(); + + bool has_children = c_root.all_of(); + + // roots are usually no normal contacts + // they should display as a protocol or profile or account + // TODO: set some table background instead of full span selected? + if (renderContactBig(_theme, _ctc, c_root, 2, false, true)) { + // clicked, toggle open + if (open) { + c_root.remove(); + open = false; + } else { + c_root.emplace_or_replace(); + open = true; + } + } + + if (open) { + // render children + + ImGui::Indent(); + + if (c_root.all_of()) { + for (const auto cv_child : c_root.get().subs) { + ImGui::PushID(entt::to_integral(cv_child)); + + Contact3Handle c_child {_cr, cv_child}; + renderContactBig(_theme, _ctc, c_child, 2); + + ImGui::PopID(); + } + } else { + // TODO: remove + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::TextDisabled("no parent of"); + } + + ImGui::Unindent(); + + } + ImGui::PopID(); + } + ImGui::EndTable(); + } + } + ImGui::End(); + } +} + diff --git a/src/chat_gui/contact_tree.hpp b/src/chat_gui/contact_tree.hpp new file mode 100644 index 00000000..b5c81af4 --- /dev/null +++ b/src/chat_gui/contact_tree.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "./texture_cache_defs.hpp" + +// fwd +struct Theme; + +class ContactTreeWindow { + bool _show_window {true}; + + Contact3Registry& _cr; + + Theme& _theme; + ContactTextureCache& _ctc; + + public: + ContactTreeWindow(Contact3Registry& cr, Theme& theme, ContactTextureCache& ctc); + + void render(void); +}; + diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 82c465f7..b23fb5cf 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -43,6 +43,7 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme mil(), msg_tc(mil, sdlrtu), cg(conf, os, rmm, cr, sdlrtu, contact_tc, msg_tc, theme), + ctw(cr, theme, contact_tc), sw(conf), osui(os), tuiu(tc, conf), @@ -357,6 +358,7 @@ Screen* MainScreen::render(float time_delta, bool&) { const float msgtc_interval = msg_tc.update(); const float cg_interval = cg.render(time_delta); // render + ctw.render(); sw.render(); // render osui.render(); tuiu.render(); // render diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 7519d61d..c5ba7e5b 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -30,6 +30,7 @@ #include "./message_image_loader.hpp" #include "./chat_gui4.hpp" +#include "./chat_gui/contact_tree.hpp" #include "./chat_gui/settings_window.hpp" #include "./object_store_ui.hpp" #include "./tox_ui_utils.hpp" @@ -92,6 +93,7 @@ struct MainScreen final : public Screen { TextureCache msg_tc; ChatGui4 cg; + ContactTreeWindow ctw; SettingsWindow sw; ObjectStoreUI osui; ToxUIUtils tuiu;