2024-04-21 14:17:50 +02:00
|
|
|
#include "./contact_list.hpp"
|
|
|
|
|
|
|
|
#include <solanaceae/contact/components.hpp>
|
|
|
|
|
|
|
|
#include <imgui/imgui.h>
|
|
|
|
//#include <imgui/imgui_internal.h>
|
|
|
|
|
2024-04-21 20:24:01 +02:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
static void drawIconDirectLines(
|
|
|
|
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 \
|
|
|
|
);
|
|
|
|
|
|
|
|
// arrow 1
|
|
|
|
// (3,1) -> (9,7)
|
|
|
|
PLINE(0.3f, 0.1f, 0.9f, 0.7f)
|
|
|
|
// (9,7) -> (9,5)
|
|
|
|
PLINE(0.9f, 0.7f, 0.9f, 0.5f)
|
|
|
|
// (9,7) -> (7,7)
|
|
|
|
PLINE(0.9f, 0.7f, 0.7f, 0.7f)
|
|
|
|
|
|
|
|
// arrow 2
|
|
|
|
// (7,9) -> (1,3)
|
|
|
|
PLINE(0.7f, 0.9f, 0.1f, 0.3f)
|
|
|
|
// (1,3) -> (3,3)
|
|
|
|
PLINE(0.1f, 0.3f, 0.3f, 0.3f)
|
|
|
|
// (1,3) -> (1,5)
|
|
|
|
PLINE(0.1f, 0.3f, 0.1f, 0.5f)
|
|
|
|
#undef PLINE
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drawIconDirect(
|
|
|
|
const ImVec2 p0,
|
|
|
|
const ImVec2 p1_o,
|
|
|
|
const ImU32 col_main,
|
|
|
|
const ImU32 col_back
|
|
|
|
) {
|
|
|
|
// dark background
|
2024-04-22 12:46:01 +02:00
|
|
|
// 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);
|
2024-04-21 20:24:01 +02:00
|
|
|
drawIconDirectLines(p0, p1_o, col_back, 4.0f);
|
|
|
|
drawIconDirectLines(p0, p1_o, col_main, 1.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drawIconCloud(
|
|
|
|
const ImVec2 p0,
|
|
|
|
const ImVec2 p1_o,
|
|
|
|
const ImU32 col_main,
|
|
|
|
const ImU32 col_back
|
|
|
|
) {
|
|
|
|
std::array<ImVec2, 19> points {{
|
|
|
|
{0.2f, 0.9f},
|
|
|
|
{0.8f, 0.9f},
|
|
|
|
{0.9f, 0.8f},
|
|
|
|
{0.9f, 0.7f},
|
|
|
|
{0.7f, 0.7f},
|
|
|
|
{0.9f, 0.5f},
|
|
|
|
{0.9f, 0.4f},
|
|
|
|
{0.8f, 0.2f},
|
|
|
|
{0.6f, 0.2f},
|
|
|
|
{0.5f, 0.3f},
|
|
|
|
{0.5f, 0.5f},
|
|
|
|
{0.4f, 0.4f},
|
|
|
|
{0.3f, 0.4f},
|
|
|
|
{0.2f, 0.5f},
|
|
|
|
{0.2f, 0.6f},
|
|
|
|
{0.3f, 0.7f},
|
|
|
|
{0.1f, 0.7f},
|
|
|
|
{0.1f, 0.8f},
|
|
|
|
{0.2f, 0.9f},
|
|
|
|
}};
|
|
|
|
for (auto& v : points) {
|
2024-04-22 12:46:01 +02:00
|
|
|
v.y -= 0.1f;
|
2024-04-21 20:24:01 +02:00
|
|
|
v = {p0.x + p1_o.x*v.x, p0.y + p1_o.y*v.y};
|
|
|
|
}
|
2024-04-22 12:46:01 +02:00
|
|
|
// 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);
|
2024-04-21 20:24:01 +02:00
|
|
|
ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_back, ImDrawFlags_None, 4.f);
|
|
|
|
ImGui::GetWindowDrawList()->AddPolyline(points.data(), points.size(), col_main, ImDrawFlags_None, 1.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderAvatar(
|
|
|
|
const Theme& th,
|
|
|
|
ContactTextureCache& contact_tc,
|
|
|
|
const Contact3Handle c,
|
|
|
|
ImVec2 box
|
|
|
|
) {
|
2024-04-23 10:38:42 +02:00
|
|
|
// deploy dummy of same size and check visibility
|
|
|
|
const auto orig_curser_pos = ImGui::GetCursorPos();
|
|
|
|
ImGui::Dummy(box);
|
|
|
|
if (ImGui::IsItemVisible()) {
|
|
|
|
ImGui::SetCursorPos(orig_curser_pos); // reset for actual img
|
2024-04-21 20:24:01 +02:00
|
|
|
|
2024-04-23 10:38:42 +02:00
|
|
|
ImVec4 color_current = th.getColor<ThemeCol_Contact::avatar_offline>();
|
|
|
|
if (c.all_of<Contact::Components::ConnectionState>()) {
|
|
|
|
const auto c_state = c.get<Contact::Components::ConnectionState>().state;
|
|
|
|
if (c_state == Contact::Components::ConnectionState::State::direct) {
|
|
|
|
color_current = th.getColor<ThemeCol_Contact::avatar_online_direct>();
|
|
|
|
} else if (c_state == Contact::Components::ConnectionState::State::cloud) {
|
|
|
|
color_current = th.getColor<ThemeCol_Contact::avatar_online_cloud>();
|
|
|
|
}
|
|
|
|
}
|
2024-04-21 20:24:01 +02:00
|
|
|
|
2024-04-23 10:38:42 +02:00
|
|
|
// avatar
|
|
|
|
const auto [id, width, height] = contact_tc.get(c);
|
|
|
|
ImGui::Image(
|
|
|
|
id,
|
|
|
|
box,
|
|
|
|
{0, 0},
|
|
|
|
{1, 1},
|
|
|
|
{1, 1, 1, 1},
|
|
|
|
color_current
|
|
|
|
);
|
|
|
|
}
|
2024-04-21 20:24:01 +02:00
|
|
|
}
|
|
|
|
|
2024-04-21 14:17:50 +02:00
|
|
|
bool renderContactBig(
|
|
|
|
const Theme& th,
|
|
|
|
ContactTextureCache& contact_tc,
|
|
|
|
const Contact3Handle c,
|
2024-04-21 20:24:01 +02:00
|
|
|
int line_height,
|
2024-04-21 14:17:50 +02:00
|
|
|
const bool unread,
|
|
|
|
const bool selectable,
|
|
|
|
const bool selected
|
|
|
|
) {
|
2024-04-21 20:24:01 +02:00
|
|
|
if (line_height < 1) {
|
|
|
|
line_height = 1;
|
|
|
|
}
|
|
|
|
|
2024-04-21 14:17:50 +02:00
|
|
|
// we dont need ### bc there is no named prefix
|
|
|
|
auto label = "##" + std::to_string(entt::to_integral(c.entity()));
|
|
|
|
|
|
|
|
const bool request_incoming = c.all_of<Contact::Components::RequestIncoming>();
|
|
|
|
const bool request_outgoing = c.all_of<Contact::Components::TagRequestOutgoing>();
|
|
|
|
|
|
|
|
ImVec2 orig_curser_pos = ImGui::GetCursorPos();
|
|
|
|
// HACK: fake selected to make it draw a box for us
|
|
|
|
const bool show_selected = request_incoming || request_outgoing || selected;
|
|
|
|
if (request_incoming) {
|
|
|
|
ImGui::PushStyleColor(
|
|
|
|
ImGuiCol_Header,
|
|
|
|
th.getColor<ThemeCol_Contact::request_incoming>()
|
|
|
|
);
|
|
|
|
} else if (request_outgoing) {
|
|
|
|
ImGui::PushStyleColor(
|
|
|
|
ImGuiCol_Header,
|
|
|
|
th.getColor<ThemeCol_Contact::request_outgoing>()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const float TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing();
|
|
|
|
|
|
|
|
bool got_selected = false;
|
|
|
|
if (selectable) {
|
2024-04-21 20:24:01 +02:00
|
|
|
got_selected = ImGui::Selectable(label.c_str(), show_selected, ImGuiSelectableFlags_None, {0, line_height*TEXT_BASE_HEIGHT});
|
2024-04-21 14:17:50 +02:00
|
|
|
} else {
|
2024-04-21 20:24:01 +02:00
|
|
|
got_selected = ImGui::InvisibleButton(label.c_str(), {-FLT_MIN, line_height*TEXT_BASE_HEIGHT});
|
2024-04-21 14:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (request_incoming || request_outgoing) {
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
}
|
|
|
|
|
2024-04-21 20:24:01 +02:00
|
|
|
const auto* cstate = c.try_get<Contact::Components::ConnectionState>();
|
2024-04-21 14:17:50 +02:00
|
|
|
if (ImGui::BeginItemTooltip()) {
|
2024-04-21 20:24:01 +02:00
|
|
|
if (cstate != nullptr) {
|
2024-04-21 14:17:50 +02:00
|
|
|
ImGui::Text("Connection state: %s",
|
2024-04-21 20:24:01 +02:00
|
|
|
(cstate->state == Contact::Components::ConnectionState::disconnected)
|
2024-04-21 14:17:50 +02:00
|
|
|
? "offline"
|
2024-04-21 20:24:01 +02:00
|
|
|
: (cstate->state == Contact::Components::ConnectionState::direct)
|
2024-04-21 14:17:50 +02:00
|
|
|
? "online (direct)"
|
|
|
|
: "online (cloud)"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ImGui::TextUnformatted("Connection state: unknown");
|
|
|
|
}
|
|
|
|
|
2024-04-21 20:24:01 +02:00
|
|
|
// TODO: add a whole bunch more info
|
|
|
|
|
2024-04-21 14:17:50 +02:00
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImVec2 post_curser_pos = ImGui::GetCursorPos();
|
|
|
|
|
|
|
|
ImVec2 img_curser {
|
|
|
|
orig_curser_pos.x + ImGui::GetStyle().FramePadding.x,
|
|
|
|
orig_curser_pos.y + ImGui::GetStyle().FramePadding.y
|
|
|
|
};
|
|
|
|
|
2024-04-22 12:46:01 +02:00
|
|
|
float img_y {TEXT_BASE_HEIGHT*line_height - ImGui::GetStyle().FramePadding.y*2};
|
2024-04-21 14:17:50 +02:00
|
|
|
|
|
|
|
ImGui::SetCursorPos(img_curser);
|
|
|
|
|
2024-04-22 12:46:01 +02:00
|
|
|
renderAvatar(th, contact_tc, c, {img_y, img_y});
|
2024-04-21 14:17:50 +02:00
|
|
|
|
2024-04-23 11:24:24 +02:00
|
|
|
const float same_line_spacing = ImGui::GetStyle().ItemSpacing.x*0.5f;
|
|
|
|
ImGui::SameLine(0.f, same_line_spacing);
|
2024-04-21 14:17:50 +02:00
|
|
|
ImGui::BeginGroup();
|
|
|
|
{
|
2024-04-22 12:46:01 +02:00
|
|
|
{ // line 1
|
|
|
|
if (line_height == 1 && cstate != nullptr) {
|
|
|
|
// icon pos
|
|
|
|
auto p0 = ImGui::GetCursorScreenPos();
|
|
|
|
p0.y += ImGui::GetStyle().FramePadding.y;
|
|
|
|
ImVec2 p1_o = {img_y, img_y}; // img_y is 1 line_height in this case
|
|
|
|
|
2024-04-22 22:31:17 +02:00
|
|
|
const ImU32 col_back = ImGui::GetColorU32(th.getColor<ThemeCol_Contact::icon_backdrop>());
|
2024-04-22 12:46:01 +02:00
|
|
|
if (cstate->state == Contact::Components::ConnectionState::direct) { // direct icon
|
2024-04-22 22:31:17 +02:00
|
|
|
drawIconDirect(
|
|
|
|
p0,
|
|
|
|
p1_o,
|
|
|
|
ImGui::GetColorU32(th.getColor<ThemeCol_Contact::avatar_online_direct>()),
|
|
|
|
col_back
|
|
|
|
);
|
2024-04-22 12:46:01 +02:00
|
|
|
} else if (cstate->state == Contact::Components::ConnectionState::cloud) { // cloud icon
|
2024-04-22 22:31:17 +02:00
|
|
|
drawIconCloud(
|
|
|
|
p0,
|
|
|
|
p1_o,
|
|
|
|
ImGui::GetColorU32(th.getColor<ThemeCol_Contact::avatar_online_cloud>()),
|
|
|
|
col_back
|
|
|
|
);
|
2024-04-22 12:46:01 +02:00
|
|
|
}
|
|
|
|
ImGui::Dummy(p1_o);
|
2024-04-23 11:24:24 +02:00
|
|
|
ImGui::SameLine(0.f, same_line_spacing);
|
2024-04-22 12:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Text("%s%s", unread?"* ":"", (c.all_of<Contact::Components::Name>() ? c.get<Contact::Components::Name>().name.c_str() : "<unk>"));
|
|
|
|
}
|
2024-04-21 14:17:50 +02:00
|
|
|
|
2024-04-21 20:24:01 +02:00
|
|
|
// line 2
|
|
|
|
if (line_height >= 2) {
|
|
|
|
if (request_incoming) {
|
|
|
|
ImGui::TextUnformatted("Incoming request/invite");
|
|
|
|
} else if (request_outgoing) {
|
|
|
|
ImGui::TextUnformatted("Outgoing request/invite");
|
|
|
|
} else {
|
2024-04-22 12:46:01 +02:00
|
|
|
if (cstate != nullptr) {
|
|
|
|
// icon pos
|
|
|
|
auto p0 = ImGui::GetCursorScreenPos();
|
|
|
|
p0.y += ImGui::GetStyle().FramePadding.y;
|
|
|
|
const float box_hight = TEXT_BASE_HEIGHT - ImGui::GetStyle().FramePadding.y*2;
|
|
|
|
ImVec2 p1_o = {box_hight, box_hight};
|
|
|
|
|
2024-04-22 22:31:17 +02:00
|
|
|
const ImU32 col_back = ImGui::GetColorU32(th.getColor<ThemeCol_Contact::icon_backdrop>());
|
2024-04-22 12:46:01 +02:00
|
|
|
if (cstate->state == Contact::Components::ConnectionState::direct) { // direct icon
|
2024-04-22 22:31:17 +02:00
|
|
|
drawIconDirect(
|
|
|
|
p0,
|
|
|
|
p1_o,
|
|
|
|
ImGui::GetColorU32(th.getColor<ThemeCol_Contact::avatar_online_direct>()),
|
|
|
|
col_back
|
|
|
|
);
|
2024-04-22 12:46:01 +02:00
|
|
|
} else if (cstate->state == Contact::Components::ConnectionState::cloud) { // cloud icon
|
2024-04-22 22:31:17 +02:00
|
|
|
drawIconCloud(
|
|
|
|
p0,
|
|
|
|
p1_o,
|
|
|
|
ImGui::GetColorU32(th.getColor<ThemeCol_Contact::avatar_online_cloud>()),
|
|
|
|
col_back
|
|
|
|
);
|
2024-04-22 12:46:01 +02:00
|
|
|
}
|
|
|
|
ImGui::Dummy(p1_o);
|
2024-04-23 11:24:24 +02:00
|
|
|
ImGui::SameLine(0.f, same_line_spacing);
|
2024-04-22 12:46:01 +02:00
|
|
|
}
|
|
|
|
|
2024-04-22 22:31:17 +02:00
|
|
|
if (
|
|
|
|
const auto* slt = c.try_get<Contact::Components::StatusText>();
|
|
|
|
slt != nullptr &&
|
|
|
|
!slt->text.empty() &&
|
|
|
|
slt->first_line_length > 0 &&
|
|
|
|
slt->first_line_length <= slt->text.size()
|
|
|
|
) {
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
|
|
|
|
ImGui::TextUnformatted(slt->text.c_str(), slt->text.c_str() + slt->first_line_length);
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
} else {
|
|
|
|
ImGui::TextDisabled(""); // or dummy?
|
|
|
|
}
|
2024-04-21 20:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// line 3
|
|
|
|
//if (line_height >= 3) {
|
|
|
|
// constexpr std::string_view test_text{"text"};
|
|
|
|
// ImGui::RenderTextEllipsis(ImGui::GetWindowDrawList(), ImVec2{}, ImVec2{}, 1.f, 1.f, test_text.data(), test_text.data()+test_text.size(), nullptr);
|
|
|
|
//}
|
2024-04-21 14:17:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndGroup();
|
|
|
|
|
|
|
|
ImGui::SetCursorPos(post_curser_pos);
|
|
|
|
|
|
|
|
return got_selected;
|
|
|
|
}
|
|
|
|
|