Compare commits

...

5 Commits

5 changed files with 64 additions and 35 deletions

View File

@ -95,35 +95,33 @@ void renderAvatar(
const Contact3Handle c,
ImVec2 box
) {
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>();
// 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
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>();
}
}
// avatar
const auto [id, width, height] = contact_tc.get(c);
ImGui::Image(
id,
box,
{0, 0},
{1, 1},
{1, 1, 1, 1},
color_current
);
}
// icon pos
auto p0 = ImGui::GetCursorScreenPos();
p0.x += box.x * 0.5f;
p0.y += box.y * 0.5f;
auto p1_o = box;
p1_o.x *= 0.5f;
p1_o.y *= 0.5f;
// avatar
const auto [id, width, height] = contact_tc.get(c);
ImGui::Image(
id,
box,
{0, 0},
{1, 1},
{1, 1, 1, 1},
color_current
);
}
bool renderContactBig(
@ -135,6 +133,7 @@ bool renderContactBig(
const bool selectable,
const bool selected
) {
ImGui::BeginGroup();
if (line_height < 1) {
line_height = 1;
}
@ -187,8 +186,18 @@ bool renderContactBig(
ImGui::TextUnformatted("Connection state: unknown");
}
// TODO: add a whole bunch more info
if (
const auto* slt = c.try_get<Contact::Components::StatusText>();
slt != nullptr &&
!slt->text.empty()
) {
ImGui::SeparatorText("Status Text");
//ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
ImGui::TextUnformatted(slt->text.c_str());
//ImGui::PopStyleColor();
}
// TODO: add a whole bunch more info
ImGui::EndTooltip();
}
@ -205,7 +214,8 @@ bool renderContactBig(
renderAvatar(th, contact_tc, c, {img_y, img_y});
ImGui::SameLine();
const float same_line_spacing = ImGui::GetStyle().ItemSpacing.x*0.5f;
ImGui::SameLine(0.f, same_line_spacing);
ImGui::BeginGroup();
{
{ // line 1
@ -232,7 +242,7 @@ bool renderContactBig(
);
}
ImGui::Dummy(p1_o);
ImGui::SameLine(0.f, ImGui::GetStyle().ItemSpacing.x*0.5f);
ImGui::SameLine(0.f, same_line_spacing);
}
ImGui::Text("%s%s", unread?"* ":"", (c.all_of<Contact::Components::Name>() ? c.get<Contact::Components::Name>().name.c_str() : "<unk>"));
@ -269,7 +279,7 @@ bool renderContactBig(
);
}
ImGui::Dummy(p1_o);
ImGui::SameLine(0.f, ImGui::GetStyle().ItemSpacing.x*0.5f);
ImGui::SameLine(0.f, same_line_spacing);
}
if (
@ -298,6 +308,7 @@ bool renderContactBig(
ImGui::SetCursorPos(post_curser_pos);
ImGui::EndGroup();
return got_selected;
}

View File

@ -17,6 +17,13 @@ enum class ThemeCol_Contact {
icon_backdrop,
};
void renderAvatar(
const Theme& th,
ContactTextureCache& contact_tc,
const Contact3Handle c,
ImVec2 box
);
// returns true if clicked, if selectable, will highlight on hover and respect selected
// TODO: refine
// +------+

View File

@ -227,7 +227,7 @@ float ChatGui4::render(float time_delta) {
if (sub_contacts != nullptr && !_cr.all_of<Contact::Components::TagPrivate>(*_selected_contact) && _cr.all_of<Contact::Components::TagGroup>(*_selected_contact)) {
if (!sub_contacts->empty()) {
if (ImGui::BeginChild("subcontacts", {175, -100}, true)) {
if (ImGui::BeginChild("subcontacts", {TEXT_BASE_WIDTH * 18.f, -100.f}, true)) {
ImGui::Text("subs: %zu", sub_contacts->size());
ImGui::Separator();
for (const auto& c : *sub_contacts) {
@ -298,7 +298,7 @@ float ChatGui4::render(float time_delta) {
ImGuiTableFlags_SizingFixedFit
;
if (msg_reg_ptr != nullptr && ImGui::BeginTable("chat_table", 5, table_flags)) {
ImGui::TableSetupColumn("name", 0, TEXT_BASE_WIDTH * 15.f);
ImGui::TableSetupColumn("name", 0, TEXT_BASE_WIDTH * 16.f);
ImGui::TableSetupColumn("message", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("delivered/read");
ImGui::TableSetupColumn("timestamp");
@ -386,6 +386,10 @@ float ChatGui4::render(float time_delta) {
// name
if (ImGui::TableNextColumn()) {
const float img_y {TEXT_BASE_HEIGHT - ImGui::GetStyle().FramePadding.y*2};
renderAvatar(_theme, _contact_tc, {_cr, c_from.c}, {img_y, img_y});
ImGui::SameLine(0.f, ImGui::GetStyle().ItemSpacing.x*0.5f);
if (_cr.all_of<Contact::Components::Name>(c_from.c)) {
ImGui::TextUnformatted(_cr.get<Contact::Components::Name>(c_from.c).name.c_str());
} else {

View File

@ -187,7 +187,8 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
if (!_cr.any_of<
Contact::Components::ToxFriendPersistent,
Contact::Components::ToxGroupPersistent,
Contact::Components::ToxGroupPeerPersistent
Contact::Components::ToxGroupPeerPersistent,
Contact::Components::ID
>(c)) {
return std::nullopt;
}
@ -199,6 +200,12 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
pixels = generateToxIdenticon(_cr.get<Contact::Components::ToxGroupPersistent>(c).chat_id);
} else if (_cr.all_of<Contact::Components::ToxGroupPeerPersistent>(c)) {
pixels = generateToxIdenticon(_cr.get<Contact::Components::ToxGroupPeerPersistent>(c).peer_key);
} else if (_cr.all_of<Contact::Components::ID>(c)) {
// TODO: should we really use toxidenticons for other protocols?
// (this is required for self)
auto id_copy = _cr.get<Contact::Components::ID>(c).data;
id_copy.resize(32);
pixels = generateToxIdenticon(id_copy);
}
TextureEntry new_entry;