diff --git a/src/app/gui/input.cc b/src/app/gui/input.cc index ff47eaf9..bbab899f 100644 --- a/src/app/gui/input.cc +++ b/src/app/gui/input.cc @@ -255,13 +255,15 @@ bool InputTileInfo(const char* label, gfx::TileInfo* tile_info) { ImGuiID GetID(const std::string& id) { return ImGui::GetID(id.c_str()); } -void AddTableColumn(Table &table, const std::string &label, GuiElement element) { +void AddTableColumn(Table& table, const std::string& label, + GuiElement element) { table.column_labels.push_back(label); table.column_contents.push_back(element); } void DrawTable(Table& params) { - if (ImGui::BeginTable(params.id, params.num_columns, params.flags, params.size)) { + if (ImGui::BeginTable(params.id, params.num_columns, params.flags, + params.size)) { for (int i = 0; i < params.num_columns; ++i) ImGui::TableSetupColumn(params.column_labels[i].c_str()); @@ -280,5 +282,34 @@ void DrawTable(Table& params) { } } +void DrawMenu(Menu& menu) { + for (const auto& each_menu : menu) { + if (ImGui::BeginMenu(each_menu.name.c_str())) { + for (const auto& each_item : each_menu.subitems) { + if (!each_item.subitems.empty()) { + if (ImGui::BeginMenu(each_item.name.c_str())) { + for (const auto& each_subitem : each_item.subitems) { + if (ImGui::MenuItem(each_subitem.name.c_str(), + each_subitem.shortcut.c_str())) { + if (each_subitem.callback) each_subitem.callback(); + } + } + ImGui::EndMenu(); + } + } else if (each_item.name == "-") { + ImGui::Separator(); + } else { + if (ImGui::MenuItem(each_item.name.c_str(), + each_item.shortcut.c_str(), + each_item.enabled_condition())) { + if (each_item.callback) each_item.callback(); + } + } + } + ImGui::EndMenu(); + } + } +} + } // namespace gui } // namespace yaze diff --git a/src/app/gui/input.h b/src/app/gui/input.h index ae63cb63..76cfa814 100644 --- a/src/app/gui/input.h +++ b/src/app/gui/input.h @@ -11,6 +11,7 @@ #include #include +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "app/gfx/snes_tile.h" #include "imgui/imgui.h" @@ -67,7 +68,63 @@ void AddTableColumn(Table &table, const std::string &label, GuiElement element); void DrawTable(Table ¶ms); -} // namespace gui -} // namespace yaze +static std::function kDefaultEnabledCondition = []() { return false; }; + +struct MenuItem { + std::string name; + std::string shortcut; + std::function callback; + std::function enabled_condition = kDefaultEnabledCondition; + std::vector subitems; +}; +using Menu = std::vector; + +void DrawMenu(Menu ¶ms); + +enum MenuType { + kFile, + kEdit, + kView, + kTools, + kHelp, +}; + +static Menu kMainMenu; + +inline void AddToMenu(const std::string &label, const char *icon, + MenuType type) { + if (icon) { + kMainMenu[type].subitems.emplace_back(absl::StrCat(icon, " ", label), "", + nullptr); + } else { + kMainMenu[type].subitems.emplace_back(label, "", nullptr); + } +} + +inline void AddToFileMenu(const std::string &label, const std::string &shortcut, + std::function callback) { + kMainMenu[MenuType::kFile].subitems.emplace_back(label, shortcut, callback); +} + +inline void AddToFileMenu(const std::string &label, const std::string &shortcut, + std::function callback, + std::function enabled_condition, + std::vector subitems) { + kMainMenu[MenuType::kFile].subitems.emplace_back(label, shortcut, callback, + enabled_condition, subitems); +} + +inline void AddToEditMenu(const std::string &label, const std::string &shortcut, + std::function callback) { + kMainMenu[MenuType::kEdit].subitems.emplace_back(label, shortcut, callback); +} + +inline void AddToViewMenu(const std::string &label, const std::string &shortcut, + std::function callback) { + kMainMenu[MenuType::kView].subitems.emplace_back(label, shortcut, callback); +} + +} // namespace gui +} // namespace yaze #endif diff --git a/src/app/gui/style.cc b/src/app/gui/style.cc index e1459142..6c2c65fc 100644 --- a/src/app/gui/style.cc +++ b/src/app/gui/style.cc @@ -1,6 +1,7 @@ #include "style.h" #include "app/core/platform/file_dialog.h" +#include "core/platform/font_loader.h" #include "gui/color.h" #include "imgui/imgui.h" #include "imgui/imgui_internal.h" @@ -752,12 +753,21 @@ void TextWithSeparators(const absl::string_view &text) { void DrawFontManager() { ImGuiIO& io = ImGui::GetIO(); ImFontAtlas* atlas = io.Fonts; + static ImFont* current_font = atlas->Fonts[0]; static int current_font_index = 0; static int font_size = 16; static bool font_selected = false; + + ImGui::Text("Loaded fonts"); + for (const auto& loaded_font : core::global_font_state.fonts) { + ImGui::Text("%s", loaded_font.font_path); + } + ImGui::Separator(); + ImGui::Text("Current Font: %s", current_font->GetDebugName()); ImGui::Text("Font Size: %d", font_size); + if (ImGui::BeginCombo("Fonts", current_font->GetDebugName())) { for (int i = 0; i < atlas->Fonts.Size; i++) { bool is_selected = (current_font == atlas->Fonts[i]); @@ -772,6 +782,7 @@ void DrawFontManager() { } ImGui::EndCombo(); } + ImGui::Separator(); if (ImGui::SliderInt("Font Size", &font_size, 8, 32)) { current_font->Scale = font_size / 16.0f;