Plan app dialog factories

This commit is contained in:
2026-06-05 07:36:56 +02:00
parent a79ef4cda8
commit 062fdaa982
9 changed files with 374 additions and 12 deletions

78
src/app_core/app_dialog.h Normal file
View File

@@ -0,0 +1,78 @@
#pragma once
#include "foundation/result.h"
#include <string>
#include <string_view>
namespace pp::app {
enum class AppDialogKind {
progress,
message,
input,
};
struct AppProgressDialogPlan {
std::string title;
int total = 0;
int count = 0;
float progress_fraction = 0.0F;
};
struct AppMessageDialogPlan {
std::string title;
std::string message;
std::string ok_caption = "Ok";
bool show_cancel = false;
};
struct AppInputDialogPlan {
std::string title;
std::string field_name;
std::string ok_caption = "Ok";
};
[[nodiscard]] inline AppProgressDialogPlan plan_app_progress_dialog(
std::string_view title,
int total) noexcept
{
return {
std::string(title),
total < 0 ? 0 : total,
0,
0.0F,
};
}
[[nodiscard]] inline AppMessageDialogPlan plan_app_message_dialog(
std::string_view title,
std::string_view message,
bool show_cancel)
{
return {
std::string(title),
std::string(message),
"Ok",
show_cancel,
};
}
[[nodiscard]] inline pp::foundation::Result<AppInputDialogPlan> plan_app_input_dialog(
std::string_view title,
std::string_view field_name,
std::string_view ok_caption)
{
if (ok_caption.empty()) {
return pp::foundation::Result<AppInputDialogPlan>::failure(
pp::foundation::Status::invalid_argument("input dialog ok caption must not be empty"));
}
return pp::foundation::Result<AppInputDialogPlan>::success({
std::string(title),
std::string(field_name),
std::string(ok_caption),
});
}
} // namespace pp::app