Compare commits

...

2 Commits

4 changed files with 44 additions and 28 deletions

View File

@ -95,6 +95,12 @@ void renderAvatar(
const Contact3Handle c, const Contact3Handle c,
ImVec2 box ImVec2 box
) { ) {
// 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>(); ImVec4 color_current = th.getColor<ThemeCol_Contact::avatar_offline>();
if (c.all_of<Contact::Components::ConnectionState>()) { if (c.all_of<Contact::Components::ConnectionState>()) {
const auto c_state = c.get<Contact::Components::ConnectionState>().state; const auto c_state = c.get<Contact::Components::ConnectionState>().state;
@ -105,14 +111,6 @@ void renderAvatar(
} }
} }
// 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 // avatar
const auto [id, width, height] = contact_tc.get(c); const auto [id, width, height] = contact_tc.get(c);
ImGui::Image( ImGui::Image(
@ -123,7 +121,7 @@ void renderAvatar(
{1, 1, 1, 1}, {1, 1, 1, 1},
color_current color_current
); );
}
} }
bool renderContactBig( bool renderContactBig(

View File

@ -17,6 +17,13 @@ enum class ThemeCol_Contact {
icon_backdrop, 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 // returns true if clicked, if selectable, will highlight on hover and respect selected
// TODO: refine // TODO: refine
// +------+ // +------+

View File

@ -386,6 +386,10 @@ float ChatGui4::render(float time_delta) {
// name // name
if (ImGui::TableNextColumn()) { 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();
if (_cr.all_of<Contact::Components::Name>(c_from.c)) { if (_cr.all_of<Contact::Components::Name>(c_from.c)) {
ImGui::TextUnformatted(_cr.get<Contact::Components::Name>(c_from.c).name.c_str()); ImGui::TextUnformatted(_cr.get<Contact::Components::Name>(c_from.c).name.c_str());
} else { } else {

View File

@ -187,7 +187,8 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
if (!_cr.any_of< if (!_cr.any_of<
Contact::Components::ToxFriendPersistent, Contact::Components::ToxFriendPersistent,
Contact::Components::ToxGroupPersistent, Contact::Components::ToxGroupPersistent,
Contact::Components::ToxGroupPeerPersistent Contact::Components::ToxGroupPeerPersistent,
Contact::Components::ID
>(c)) { >(c)) {
return std::nullopt; 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); pixels = generateToxIdenticon(_cr.get<Contact::Components::ToxGroupPersistent>(c).chat_id);
} else if (_cr.all_of<Contact::Components::ToxGroupPeerPersistent>(c)) { } else if (_cr.all_of<Contact::Components::ToxGroupPeerPersistent>(c)) {
pixels = generateToxIdenticon(_cr.get<Contact::Components::ToxGroupPeerPersistent>(c).peer_key); 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; TextureEntry new_entry;