yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dashboard_panel.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include <algorithm>
5#include <cfloat>
6#include <fstream>
7#include <sstream>
8
9#include "absl/strings/str_cat.h"
10#include "absl/strings/str_format.h"
12#include "app/gui/core/color.h"
13#include "app/gui/core/icons.h"
15#include "app/gui/core/style.h"
19#include "imgui/imgui.h"
20#include "imgui/imgui_internal.h"
21#include "rom/rom.h"
22#include "util/file_util.h"
23
24namespace yaze {
25namespace editor {
26
27namespace {
28
29constexpr float kDashboardCardBaseWidth = 180.0f;
30constexpr float kDashboardCardBaseHeight = 120.0f;
31constexpr float kDashboardCardWidthMaxFactor = 1.35f;
32constexpr float kDashboardCardHeightMaxFactor = 1.35f;
33constexpr float kDashboardCardMinWidthFactor = 0.9f;
34constexpr float kDashboardCardMinHeightFactor = 0.9f;
35constexpr int kDashboardMaxColumns = 5;
36constexpr float kDashboardRecentBaseWidth = 150.0f;
37constexpr float kDashboardRecentBaseHeight = 35.0f;
38constexpr float kDashboardRecentWidthMaxFactor = 1.3f;
40
41struct FlowLayout {
42 int columns = 1;
43 float item_width = 0.0f;
44 float item_height = 0.0f;
45 float spacing = 0.0f;
46};
47
48FlowLayout ComputeFlowLayout(float avail_width, float min_width,
49 float max_width, float min_height,
50 float max_height, float aspect_ratio,
51 float spacing, int max_columns, int item_count) {
52 FlowLayout layout;
53 layout.spacing = spacing;
54 if (avail_width <= 0.0f) {
55 layout.columns = 1;
56 layout.item_width = min_width;
57 layout.item_height = min_height;
58 return layout;
59 }
60
61 const int clamped_max =
62 std::max(1, max_columns > 0 ? max_columns : item_count);
63 const auto width_for_columns = [avail_width, spacing](int columns) {
64 return (avail_width - spacing * static_cast<float>(columns - 1)) /
65 static_cast<float>(columns);
66 };
67
68 int columns = std::max(
69 1, static_cast<int>((avail_width + spacing) / (min_width + spacing)));
70 columns = std::min(columns, clamped_max);
71 if (item_count > 0) {
72 columns = std::min(columns, item_count);
73 }
74 columns = std::max(columns, 1);
75
76 float width = width_for_columns(columns);
77 while (columns < clamped_max && width > max_width) {
78 columns += 1;
79 width = width_for_columns(columns);
80 }
81
82 const float clamped_max_width = std::min(max_width, avail_width);
83 const float clamped_min_width = std::min(min_width, clamped_max_width);
84 layout.item_width = std::clamp(width, clamped_min_width, clamped_max_width);
85 layout.item_height =
86 std::clamp(layout.item_width * aspect_ratio, min_height, max_height);
87
88 layout.columns = columns;
89
90 return layout;
91}
92
93ImVec4 ScaleColor(const ImVec4& color, float scale, float alpha) {
94 return ImVec4(color.x * scale, color.y * scale, color.z * scale, alpha);
95}
96
97ImVec4 ScaleColor(const ImVec4& color, float scale) {
98 return ScaleColor(color, scale, color.w);
99}
100
101ImVec4 WithAlpha(ImVec4 color, float alpha) {
102 color.w = alpha;
103 return color;
104}
105
106ImVec4 GetEditorAccentColor(EditorType type, const gui::Theme& theme) {
107 switch (type) {
115 return gui::ConvertColorToImVec4(theme.info);
119 return gui::ConvertColorToImVec4(theme.accent);
121 return gui::ConvertColorToImVec4(theme.error);
123 return gui::ConvertColorToImVec4(theme.info);
126 case EditorType::kHex:
129 return gui::ConvertColorToImVec4(theme.info);
131 return gui::ConvertColorToImVec4(theme.accent);
134 default:
136 }
137}
138
139} // namespace
140
142 : editor_switcher_(editor_switcher),
143 window_("Dashboard", ICON_MD_DASHBOARD) {
145 window_.SetDefaultSize(950, 650);
147
148 // Use platform-aware shortcut strings (Cmd on macOS, Ctrl elsewhere)
149 const char* ctrl = gui::GetCtrlDisplayName();
150 editors_ = {
151 {"Overworld", ICON_MD_MAP,
152 "Edit overworld maps, entrances, and properties",
153 absl::StrFormat("%s+1", ctrl), EditorType::kOverworld},
154 {"Dungeon", ICON_MD_CASTLE,
155 "Design dungeon rooms, layouts, and mechanics",
156 absl::StrFormat("%s+2", ctrl), EditorType::kDungeon},
157 {"Graphics", ICON_MD_PALETTE, "Modify tiles, palettes, and graphics sets",
158 absl::StrFormat("%s+3", ctrl), EditorType::kGraphics},
159 {"Sprites", ICON_MD_EMOJI_EMOTIONS, "Edit sprite graphics and properties",
160 absl::StrFormat("%s+4", ctrl), EditorType::kSprite},
161 {"Messages", ICON_MD_CHAT_BUBBLE, "Edit dialogue, signs, and text",
162 absl::StrFormat("%s+5", ctrl), EditorType::kMessage},
163 {"Music", ICON_MD_MUSIC_NOTE, "Configure music and sound effects",
164 absl::StrFormat("%s+6", ctrl), EditorType::kMusic},
165 {"Palettes", ICON_MD_COLOR_LENS, "Edit color palettes and animations",
166 absl::StrFormat("%s+7", ctrl), EditorType::kPalette},
167 {"Screens", ICON_MD_TV, "Edit title screen and ending screens",
168 absl::StrFormat("%s+8", ctrl), EditorType::kScreen},
169 {"Assembly", ICON_MD_CODE, "Write and edit assembly code",
170 absl::StrFormat("%s+9", ctrl), EditorType::kAssembly},
171 {"Hex Editor", ICON_MD_DATA_ARRAY,
172 "Direct ROM memory editing and comparison",
173 absl::StrFormat("%s+0", ctrl), EditorType::kHex},
174 {"Emulator", ICON_MD_VIDEOGAME_ASSET,
175 "Test and debug your ROM in real-time",
176 absl::StrFormat("%s+Shift+E", ctrl), EditorType::kEmulator},
177 {"AI Agent", ICON_MD_SMART_TOY,
178 "Configure AI agent, collaboration, and automation",
179 absl::StrFormat("%s+Shift+A", ctrl), EditorType::kAgent, false, false},
180 };
181
183}
184
186 if (!show_)
187 return;
188
189 // Set window properties immediately before Begin
190 ImGuiViewport* viewport = ImGui::GetMainViewport();
191 ImVec2 center = viewport->GetCenter();
192 ImVec2 view_size = viewport->WorkSize;
193 float target_width = std::clamp(view_size.x * 0.9f, 520.0f, 1000.0f);
194 float target_height = std::clamp(view_size.y * 0.88f, 420.0f, 780.0f);
195 ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
196 ImGui::SetNextWindowSize(ImVec2(target_width, target_height),
197 ImGuiCond_Appearing);
198 ImGui::SetNextWindowSizeConstraints(
199 ImVec2(420.0f, 360.0f), ImVec2(view_size.x * 0.98f, view_size.y * 0.95f));
200
203
204 if (window_.Begin(&show_)) {
206 ImGui::Separator();
207 ImGui::Spacing();
208
209 if (!has_rom_) {
210 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
211 ImVec4 info_color = gui::ConvertColorToImVec4(theme.text_secondary);
212 ImGui::TextColored(info_color,
213 ICON_MD_INFO " Load a ROM to enable editors.");
214 ImGui::Spacing();
215 }
216
218 if (!recent_editors_.empty()) {
219 ImGui::Separator();
220 ImGui::Spacing();
221 }
223 }
224 window_.End();
225}
226
228 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
229 const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
230 const ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
231
232 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[2]); // Large font
233 ImGui::TextColored(accent, ICON_MD_EDIT " Select an Editor");
234 ImGui::PopFont();
235
236 ImGui::TextColored(text_secondary,
237 tr("Choose an editor to begin working on your ROM. "
238 "You can open multiple editors simultaneously."));
239}
240
242 if (recent_editors_.empty())
243 return;
244
245 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
246 const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
247 ImGui::TextColored(accent, ICON_MD_HISTORY " Recently Used");
248 ImGui::Spacing();
249
250 const ImGuiStyle& style = ImGui::GetStyle();
251 const float avail_width = ImGui::GetContentRegionAvail().x;
252 const float min_width = kDashboardRecentBaseWidth;
253 const float max_width =
254 kDashboardRecentBaseWidth * kDashboardRecentWidthMaxFactor;
255 const float height =
256 std::max(kDashboardRecentBaseHeight, ImGui::GetFrameHeight());
257 const float spacing = style.ItemSpacing.x;
258 const bool stack_items = avail_width < min_width * 1.6f;
259 FlowLayout row_layout{};
260 if (stack_items) {
261 row_layout.columns = 1;
262 row_layout.item_width = avail_width;
263 row_layout.item_height = height;
264 row_layout.spacing = spacing;
265 } else {
266 row_layout = ComputeFlowLayout(avail_width, min_width, max_width, height,
267 height, height / std::max(min_width, 1.0f),
268 spacing, kDashboardMaxRecentColumns,
269 static_cast<int>(recent_editors_.size()));
270 }
271
272 ImGuiTableFlags table_flags =
273 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
274 const ImVec2 cell_padding(row_layout.spacing * 0.5f,
275 style.ItemSpacing.y * 0.4f);
276 gui::StyleVarGuard cell_var_guard(ImGuiStyleVar_CellPadding, cell_padding);
277 if (ImGui::BeginTable("DashboardRecentGrid", row_layout.columns,
278 table_flags)) {
279 for (EditorType type : recent_editors_) {
280 // Find editor info
281 auto it = std::find_if(
282 editors_.begin(), editors_.end(),
283 [type](const EditorInfo& info) { return info.type == type; });
284
285 if (it == editors_.end()) {
286 continue;
287 }
288
289 ImGui::TableNextColumn();
290
291 const bool enabled = has_rom_ || !it->requires_rom;
292 const float alpha = enabled ? 1.0f : 0.35f;
293 const ImVec4 base_color = GetEditorAccentColor(it->type, theme);
294 gui::StyleColorGuard btn_guard(
295 {{ImGuiCol_Button, ScaleColor(base_color, 0.5f, 0.7f * alpha)},
296 {ImGuiCol_ButtonHovered, ScaleColor(base_color, 0.7f, 0.9f * alpha)},
297 {ImGuiCol_ButtonActive, WithAlpha(base_color, 1.0f * alpha)}});
298
299 ImVec2 button_size(
300 stack_items ? avail_width : row_layout.item_width,
301 row_layout.item_height > 0.0f ? row_layout.item_height : height);
302 if (!enabled) {
303 ImGui::BeginDisabled();
304 }
305 if (ImGui::Button(absl::StrCat(it->icon, " ", it->name).c_str(),
306 button_size)) {
307 if (enabled && editor_switcher_) {
308 MarkRecentlyUsed(type);
311 show_ = false;
312 }
313 }
314 if (!enabled) {
315 ImGui::EndDisabled();
316 }
317
318 if (ImGui::IsItemHovered()) {
319 if (!enabled) {
320 ImGui::SetTooltip(tr("Load a ROM to open %s"), it->name.c_str());
321 } else {
322 ImGui::SetTooltip("%s", it->description.c_str());
323 }
324 }
325 }
326 ImGui::EndTable();
327 }
328}
329
331 ImGui::Text(ICON_MD_APPS " All Editors");
332 ImGui::Spacing();
333
334 const ImGuiStyle& style = ImGui::GetStyle();
335 const float avail_width = ImGui::GetContentRegionAvail().x;
336 const float scale = ImGui::GetFontSize() / 16.0f;
337 const float compact_scale = avail_width < 620.0f ? 0.85f : 1.0f;
338 const float min_width = kDashboardCardBaseWidth *
339 kDashboardCardMinWidthFactor * scale * compact_scale;
340 const float max_width = kDashboardCardBaseWidth *
341 kDashboardCardWidthMaxFactor * scale * compact_scale;
342 const float min_height =
343 std::max(kDashboardCardBaseHeight * kDashboardCardMinHeightFactor *
344 scale * compact_scale,
345 ImGui::GetFrameHeight() * 3.2f);
346 const float max_height = kDashboardCardBaseHeight *
347 kDashboardCardHeightMaxFactor * scale *
348 compact_scale;
349 const float aspect_ratio =
350 kDashboardCardBaseHeight / std::max(kDashboardCardBaseWidth, 1.0f);
351 const float spacing = style.ItemSpacing.x;
352
353 FlowLayout layout = ComputeFlowLayout(
354 avail_width, min_width, max_width, min_height, max_height, aspect_ratio,
355 spacing, kDashboardMaxColumns, static_cast<int>(editors_.size()));
356
357 ImGuiTableFlags table_flags =
358 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
359 const ImVec2 cell_padding(layout.spacing * 0.5f, style.ItemSpacing.y * 0.5f);
360 gui::StyleVarGuard grid_var_guard(ImGuiStyleVar_CellPadding, cell_padding);
361 if (ImGui::BeginTable("DashboardEditorGrid", layout.columns, table_flags)) {
362 for (size_t i = 0; i < editors_.size(); ++i) {
363 ImGui::TableNextColumn();
364 const bool enabled = has_rom_ || !editors_[i].requires_rom;
365 DrawEditorPanel(editors_[i], static_cast<int>(i),
366 ImVec2(layout.item_width, layout.item_height), enabled);
367 }
368 ImGui::EndTable();
369 }
370}
371
372void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
373 const ImVec2& card_size, bool enabled) {
374 ImGui::PushID(index);
375
376 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
377 const float disabled_alpha = enabled ? 1.0f : 0.35f;
378 const ImVec4 base_color = GetEditorAccentColor(info.type, theme);
379 ImVec4 text_primary = gui::ConvertColorToImVec4(theme.text_primary);
380 ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
381 const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
382 text_primary.w *= enabled ? 1.0f : 0.5f;
383 text_secondary.w *= enabled ? 1.0f : 0.5f;
384 ImFont* text_font = ImGui::GetFont();
385 const float text_font_size = ImGui::GetFontSize();
386
387 const ImGuiStyle& style = ImGui::GetStyle();
388 const float line_height = ImGui::GetTextLineHeight();
389 const float padding_x = std::max(style.FramePadding.x, card_size.x * 0.06f);
390 const float padding_y = std::max(style.FramePadding.y, card_size.y * 0.08f);
391
392 const float footer_height = info.shortcut.empty() ? 0.0f : line_height;
393 const float footer_spacing =
394 info.shortcut.empty() ? 0.0f : style.ItemSpacing.y;
395 const float available_icon_height = card_size.y - padding_y * 2.0f -
396 line_height - footer_height -
397 footer_spacing;
398 const float min_icon_radius = line_height * 0.9f;
399 float max_icon_radius = card_size.y * 0.24f;
400 max_icon_radius = std::max(max_icon_radius, min_icon_radius);
401 const float icon_radius = std::clamp(available_icon_height * 0.5f,
402 min_icon_radius, max_icon_radius);
403
404 const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
405 ImDrawList* draw_list = ImGui::GetWindowDrawList();
406 const ImVec2 icon_center(cursor_pos.x + card_size.x * 0.5f,
407 cursor_pos.y + padding_y + icon_radius);
408 float title_y = icon_center.y + icon_radius + style.ItemSpacing.y;
409 const float footer_y = cursor_pos.y + card_size.y - padding_y - footer_height;
410 if (title_y + line_height > footer_y - style.ItemSpacing.y) {
411 title_y = footer_y - line_height - style.ItemSpacing.y;
412 }
413
414 bool is_recent = std::find(recent_editors_.begin(), recent_editors_.end(),
415 info.type) != recent_editors_.end();
416
417 // Create gradient background
418 ImU32 color_top =
419 ImGui::GetColorU32(ScaleColor(base_color, 0.4f, 0.85f * disabled_alpha));
420 ImU32 color_bottom =
421 ImGui::GetColorU32(ScaleColor(base_color, 0.2f, 0.9f * disabled_alpha));
422
423 // Draw gradient card background
424 draw_list->AddRectFilledMultiColor(
425 cursor_pos,
426 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y), color_top,
427 color_top, color_bottom, color_bottom);
428
429 // Colored border
430 ImU32 border_color =
431 is_recent
432 ? ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha))
433 : ImGui::GetColorU32(
434 ScaleColor(base_color, 0.6f, 0.7f * disabled_alpha));
435 const float rounding = std::max(style.FrameRounding, card_size.y * 0.05f);
436 const float border_thickness =
437 is_recent ? std::max(2.0f, style.FrameBorderSize + 1.0f)
438 : std::max(1.0f, style.FrameBorderSize);
439 draw_list->AddRect(
440 cursor_pos,
441 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
442 border_color, rounding, 0, border_thickness);
443
444 // Recent indicator badge
445 if (is_recent) {
446 const float badge_radius =
447 std::clamp(line_height * 0.6f, line_height * 0.4f, line_height);
448 ImVec2 badge_pos(cursor_pos.x + card_size.x - padding_x - badge_radius,
449 cursor_pos.y + padding_y + badge_radius);
450 draw_list->AddCircleFilled(badge_pos, badge_radius,
451 ImGui::GetColorU32(base_color), 16);
452 const ImU32 star_color = ImGui::GetColorU32(text_primary);
453 const ImVec2 star_size =
454 text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f, ICON_MD_STAR);
455 const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
456 badge_pos.y - star_size.y * 0.5f);
457 draw_list->AddText(text_font, text_font_size, star_pos, star_color,
459 }
460
461 // Make button transparent (we draw our own background)
462 ImVec4 button_bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
463 button_bg.w = 0.0f;
464 gui::StyleColorGuard card_btn_guard(
465 {{ImGuiCol_Button, button_bg},
466 {ImGuiCol_ButtonHovered,
467 ScaleColor(base_color, 0.3f, enabled ? 0.5f : 0.2f)},
468 {ImGuiCol_ButtonActive,
469 ScaleColor(base_color, 0.5f, enabled ? 0.7f : 0.2f)}});
470
471 if (!enabled) {
472 ImGui::BeginDisabled();
473 }
474 bool clicked =
475 ImGui::Button(absl::StrCat("##", info.name).c_str(), card_size);
476 if (!enabled) {
477 ImGui::EndDisabled();
478 }
479 bool is_hovered = ImGui::IsItemHovered();
480
481 // Draw icon with colored background circle
482 ImU32 icon_bg =
483 ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha));
484 draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
485
486 // Draw icon
487 ImFont* icon_font = ImGui::GetFont();
488 if (ImGui::GetIO().Fonts->Fonts.size() > 2 &&
489 card_size.y >= kDashboardCardBaseHeight) {
490 icon_font = ImGui::GetIO().Fonts->Fonts[2];
491 } else if (ImGui::GetIO().Fonts->Fonts.size() > 1) {
492 icon_font = ImGui::GetIO().Fonts->Fonts[1];
493 }
494 ImGui::PushFont(icon_font);
495 const float icon_font_size = ImGui::GetFontSize();
496 const ImVec2 icon_size = icon_font->CalcTextSizeA(icon_font_size, FLT_MAX,
497 0.0f, info.icon.c_str());
498 ImGui::PopFont();
499 const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
500 icon_center.y - icon_size.y * 0.5f);
501 draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
502 ImGui::GetColorU32(text_primary), info.icon.c_str());
503
504 // Draw name
505 const ImVec2 name_size = text_font->CalcTextSizeA(text_font_size, FLT_MAX,
506 0.0f, info.name.c_str());
507 float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
508 const float name_min_x = cursor_pos.x + padding_x;
509 const float name_max_x = cursor_pos.x + card_size.x - padding_x;
510 name_x = std::clamp(name_x, name_min_x, name_max_x);
511 const ImVec2 name_pos(name_x, title_y);
512 const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
513 footer_y);
514 draw_list->AddText(text_font, text_font_size, name_pos,
515 ImGui::GetColorU32(WithAlpha(base_color, disabled_alpha)),
516 info.name.c_str(), nullptr, 0.0f, &name_clip);
517
518 // Draw shortcut hint if available
519 if (!info.shortcut.empty()) {
520 const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
521 const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
522 cursor_pos.x + card_size.x - padding_x,
523 cursor_pos.y + card_size.y - padding_y);
524 draw_list->AddText(text_font, text_font_size, shortcut_pos,
525 ImGui::GetColorU32(text_secondary),
526 info.shortcut.c_str(), nullptr, 0.0f, &shortcut_clip);
527 }
528
529 // Hover glow effect
530 if (is_hovered) {
531 ImU32 glow_color = ImGui::GetColorU32(
532 ScaleColor(base_color, 1.0f, enabled ? 0.18f : 0.08f));
533 draw_list->AddRectFilled(
534 cursor_pos,
535 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
536 glow_color, rounding);
537 }
538
539 // Enhanced tooltip
540 if (is_hovered) {
541 const float tooltip_width = std::clamp(card_size.x * 1.4f, 240.0f, 340.0f);
542 ImGui::SetNextWindowSize(ImVec2(tooltip_width, 0), ImGuiCond_Always);
543 ImGui::BeginTooltip();
544 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); // Medium font
545 ImGui::TextColored(WithAlpha(base_color, disabled_alpha), "%s %s",
546 info.icon.c_str(), info.name.c_str());
547 ImGui::PopFont();
548 ImGui::Separator();
549 ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + tooltip_width - 20.0f);
550 if (!enabled) {
551 ImGui::TextWrapped(tr("Load a ROM to open this editor."));
552 } else {
553 ImGui::TextWrapped("%s", info.description.c_str());
554 }
555 ImGui::PopTextWrapPos();
556 if (enabled && !info.shortcut.empty()) {
557 ImGui::Spacing();
558 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
559 ICON_MD_KEYBOARD " %s", info.shortcut.c_str());
560 }
561 if (is_recent) {
562 ImGui::Spacing();
563 ImGui::TextColored(accent, ICON_MD_STAR " Recently used");
564 }
565 ImGui::EndTooltip();
566 }
567
568 if (clicked && enabled) {
569 if (editor_switcher_) {
573 show_ = false;
574 }
575 }
576
577 ImGui::PopID();
578}
579
581 // Remove if already in list
582 auto it = std::find(recent_editors_.begin(), recent_editors_.end(), type);
583 if (it != recent_editors_.end()) {
584 recent_editors_.erase(it);
585 }
586
587 // Add to front
588 recent_editors_.insert(recent_editors_.begin(), type);
589
590 // Limit size
591 if (recent_editors_.size() > kMaxRecentEditors) {
593 }
594
596}
597
599 try {
600 auto data = util::LoadFileFromConfigDir("recent_editors.txt");
601 if (!data.empty()) {
602 std::istringstream ss(data);
603 std::string line;
604 while (std::getline(ss, line) &&
606 int type_int = std::stoi(line);
607 if (type_int >= 0 &&
608 type_int < static_cast<int>(EditorType::kSettings)) {
609 recent_editors_.push_back(static_cast<EditorType>(type_int));
610 }
611 }
612 }
613 } catch (...) {
614 // Ignore errors
615 }
616}
617
619 try {
620 std::ostringstream ss;
621 for (EditorType type : recent_editors_) {
622 ss << static_cast<int>(type) << "\n";
623 }
624 util::SaveFile("recent_editors.txt", ss.str());
625 } catch (...) {
626 // Ignore save errors
627 }
628}
629
634
635} // namespace editor
636} // namespace yaze
bool is_loaded() const
Definition rom.h:144
std::vector< EditorInfo > editors_
static constexpr size_t kMaxRecentEditors
std::vector< EditorType > recent_editors_
void MarkRecentlyUsed(EditorType type)
void DrawEditorPanel(const EditorInfo &info, int index, const ImVec2 &card_size, bool enabled)
DashboardPanel(IEditorSwitcher *editor_switcher)
IEditorSwitcher * editor_switcher_
Interface for editor selection and navigation.
virtual void SwitchToEditor(EditorType type, bool force_visible=false, bool from_dialog=false)=0
virtual void DismissEditorSelection()=0
virtual Rom * GetCurrentRom() const =0
void SetSaveSettings(bool save)
void SetPosition(Position pos)
bool Begin(bool *p_open=nullptr)
void SetDefaultSize(float width, float height)
RAII guard for ImGui style colors.
Definition style_guard.h:27
RAII guard for ImGui style vars.
Definition style_guard.h:68
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
#define ICON_MD_APPS
Definition icons.h:168
#define ICON_MD_INFO
Definition icons.h:993
#define ICON_MD_EMOJI_EMOTIONS
Definition icons.h:672
#define ICON_MD_DATA_ARRAY
Definition icons.h:519
#define ICON_MD_STAR
Definition icons.h:1848
#define ICON_MD_MAP
Definition icons.h:1173
#define ICON_MD_CODE
Definition icons.h:434
#define ICON_MD_VIDEOGAME_ASSET
Definition icons.h:2076
#define ICON_MD_CHAT_BUBBLE
Definition icons.h:395
#define ICON_MD_EDIT
Definition icons.h:645
#define ICON_MD_CASTLE
Definition icons.h:380
#define ICON_MD_MUSIC_NOTE
Definition icons.h:1264
#define ICON_MD_KEYBOARD
Definition icons.h:1028
#define ICON_MD_DASHBOARD
Definition icons.h:517
#define ICON_MD_PALETTE
Definition icons.h:1370
#define ICON_MD_TV
Definition icons.h:2032
#define ICON_MD_COLOR_LENS
Definition icons.h:440
#define ICON_MD_SMART_TOY
Definition icons.h:1781
#define ICON_MD_HISTORY
Definition icons.h:946
FlowLayout ComputeFlowLayout(float avail_width, float min_width, float max_width, float min_height, float max_height, float aspect_ratio, float spacing, int max_columns, int item_count)
const char * GetCtrlDisplayName()
Get the display name for the primary modifier key.
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:134
void SaveFile(const std::string &filename, const std::string &contents)
Definition file_util.cc:56
std::string LoadFileFromConfigDir(const std::string &filename)
Loads a file from the user's config directory.
Definition file_util.cc:38
Comprehensive theme structure for YAZE.