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
3#include <algorithm>
4#include <ctime>
5
8
10namespace {
11
14 rect.visible = true;
15 rect.id = ImGui::GetItemID();
16 rect.min = ImGui::GetItemRectMin();
17 rect.max = ImGui::GetItemRectMax();
18 return rect;
19}
20
21bool DrawWorkflowActionButton(const char* button_label, const char* tooltip,
22 const std::function<void()>& callback,
23 WorkflowButtonRect* rect) {
24 if (!callback) {
25 return false;
26 }
27 if (ImGui::SmallButton(button_label)) {
28 if (rect != nullptr) {
29 *rect = LastItemRect();
30 }
31 callback();
32 return true;
33 }
34 if (rect != nullptr) {
35 *rect = LastItemRect();
36 }
37 ImGui::SetItemTooltip("%s", tooltip);
38 return false;
39}
40
41} // namespace
42
44 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("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(
133 "Open Output##workflow_open_output",
134 "Open the Workflow Output panel", callbacks.show_output,
135 &result.open_output);
136 }
137
138 if (entry.kind == "Build" && callbacks.start_build) {
139 if (drew_action) {
140 ImGui::SameLine();
141 }
142 drew_action = true;
143 DrawWorkflowActionButton(
144 "Rebuild##workflow_rebuild", "Rebuild project",
145 callbacks.start_build, &result.primary_action);
146 } else if (entry.kind == "Run" && callbacks.run_project) {
147 if (drew_action) {
148 ImGui::SameLine();
149 }
150 drew_action = true;
151 DrawWorkflowActionButton(
152 "Run Again##workflow_run_again",
153 "Run project output again", callbacks.run_project,
154 &result.primary_action);
155 }
156
157 const std::string copy_payload =
158 BuildCopyPayload(entry.status, entry.output_log);
159 if (options.show_copy_log && !copy_payload.empty()) {
160 if (drew_action) {
161 ImGui::SameLine();
162 }
163 if (ImGui::SmallButton("Copy Log##workflow_copy_log")) {
164 result.copy_log = LastItemRect();
165 ImGui::SetClipboardText(copy_payload.c_str());
166 } else {
167 result.copy_log = LastItemRect();
168 }
169 }
170
171 return result;
172}
173
174std::vector<ProjectWorkflowHistoryEntry> SelectWorkflowPreviewEntries(
175 const std::vector<ProjectWorkflowHistoryEntry>& history,
176 size_t max_entries) {
177 if (max_entries == 0 || history.empty()) {
178 return {};
179 }
180 const size_t count = std::min(history.size(), max_entries);
181 return std::vector<ProjectWorkflowHistoryEntry>(history.begin(),
182 history.begin() + count);
183}
184
185} // 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()