From 22e97063ec7a94c05061066d10cb0d14bb99adde Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 22 May 2024 22:23:55 +0200 Subject: [PATCH] unread icon in contact list --- src/chat_gui/contact_list.cpp | 67 ++++++++++++++++++++++++++++++++++- src/chat_gui/contact_list.hpp | 5 ++- src/chat_gui/theme.cpp | 11 +++--- 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/chat_gui/contact_list.cpp b/src/chat_gui/contact_list.cpp index 82ce543..a9c6434 100644 --- a/src/chat_gui/contact_list.cpp +++ b/src/chat_gui/contact_list.cpp @@ -89,6 +89,52 @@ static void drawIconCloud( ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_main, ImDrawFlags_None, 1.5f); } +static void drawIconMailLines( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col, + const float thickness +) { +#define PLINE(x0, y0, x1, y1) \ + ImGui::GetWindowDrawList()->AddLine( \ + {p0.x + p1_o.x*(x0), p0.y + p1_o.y*(y0)}, \ + {p0.x + p1_o.x*(x1), p0.y + p1_o.y*(y1)}, \ + col, \ + thickness \ + ); + + // quad + // (1,2) -> (1,8) + PLINE(0.1f, 0.2f, 0.1f, 0.8f) + // (1,8) -> (9,8) + PLINE(0.1f, 0.8f, 0.9f, 0.8f) + // (9,8) -> (9,2) + PLINE(0.9f, 0.8f, 0.9f, 0.2f) + // (9,2) -> (1,2) + PLINE(0.9f, 0.2f, 0.1f, 0.2f) + + // lip + // (1,2) -> (5,5) + PLINE(0.1f, 0.2f, 0.5f, 0.5f) + // (5,5) -> (9,2) + PLINE(0.5f, 0.5f, 0.9f, 0.2f) + +#undef PLINE +} + +static void drawIconMail( + const ImVec2 p0, + const ImVec2 p1_o, + const ImU32 col_main, + const ImU32 col_back +) { + // dark background + // the circle looks bad in light mode + //ImGui::GetWindowDrawList()->AddCircleFilled({p0.x + p1_o.x*0.5f, p0.y + p1_o.y*0.5f}, p1_o.x*0.5f, col_back); + drawIconMailLines(p0, p1_o, col_back, 4.0f); + drawIconMailLines(p0, p1_o, col_main, 1.5f); +} + void renderAvatar( const Theme& th, ContactTextureCache& contact_tc, @@ -245,7 +291,26 @@ bool renderContactBig( ImGui::SameLine(0.f, same_line_spacing); } - ImGui::Text("%s%s", unread?"* ":"", (c.all_of() ? c.get().name.c_str() : "")); + //ImGui::Text("%s%s", unread?"* ":"", (c.all_of() ? c.get().name.c_str() : "")); + ImGui::TextUnformatted(c.all_of() ? c.get().name.c_str() : ""); + if (unread) { + ImGui::SameLine(); + const float icon_size { TEXT_BASE_HEIGHT - ImGui::GetStyle().FramePadding.y*2 }; + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - icon_size); + + // icon pos + auto p0 = ImGui::GetCursorScreenPos(); + //p0.y += ImGui::GetStyle().FramePadding.y; + ImVec2 p1_o = {icon_size, icon_size}; + + drawIconMail( + p0, + p1_o, + ImGui::GetColorU32(th.getColor()), + ImGui::GetColorU32(th.getColor()) + ); + ImGui::Dummy(p1_o); + } } // line 2 diff --git a/src/chat_gui/contact_list.hpp b/src/chat_gui/contact_list.hpp index 0b2bfc8..c284054 100644 --- a/src/chat_gui/contact_list.hpp +++ b/src/chat_gui/contact_list.hpp @@ -14,6 +14,9 @@ enum class ThemeCol_Contact { avatar_online_cloud, avatar_offline, + unread, + unread_muted, + icon_backdrop, }; @@ -27,7 +30,7 @@ void renderAvatar( // returns true if clicked, if selectable, will highlight on hover and respect selected // TODO: refine // +------+ -// | | *Name (Alias?) +// | | *Name (Alias?) [v] // |Avatar| Satus Message <-- richpresence interface? // | | user status (online/away/busy)-direct/relayed / offline <-- last text? // +------+ diff --git a/src/chat_gui/theme.cpp b/src/chat_gui/theme.cpp index 2711293..2476435 100644 --- a/src/chat_gui/theme.cpp +++ b/src/chat_gui/theme.cpp @@ -41,14 +41,17 @@ bool Theme::store(void) { Theme getDefaultThemeDark(void) { Theme t; - t.setColor({0.98f, 0.41f, 0.26f, 0.52f}); - t.setColor({0.98f, 0.26f, 0.41f, 0.52f}); + t.setColor({0.98f, 0.41f, 0.26f, 0.52f}); + t.setColor({0.98f, 0.26f, 0.41f, 0.52f}); t.setColor({0.3f, 1.0f, 0.0f, 1.0f}); t.setColor({0.0f, 1.0f, 0.8f, 1.0f}); - t.setColor({0.4f, 0.4f, 0.4f, 1.0f}); + t.setColor({0.4f, 0.4f, 0.4f, 1.0f}); - t.setColor({0.0f, 0.0f, 0.0f, 0.4f}); + t.setColor(ImGui::GetStyleColorVec4(ImGuiCol_PlotHistogramHovered)); + t.setColor({0.6f, 0.6f, 0.6f, 0.9f}); + + t.setColor({0.0f, 0.0f, 0.0f, 0.4f}); return t; }