Enhance EditorManager: add assembly and palette editors to the view menu, and improve menu initialization for better readability

This commit is contained in:
scawful
2025-02-28 00:48:12 -05:00
parent 4dc09ad5fc
commit a28ad9c516
4 changed files with 77 additions and 54 deletions

View File

@@ -53,11 +53,11 @@ void EditorManager::Initialize(std::string filename) {
if (!filename.empty()) { if (!filename.empty()) {
PRINT_IF_ERROR(rom()->LoadFromFile(filename)); PRINT_IF_ERROR(rom()->LoadFromFile(filename));
} }
gui::kMainMenu.emplace_back("File"); gui::kMainMenu[gui::MenuType::kFile].name = "File";
gui::kMainMenu.emplace_back("Edit"); gui::kMainMenu[gui::MenuType::kEdit].name = "Edit";
gui::kMainMenu.emplace_back("View"); gui::kMainMenu[gui::MenuType::kView].name = "View";
gui::kMainMenu.emplace_back("Tools"); gui::kMainMenu[gui::MenuType::kTools].name = "Tools";
gui::kMainMenu.emplace_back("Help"); gui::kMainMenu[gui::MenuType::kHelp].name = "Help";
gui::AddToFileMenu(absl::StrCat(ICON_MD_FILE_OPEN, " Open"), "Ctrl+O", gui::AddToFileMenu(absl::StrCat(ICON_MD_FILE_OPEN, " Open"), "Ctrl+O",
[&]() { LoadRom(); }); [&]() { LoadRom(); });
@@ -110,6 +110,15 @@ void EditorManager::Initialize(std::string filename) {
[&]() { show_emulator_ = true; }); [&]() { show_emulator_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_MEMORY, " Memory Editor"), "", gui::AddToViewMenu(absl::StrCat(ICON_MD_MEMORY, " Memory Editor"), "",
[&]() { show_memory_editor_ = true; }); [&]() { show_memory_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_CODE, " Assembly Editor"), "",
[&]() { show_asm_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_PALETTE, " Palette Editor"), "",
[&]() { show_palette_editor_ = true; });
gui::AddToViewMenu(absl::StrCat(ICON_MD_SIM_CARD, " ROM Metadata"), "",
[&]() { rom_info_ = true; });
gui::AddToHelpMenu(absl::StrCat(ICON_MD_HELP, " About"), "F1",
[&]() { about_ = true; });
overworld_editor_.Initialize(); overworld_editor_.Initialize();
} }

View File

@@ -83,6 +83,8 @@ class EditorManager : public SharedRom {
bool save_as_menu_ = false; bool save_as_menu_ = false;
bool show_emulator_ = false; bool show_emulator_ = false;
bool show_memory_editor_ = false; bool show_memory_editor_ = false;
bool show_asm_editor_ = false;
bool show_palette_editor_ = false;
bool show_status_ = false; bool show_status_ = false;
bool rom_assets_loaded_ = false; bool rom_assets_loaded_ = false;

View File

@@ -77,7 +77,7 @@ struct MenuItem {
std::function<bool()> enabled_condition = kDefaultEnabledCondition; std::function<bool()> enabled_condition = kDefaultEnabledCondition;
std::vector<MenuItem> subitems; std::vector<MenuItem> subitems;
}; };
using Menu = std::vector<MenuItem>; using Menu = std::array<MenuItem, 5>;
void DrawMenu(Menu &params); void DrawMenu(Menu &params);
@@ -124,6 +124,11 @@ inline void AddToViewMenu(const std::string &label, const std::string &shortcut,
kMainMenu[MenuType::kView].subitems.emplace_back(label, shortcut, callback); kMainMenu[MenuType::kView].subitems.emplace_back(label, shortcut, callback);
} }
inline void AddToHelpMenu(const std::string &label, const std::string &shortcut,
std::function<void()> callback) {
kMainMenu[MenuType::kHelp].subitems.emplace_back(label, shortcut, callback);
}
} // namespace gui } // namespace gui
} // namespace yaze } // namespace yaze

View File

@@ -78,18 +78,27 @@ absl::Status SaveTheme(const Theme &theme) {
theme_stream << theme.name << "Theme\n"; theme_stream << theme.name << "Theme\n";
theme_stream << "MenuBarBg=#" << gui::ColorToHexString(theme.menu_bar_bg) theme_stream << "MenuBarBg=#" << gui::ColorToHexString(theme.menu_bar_bg)
<< "\n"; << "\n";
theme_stream << "TitleBg=#" << gui::ColorToHexString(theme.title_bar_bg) << "\n"; theme_stream << "TitleBg=#" << gui::ColorToHexString(theme.title_bar_bg)
<< "\n";
theme_stream << "Header=#" << gui::ColorToHexString(theme.header) << "\n"; theme_stream << "Header=#" << gui::ColorToHexString(theme.header) << "\n";
theme_stream << "HeaderHovered=#" << gui::ColorToHexString(theme.header_hovered) << "\n"; theme_stream << "HeaderHovered=#"
theme_stream << "HeaderActive=#" << gui::ColorToHexString(theme.header_active) << "\n"; << gui::ColorToHexString(theme.header_hovered) << "\n";
theme_stream << "TitleBgActive=#" << gui::ColorToHexString(theme.title_bg_active) << "\n"; theme_stream << "HeaderActive=#" << gui::ColorToHexString(theme.header_active)
theme_stream << "TitleBgCollapsed=#" << gui::ColorToHexString(theme.title_bg_collapsed) << "\n"; << "\n";
theme_stream << "TitleBgActive=#"
<< gui::ColorToHexString(theme.title_bg_active) << "\n";
theme_stream << "TitleBgCollapsed=#"
<< gui::ColorToHexString(theme.title_bg_collapsed) << "\n";
theme_stream << "Tab=#" << gui::ColorToHexString(theme.tab) << "\n"; theme_stream << "Tab=#" << gui::ColorToHexString(theme.tab) << "\n";
theme_stream << "TabHovered=#" << gui::ColorToHexString(theme.tab_hovered) << "\n"; theme_stream << "TabHovered=#" << gui::ColorToHexString(theme.tab_hovered)
theme_stream << "TabActive=#" << gui::ColorToHexString(theme.tab_active) << "\n"; << "\n";
theme_stream << "TabActive=#" << gui::ColorToHexString(theme.tab_active)
<< "\n";
theme_stream << "Button=#" << gui::ColorToHexString(theme.button) << "\n"; theme_stream << "Button=#" << gui::ColorToHexString(theme.button) << "\n";
theme_stream << "ButtonHovered=#" << gui::ColorToHexString(theme.button_hovered) << "\n"; theme_stream << "ButtonHovered=#"
theme_stream << "ButtonActive=#" << gui::ColorToHexString(theme.button_active) << "\n"; << gui::ColorToHexString(theme.button_hovered) << "\n";
theme_stream << "ButtonActive=#" << gui::ColorToHexString(theme.button_active)
<< "\n";
// Save the theme to a file. // Save the theme to a file.
@@ -103,16 +112,22 @@ void ApplyTheme(const Theme &theme) {
colors[ImGuiCol_MenuBarBg] = gui::ConvertColorToImVec4(theme.menu_bar_bg); colors[ImGuiCol_MenuBarBg] = gui::ConvertColorToImVec4(theme.menu_bar_bg);
colors[ImGuiCol_TitleBg] = gui::ConvertColorToImVec4(theme.title_bar_bg); colors[ImGuiCol_TitleBg] = gui::ConvertColorToImVec4(theme.title_bar_bg);
colors[ImGuiCol_Header] = gui::ConvertColorToImVec4(theme.header); colors[ImGuiCol_Header] = gui::ConvertColorToImVec4(theme.header);
colors[ImGuiCol_HeaderHovered] = gui::ConvertColorToImVec4(theme.header_hovered); colors[ImGuiCol_HeaderHovered] =
colors[ImGuiCol_HeaderActive] = gui::ConvertColorToImVec4(theme.header_active); gui::ConvertColorToImVec4(theme.header_hovered);
colors[ImGuiCol_TitleBgActive] = gui::ConvertColorToImVec4(theme.title_bg_active); colors[ImGuiCol_HeaderActive] =
colors[ImGuiCol_TitleBgCollapsed] = gui::ConvertColorToImVec4(theme.title_bg_collapsed); gui::ConvertColorToImVec4(theme.header_active);
colors[ImGuiCol_TitleBgActive] =
gui::ConvertColorToImVec4(theme.title_bg_active);
colors[ImGuiCol_TitleBgCollapsed] =
gui::ConvertColorToImVec4(theme.title_bg_collapsed);
colors[ImGuiCol_Tab] = gui::ConvertColorToImVec4(theme.tab); colors[ImGuiCol_Tab] = gui::ConvertColorToImVec4(theme.tab);
colors[ImGuiCol_TabHovered] = gui::ConvertColorToImVec4(theme.tab_hovered); colors[ImGuiCol_TabHovered] = gui::ConvertColorToImVec4(theme.tab_hovered);
colors[ImGuiCol_TabActive] = gui::ConvertColorToImVec4(theme.tab_active); colors[ImGuiCol_TabActive] = gui::ConvertColorToImVec4(theme.tab_active);
colors[ImGuiCol_Button] = gui::ConvertColorToImVec4(theme.button); colors[ImGuiCol_Button] = gui::ConvertColorToImVec4(theme.button);
colors[ImGuiCol_ButtonHovered] = gui::ConvertColorToImVec4(theme.button_hovered); colors[ImGuiCol_ButtonHovered] =
colors[ImGuiCol_ButtonActive] = gui::ConvertColorToImVec4(theme.button_active); gui::ConvertColorToImVec4(theme.button_hovered);
colors[ImGuiCol_ButtonActive] =
gui::ConvertColorToImVec4(theme.button_active);
} }
void ColorsYaze() { void ColorsYaze() {
@@ -277,8 +292,7 @@ static const char *const kIdentifiers[] = {
TextEditor::LanguageDefinition GetAssemblyLanguageDef() { TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
TextEditor::LanguageDefinition language_65816; TextEditor::LanguageDefinition language_65816;
for (auto &k : kKeywords) for (auto &k : kKeywords) language_65816.mKeywords.emplace(k);
language_65816.mKeywords.emplace(k);
for (auto &k : kIdentifiers) { for (auto &k : kIdentifiers) {
TextEditor::Identifier id; TextEditor::Identifier id;
@@ -389,16 +403,13 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
// Default to using internal storage as reference // Default to using internal storage as reference
static bool init = true; static bool init = true;
if (init && ref == NULL) if (init && ref == NULL) ref_saved_style = style;
ref_saved_style = style;
init = false; init = false;
if (ref == NULL) if (ref == NULL) ref = &ref_saved_style;
ref = &ref_saved_style;
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
if (ImGui::ShowStyleSelector("Colors##Selector")) if (ImGui::ShowStyleSelector("Colors##Selector")) ref_saved_style = style;
ref_saved_style = style;
ImGui::ShowFontSelector("Fonts##Selector"); ImGui::ShowFontSelector("Fonts##Selector");
// Simplified Settings (expose floating-pointer border sizes as boolean // Simplified Settings (expose floating-pointer border sizes as boolean
@@ -429,11 +440,9 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
} }
// Save/Revert button // Save/Revert button
if (ImGui::Button("Save Ref")) if (ImGui::Button("Save Ref")) *ref = ref_saved_style = style;
*ref = ref_saved_style = style;
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Revert Ref")) if (ImGui::Button("Revert Ref")) style = *ref;
style = *ref;
ImGui::SameLine(); ImGui::SameLine();
ImGui::Separator(); ImGui::Separator();
@@ -605,8 +614,7 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
ImGui::PushItemWidth(ImGui::GetFontSize() * -12); ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
for (int i = 0; i < ImGuiCol_COUNT; i++) { for (int i = 0; i < ImGuiCol_COUNT; i++) {
const char *name = ImGui::GetStyleColorName(i); const char *name = ImGui::GetStyleColorName(i);
if (!filter.PassFilter(name)) if (!filter.PassFilter(name)) continue;
continue;
ImGui::PushID(i); ImGui::PushID(i);
ImGui::ColorEdit4("##color", (float *)&style.Colors[i], ImGui::ColorEdit4("##color", (float *)&style.Colors[i],
ImGuiColorEditFlags_AlphaBar | alpha_flags); ImGuiColorEditFlags_AlphaBar | alpha_flags);
@@ -683,8 +691,7 @@ void DrawDisplaySettings(ImGuiStyle *ref) {
&style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f, &style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f,
"%.2f", ImGuiSliderFlags_AlwaysClamp); "%.2f", ImGuiSliderFlags_AlwaysClamp);
const bool show_samples = ImGui::IsItemActive(); const bool show_samples = ImGui::IsItemActive();
if (show_samples) if (show_samples) ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
if (show_samples && ImGui::BeginTooltip()) { if (show_samples && ImGui::BeginTooltip()) {
ImGui::TextUnformatted("(R = radius, N = number of segments)"); ImGui::TextUnformatted("(R = radius, N = number of segments)");
ImGui::Spacing(); ImGui::Spacing();
@@ -760,7 +767,7 @@ void DrawFontManager() {
static bool font_selected = false; static bool font_selected = false;
ImGui::Text("Loaded fonts"); ImGui::Text("Loaded fonts");
for (const auto& loaded_font : core::global_font_state.fonts) { for (const auto &loaded_font : core::font_registry.fonts) {
ImGui::Text("%s", loaded_font.font_path); ImGui::Text("%s", loaded_font.font_path);
} }
ImGui::Separator(); ImGui::Separator();