image viewer popup when clicking an image in a message
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / linux (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / dumpsyms (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled

This commit is contained in:
Green Sky 2025-03-17 22:52:31 +01:00
parent 10ad2be8bf
commit 90a28d727b
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
7 changed files with 425 additions and 312 deletions

12
flake.lock generated
View File

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
@ -37,11 +37,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1720691131,
"narHash": "sha256-CWT+KN8aTPyMIx8P303gsVxUnkinIz0a/Cmasz1jyIM=",
"lastModified": 1735651292,
"narHash": "sha256-YLbzcBtYo1/FEzFsB3AnM16qFc6fWPMIoOuSoDwvg9g=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a046c1202e11b62cbede5385ba64908feb7bfac4",
"rev": "0da3c44a9460a26d2025ec3ed2ec60a895eb1114",
"type": "github"
},
"original": {

View File

@ -91,6 +91,8 @@ target_sources(tomato PUBLIC
./chat_gui/contact_list.cpp
./chat_gui/file_selector.hpp
./chat_gui/file_selector.cpp
./chat_gui/image_viewer_popup.hpp
./chat_gui/image_viewer_popup.cpp
./chat_gui/send_image_popup.hpp
./chat_gui/send_image_popup.cpp
./chat_gui/settings_window.hpp

View File

@ -0,0 +1,66 @@
#include "./image_viewer_popup.hpp"
#include <imgui/imgui.h>
#include <iostream>
ImageViewerPopup::ImageViewerPopup(MessageTextureCache& mtc) : _mtc(mtc) {
}
// open popup with (image) file
void ImageViewerPopup::view(Message3Handle m) {
if (static_cast<bool>(_m)) {
std::cout << "IVP warning: overriding open image\n";
}
_m = m;
_open_popup = true;
}
// call this each frame
void ImageViewerPopup::render(float) {
if (_open_popup) {
_open_popup = false;
ImGui::OpenPopup("Image##ImageViewerPopup");
}
if (!ImGui::BeginPopup("Image##ImageViewerPopup", ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize)) {
_m = {}; // meh, event on close would be nice, but the reset is cheap
_scale = 1.f;
return;
}
ImGui::SliderFloat("scale", &_scale, 0.05f, 2.f);
auto [id, img_width, img_height] = _mtc.get(_m);
img_width = std::max<int32_t>(5, _scale * img_width);
img_height = std::max<int32_t>(5, _scale * img_height);
ImGui::Image(
id,
ImVec2{
static_cast<float>(img_width),
static_cast<float>(img_height)
}
);
// TODO: figure out nice scroll zooming
//ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);
//const auto prev_scale = _scale;
//_scale += ImGui::GetIO().MouseWheel * 0.05f;
//_scale = std::clamp(_scale, 0.05f, 3.f);
//if (std::abs(prev_scale - _scale) > 0.001f) {
//}
if (ImGui::Shortcut(ImGuiKey_Escape)) {
ImGui::CloseCurrentPopup();
_m = {};
_scale = 1.f;
}
ImGui::EndPopup();
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <solanaceae/message3/registry_message_model.hpp>
#include "./texture_cache_defs.hpp"
#include <entt/entity/registry.hpp>
#include <entt/entity/handle.hpp>
struct ImageViewerPopup {
MessageTextureCache& _mtc;
Message3Handle _m{};
float _scale {1.f};
bool _open_popup {false};
//void reset(void);
public:
ImageViewerPopup(MessageTextureCache& mtc);
// open popup with (image) message
//void view(ObjectHandle o);
void view(Message3Handle m);
// call this each frame
void render(float time_delta);
// TODO: events (destroy/update)
};

View File

@ -219,7 +219,10 @@ void SendImagePopup::render(float time_delta) {
}
// TODO: add cancel shortcut (esc)
if (ImGui::BeginPopupModal("send image##SendImagePopup", nullptr/*, ImGuiWindowFlags_NoDecoration*/)) {
if (!ImGui::BeginPopupModal("send image##SendImagePopup", nullptr/*, ImGuiWindowFlags_NoDecoration*/)) {
return;
}
//const auto TEXT_BASE_WIDTH = ImGui::CalcTextSize("A").x;
const auto TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing();
@ -551,7 +554,11 @@ void SendImagePopup::render(float time_delta) {
reset();
}
ImGui::EndPopup();
if (ImGui::Shortcut(ImGuiKey_Escape)) {
ImGui::CloseCurrentPopup();
reset();
}
ImGui::EndPopup();
}

View File

@ -201,7 +201,8 @@ ChatGui4::ChatGui4(
_msg_tc(msg_tc),
_b_tc(_bil, tu),
_theme(theme),
_sip(tu)
_sip(tu),
_ivp(_msg_tc)
{
_os_sr.subscribe(ObjectStore_Event::object_update);
}
@ -220,6 +221,7 @@ ChatGui4::~ChatGui4(void) {
float ChatGui4::render(float time_delta, bool window_hidden, bool window_focused) {
_fss.render();
_sip.render(time_delta);
_ivp.render(time_delta);
_b_tc.update();
_b_tc.workLoadQueue();
@ -1330,7 +1332,9 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
{0.5f, 0.5f, 0.5f, 0.8f} // border
);
// TODO: clickable to open in internal image viewer
if (ImGui::IsItemClicked()) {
_ivp.view(Message3Handle{reg, e});
}
}
} else if (o.all_of<ObjComp::F::SingleInfo>()) { // only show info if not inlined image
// just filename

View File

@ -14,6 +14,7 @@
#include "./bitset_image_loader.hpp"
#include "./chat_gui/file_selector.hpp"
#include "./chat_gui/send_image_popup.hpp"
#include "./chat_gui/image_viewer_popup.hpp"
#include <entt/container/dense_map.hpp>
@ -39,6 +40,7 @@ class ChatGui4 : public ObjectStoreEventI {
FileSelector _fss;
SendImagePopup _sip;
ImageViewerPopup _ivp;
// TODO: refactor this to allow multiple open contacts
std::optional<Contact4> _selected_contact;