Extract document resize planning

This commit is contained in:
2026-06-03 10:03:34 +02:00
parent 21c448d6f1
commit 5d5bb24711
9 changed files with 226 additions and 7 deletions

View File

@@ -0,0 +1,57 @@
#pragma once
#include "app_core/app_status.h"
#include "foundation/result.h"
#include <string>
#include <string_view>
namespace pp::app {
struct DocumentResizeDialogState {
int current_resolution = 0;
std::string current_resolution_text;
int current_resolution_index = 0;
};
struct DocumentResizePlan {
int resolution = 0;
int width = 0;
int height = 0;
bool clears_history = false;
};
[[nodiscard]] inline DocumentResizeDialogState make_document_resize_dialog_state(
int current_resolution)
{
const auto label = document_resolution_label(current_resolution);
const auto index = document_resolution_to_index(current_resolution);
std::string text = "Current: ";
text.append(label ? std::string_view(label.value()) : std::string_view("unknown"));
return {
current_resolution,
text,
index ? static_cast<int>(index.value()) : static_cast<int>(document_resolution_values.size()),
};
}
[[nodiscard]] inline pp::foundation::Result<DocumentResizePlan> plan_document_resize(
int selected_resolution_index)
{
const auto resolution = display_resolution_from_index(selected_resolution_index);
if (!resolution) {
return pp::foundation::Result<DocumentResizePlan>::failure(resolution.status());
}
const auto value = resolution.value();
return pp::foundation::Result<DocumentResizePlan>::success(
DocumentResizePlan {
value,
value,
value,
true,
});
}
}