yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
workflow_activity_widgets.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include <algorithm>
5#include <ctime>
6
9
10namespace yaze::editor::workflow {
11namespace {
12
15 rect.visible = true;
16 rect.id = ImGui::GetItemID();
17 rect.min = ImGui::GetItemRectMin();
18 rect.max = ImGui::GetItemRectMax();
19 return rect;
20}
21
22bool DrawWorkflowActionButton(const char* button_label, const char* tooltip,
23 const std::function<void()>& callback,
24 WorkflowButtonRect* rect) {
25 if (!callback) {
26 return false;
27 }
28 if (ImGui::SmallButton(button_label)) {
29 if (rect != nullptr) {
30 *rect = LastItemRect();
31 }
32 callback();
33 return true;
34 }
35 if (rect != nullptr) {
36 *rect = LastItemRect();
37 }
38 ImGui::SetItemTooltip("%s", tooltip);
39 return false;
40}
41
42} // namespace
43
44std::string FormatHistoryTime(std::chrono::system_clock::time_point timestamp) {
45 const std::time_t raw = std::chrono::system_clock::to_time_t(timestamp);
46 std::tm local_tm{};
47#if defined(_WIN32)
48 localtime_s(&local_tm, &raw);
49#else
50 localtime_r(&raw, &local_tm);
51#endif
52 char buffer[64];
53 std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &local_tm);
54 return std::string(buffer);
55}
56
58 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
59 switch (state) {
61 return gui::ConvertColorToImVec4(theme.info);
63 return gui::ConvertColorToImVec4(theme.success);
65 return gui::ConvertColorToImVec4(theme.error);
67 default:
69 }
70}
71
72const char* WorkflowIcon(const ProjectWorkflowStatus& status,
73 const char* fallback_icon) {
74 switch (status.state) {
76 return ICON_MD_SYNC;
80 return ICON_MD_ERROR;
82 default:
83 return fallback_icon;
84 }
85}
86
87std::string BuildCopyPayload(const ProjectWorkflowStatus& status,
88 const std::string& output_log) {
89 if (!output_log.empty()) {
90 return output_log;
91 }
92
93 std::string payload = status.summary.empty() ? status.label : status.summary;
94 if (!status.detail.empty()) {
95 if (!payload.empty()) {
96 payload.append("\n");
97 }
98 payload.append(status.detail);
99 }
100 if (!status.output_tail.empty()) {
101 if (!payload.empty()) {
102 payload.append("\n");
103 }
104 payload.append(status.output_tail);
105 }
106 return payload;
107}
108
109WorkflowButtonRect DrawCopyCurrentLogButton(const std::string& build_log) {
111 if (build_log.empty()) {
112 return rect;
113 }
114 if (ImGui::SmallButton(tr("Copy Current Log##workflow_copy_current_log"))) {
115 rect = LastItemRect();
116 ImGui::SetClipboardText(build_log.c_str());
117 return rect;
118 }
119 rect = LastItemRect();
120 return rect;
121}
122
124 const ProjectWorkflowHistoryEntry& entry,
125 const WorkflowActionCallbacks& callbacks,
126 const WorkflowActionRowOptions& options) {
128 bool drew_action = false;
129
130 if (options.show_open_output && callbacks.show_output) {
131 drew_action = true;
132 DrawWorkflowActionButton("Open Output##workflow_open_output",
133 "Open the Workflow Output panel",
134 callbacks.show_output, &result.open_output);
135 }
136
137 if (entry.kind == "Build" && callbacks.start_build) {
138 if (drew_action) {
139 ImGui::SameLine();
140 }
141 drew_action = true;
142 DrawWorkflowActionButton("Rebuild##workflow_rebuild", "Rebuild project",
143 callbacks.start_build, &result.primary_action);
144 } else if (entry.kind == "Run" && callbacks.run_project) {
145 if (drew_action) {
146 ImGui::SameLine();
147 }
148 drew_action = true;
149 DrawWorkflowActionButton("Run Again##workflow_run_again",
150 "Run project output again", callbacks.run_project,
151 &result.primary_action);
152 }
153
154 const std::string copy_payload =
155 BuildCopyPayload(entry.status, entry.output_log);
156 if (options.show_copy_log && !copy_payload.empty()) {
157 if (drew_action) {
158 ImGui::SameLine();
159 }
160 if (ImGui::SmallButton(tr("Copy Log##workflow_copy_log"))) {
161 result.copy_log = LastItemRect();
162 ImGui::SetClipboardText(copy_payload.c_str());
163 } else {
164 result.copy_log = LastItemRect();
165 }
166 }
167
168 return result;
169}
170
171std::vector<ProjectWorkflowHistoryEntry> SelectWorkflowPreviewEntries(
172 const std::vector<ProjectWorkflowHistoryEntry>& history,
173 size_t max_entries) {
174 if (max_entries == 0 || history.empty()) {
175 return {};
176 }
177 const size_t count = std::min(history.size(), max_entries);
178 return std::vector<ProjectWorkflowHistoryEntry>(history.begin(),
179 history.begin() + count);
180}
181
182} // namespace yaze::editor::workflow
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
#define ICON_MD_ERROR
Definition icons.h:686
#define ICON_MD_CHECK_CIRCLE
Definition icons.h:400
#define ICON_MD_SYNC
Definition icons.h:1919
bool DrawWorkflowActionButton(const char *button_label, const char *tooltip, const std::function< void()> &callback, WorkflowButtonRect *rect)
WorkflowButtonRect DrawCopyCurrentLogButton(const std::string &build_log)
std::string FormatHistoryTime(std::chrono::system_clock::time_point timestamp)
const char * WorkflowIcon(const ProjectWorkflowStatus &status, const char *fallback_icon)
std::string BuildCopyPayload(const ProjectWorkflowStatus &status, const std::string &output_log)
WorkflowActionRowResult DrawHistoryActionRow(const ProjectWorkflowHistoryEntry &entry, const WorkflowActionCallbacks &callbacks, const WorkflowActionRowOptions &options)
std::vector< ProjectWorkflowHistoryEntry > SelectWorkflowPreviewEntries(const std::vector< ProjectWorkflowHistoryEntry > &history, size_t max_entries)
ImVec4 WorkflowColor(ProjectWorkflowState state)
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:134
ImVec4 GetTextSecondaryVec4()