chat gui refactor and first contact sorting

This commit is contained in:
Green Sky
2025-03-21 16:16:02 +01:00
parent c383c4f5a0
commit 1fb590dfc1
4 changed files with 200 additions and 65 deletions

View File

@ -1,12 +1,15 @@
#include "./contact_list.hpp"
#include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/util/utils.hpp>
#include <solanaceae/util/time.hpp>
#include <imgui/imgui.h>
//#include <imgui/imgui_internal.h>
#include <entt/entity/runtime_view.hpp>
#include "./icons/direct.hpp"
#include "./icons/cloud.hpp"
#include "./icons/mail.hpp"
@ -312,3 +315,36 @@ bool renderContactBig(
return got_selected;
}
bool renderContactList(
ContactRegistry4& cr,
RegistryMessageModelI& rmm,
const Theme& th,
ContactTextureCache& contact_tc,
const contact_const_runtime_view& view,
// in/out
ContactHandle4& selected_c
) {
bool selection_changed {false};
for (const Contact4 cv : view) {
ContactHandle4 c{cr, cv};
const bool selected = selected_c == c;
// TODO: is there a better way?
// maybe cache mm?
bool has_unread = false;
if (const auto* mm = rmm.get(c); mm != nullptr) {
if (const auto* unread_storage = mm->storage<Message::Components::TagUnread>(); unread_storage != nullptr && !unread_storage->empty()) {
has_unread = true;
}
}
// TODO: expose line_height
if (renderContactBig(th, contact_tc, c, 2, has_unread, true, selected)) {
selected_c = c;
selection_changed = true;
}
}
return selection_changed;
}

View File

@ -46,3 +46,19 @@ bool renderContactBig(
const bool selected = false
);
using contact_sparse_set = entt::basic_sparse_set<Contact4>;
using contact_runtime_view = entt::basic_runtime_view<contact_sparse_set>;
using contact_const_runtime_view = entt::basic_runtime_view<const contact_sparse_set>;
// returns true if contact was selected
bool renderContactList(
ContactRegistry4& cr,
RegistryMessageModelI& rmm,
const Theme& th,
ContactTextureCache& contact_tc,
const contact_const_runtime_view& view,
// in/out
ContactHandle4& selected_c
);