Plan app dialog factories
This commit is contained in:
78
src/app_core/app_dialog.h
Normal file
78
src/app_core/app_dialog.h
Normal 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
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
#include "app_core/app_dialog.h"
|
||||
#include "app_core/document_layer.h"
|
||||
#include "app_core/document_resize.h"
|
||||
#include "app_core/document_export.h"
|
||||
@@ -108,30 +109,32 @@ void start_document_export_collection(
|
||||
|
||||
std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title, int total /*= 0*/)
|
||||
{
|
||||
const auto plan = pp::app::plan_app_progress_dialog(title, total);
|
||||
auto pb = std::make_shared<NodeProgressBar>();
|
||||
pb->set_manager(&layout);
|
||||
pb->init();
|
||||
pb->create();
|
||||
pb->loaded();
|
||||
pb->m_progress->SetWidthP(0);
|
||||
pb->m_title->set_text(title.c_str());
|
||||
pb->m_total = total;
|
||||
pb->m_count = 0;
|
||||
pb->m_progress->SetWidthP(plan.progress_fraction);
|
||||
pb->m_title->set_text(plan.title.c_str());
|
||||
pb->m_total = plan.total;
|
||||
pb->m_count = plan.count;
|
||||
layout[main_id]->add_child(pb);
|
||||
return pb;
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const std::string& text, bool cancel_button)
|
||||
{
|
||||
const auto plan = pp::app::plan_app_message_dialog(title, text, cancel_button);
|
||||
auto m = std::make_shared<NodeMessageBox>();
|
||||
m->set_manager(&layout);
|
||||
m->init();
|
||||
m->create();
|
||||
m->loaded();
|
||||
m->m_title->set_text(title.c_str());
|
||||
m->m_message->set_text(text.c_str());
|
||||
m->btn_ok->m_text->set_text("Ok");
|
||||
if (!cancel_button)
|
||||
m->m_title->set_text(plan.title.c_str());
|
||||
m->m_message->set_text(plan.message.c_str());
|
||||
m->btn_ok->m_text->set_text(plan.ok_caption.c_str());
|
||||
if (!plan.show_cancel)
|
||||
m->btn_cancel->destroy();
|
||||
layout[main_id]->add_child(m);
|
||||
return m;
|
||||
@@ -140,14 +143,20 @@ std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const
|
||||
std::shared_ptr<NodeInputBox> App::input_box(const std::string& title,
|
||||
const std::string& field_name, const std::string& ok_caption /*= "Ok"*/)
|
||||
{
|
||||
const auto plan_result = pp::app::plan_app_input_dialog(title, field_name, ok_caption);
|
||||
if (!plan_result) {
|
||||
LOG("input dialog skipped: %s", plan_result.status().message);
|
||||
return nullptr;
|
||||
}
|
||||
const auto& plan = plan_result.value();
|
||||
auto m = std::make_shared<NodeInputBox>();
|
||||
m->set_manager(&layout);
|
||||
m->init();
|
||||
m->create();
|
||||
m->loaded();
|
||||
m->m_title->set_text(title.c_str());
|
||||
m->m_field_name->set_text(field_name.c_str());
|
||||
m->btn_ok->m_text->set_text(ok_caption.c_str());
|
||||
m->m_title->set_text(plan.title.c_str());
|
||||
m->m_field_name->set_text(plan.field_name.c_str());
|
||||
m->btn_ok->m_text->set_text(plan.ok_caption.c_str());
|
||||
layout[main_id]->add_child(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user