Proper image rendering ux (#5)
* can draw from selection
* add light-weight render manager to render many images simultaneously
* [debug me] currently the image close button does not do
* the unselected image can be closed now
* can close images and manually open them on demand
* cosmetic
* image view stuff in render subdirectory
* cosmetic
* generate docs
* review
windows support
some cosmetics
💅 and pin libCZI module
This commit is contained in:
committed by
Maximilian Kueffner
parent
2990f3313d
commit
bce12b0bb4
+59
-6
@@ -1,13 +1,15 @@
|
||||
#include "MyApp.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <format>
|
||||
#include <memory>
|
||||
|
||||
#include "app_resources_default.h"
|
||||
#include "app_resources_local.h"
|
||||
#include "imaging/PixelariumImage.hpp"
|
||||
#include "imgui.h"
|
||||
#include "portable-file-dialogs.h"
|
||||
#include "app_resources_default.h"
|
||||
#include "app_resources_local.h"
|
||||
#include "rendering/RenderImageManager.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
using namespace pixelarium::imaging;
|
||||
@@ -35,17 +37,68 @@ void pixelarium::ui::MyApp::Run()
|
||||
{
|
||||
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
|
||||
if (image_listp_) this->ImageGalleryRender();
|
||||
|
||||
this->RenderImages();
|
||||
}
|
||||
|
||||
void pixelarium::ui::MyApp::RenderImages()
|
||||
{
|
||||
this->render_manager_->Enumerate(
|
||||
[&](resources::ResourceKey key, render::RenderImageStateWrapper& render_state)
|
||||
{
|
||||
render_state.view->ShowImage();
|
||||
|
||||
if (!*render_state.view->GetStatus())
|
||||
{
|
||||
this->render_manager_->MarkForDeletion(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void pixelarium::ui::MyApp::ImageGalleryRender()
|
||||
{
|
||||
if (ImGui::BeginListBox("ListBox"))
|
||||
ImGui::SetNextWindowSize(ImVec2(300, 500));
|
||||
ImGui::Begin(SHOWIMAGEGALLERY);
|
||||
|
||||
// this updates the render collection
|
||||
// essentially deleting render views that were
|
||||
// marked for deletion
|
||||
this->render_manager_->UpdateCollection();
|
||||
|
||||
static size_t selected_index{0};
|
||||
int highlight_index{-1};
|
||||
|
||||
if (ImGui::BeginListBox("Image List", ImVec2(200, 400)))
|
||||
{
|
||||
pool_.EnumerateResources([](size_t id, const imaging::PixelariumImage&) -> void
|
||||
{ ImGui::Selectable(std::format("Image {}", id).c_str()); });
|
||||
pool_.EnumerateResources(
|
||||
[&](size_t id, size_t idx, const imaging::PixelariumImage& img) -> void
|
||||
{
|
||||
const bool is_selected = selected_index == idx;
|
||||
if (ImGui::Selectable(std::format("{}", img.Name()).c_str(), is_selected))
|
||||
{
|
||||
selected_index = idx;
|
||||
this->selected_image_ = id;
|
||||
}
|
||||
if (highlight_index && ImGui::IsItemHovered()) highlight_index = idx;
|
||||
|
||||
if (is_selected) ImGui::SetItemDefaultFocus();
|
||||
});
|
||||
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
|
||||
ImGui::Checkbox(AUTOSHOWSELECTED, &this->auto_show_selectd_image_);
|
||||
ImGui::SameLine(); // put the button next to the checkbox
|
||||
// note that the button will only show when the checkbox is toggled off
|
||||
// this is intended behavior as the selected image will render automatically
|
||||
// when the checkbox is toggled on
|
||||
if (this->auto_show_selectd_image_ || ImGui::Button(OPENIMAGE))
|
||||
{
|
||||
// Try add the selected index to the manager
|
||||
this->render_manager_->Add(this->selected_image_);
|
||||
}
|
||||
|
||||
ImGui::End(); // end gallery window
|
||||
}
|
||||
|
||||
void pixelarium::ui::MyApp::LoadImageProt()
|
||||
@@ -56,6 +109,6 @@ void pixelarium::ui::MyApp::LoadImageProt()
|
||||
{
|
||||
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
||||
|
||||
last_id = image_view_model_->AddImage(std::make_unique<PixelariumImage>(p));
|
||||
pool_.SetResource(std::make_unique<PixelariumImage>(p));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user