diff --git a/src/app/core/common.h b/src/app/core/common.h index 0a99b54a..0d561147 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -44,6 +44,10 @@ class ExperimentFlags { // Use the new platform specific file dialog wrappers. bool kNewFileDialogWrapper = true; + + // Platform specific loading of fonts from the system. Currently + // only supports macOS. + bool kLoadSystemFonts = true; }; ExperimentFlags() = default; diff --git a/src/app/core/constants.h b/src/app/core/constants.h index f9b49beb..d10adce2 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -93,6 +93,9 @@ ImGui::Text(text); \ ImGui::Separator(); +#define TABLE_BORDERS_RESIZABLE \ + ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable + #define CLEAR_AND_RETURN_STATUS(status) \ if (!status.ok()) { \ auto temp = status; \ diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 99d5b2b2..2c72751c 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -11,6 +11,7 @@ #include "absl/status/status.h" #include "absl/strings/str_format.h" +#include "app/core/platform/font_loader.h" #include "app/editor/master_editor.h" #include "app/gui/icons.h" #include "app/gui/style.h" @@ -212,7 +213,7 @@ absl::Status Controller::CreateRenderer() { return absl::OkStatus(); } -absl::Status Controller::CreateGuiContext() const { +absl::Status Controller::CreateGuiContext() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -228,6 +229,25 @@ absl::Status Controller::CreateGuiContext() const { ImGui_ImplSDL2_InitForSDLRenderer(window_.get(), renderer_.get()); ImGui_ImplSDLRenderer2_Init(renderer_.get()); + if (flags()->kLoadSystemFonts) { + LoadSystemFonts(); + } else { + LoadFontFamilies(); + } + + // Set the default style + gui::ColorsYaze(); + + // Build a new ImGui frame + ImGui_ImplSDLRenderer2_NewFrame(); + ImGui_ImplSDL2_NewFrame(window_.get()); + + return absl::OkStatus(); +} + +absl::Status Controller::LoadFontFamilies() const { + ImGuiIO &io = ImGui::GetIO(); + // Define constants static const char *KARLA_REGULAR = "assets/font/Karla-Regular.ttf"; static const char *ROBOTO_MEDIUM = "assets/font/Roboto-Medium.ttf"; @@ -277,13 +297,6 @@ absl::Status Controller::CreateGuiContext() const { io.Fonts->GetGlyphRangesJapanese()); } - // Set the default style - gui::ColorsYaze(); - - // Build a new ImGui frame - ImGui_ImplSDLRenderer2_NewFrame(); - ImGui_ImplSDL2_NewFrame(window_.get()); - return absl::OkStatus(); } diff --git a/src/app/core/controller.h b/src/app/core/controller.h index 423823d4..67914445 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -39,7 +39,8 @@ class Controller : public ExperimentFlags { absl::Status CreateWindow(); absl::Status CreateRenderer(); - absl::Status CreateGuiContext() const; + absl::Status CreateGuiContext(); + absl::Status LoadFontFamilies() const; void CloseWindow() { active_ = false; } friend int ::main(int argc, char **argv); diff --git a/src/app/editor/modules/assembly_editor.cc b/src/app/editor/modules/assembly_editor.cc index 7601c189..86403d8b 100644 --- a/src/app/editor/modules/assembly_editor.cc +++ b/src/app/editor/modules/assembly_editor.cc @@ -50,6 +50,45 @@ void AssemblyEditor::ChangeActiveFile(const std::string_view& filename) { current_file_ = filename; } +void AssemblyEditor::DrawFileView() { + ImGui::BeginTable("##table_view", 4, + ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg); + + // Table headers + ImGui::TableSetupColumn("Files", ImGuiTableColumnFlags_WidthFixed, 150.0f); + ImGui::TableSetupColumn("Line", ImGuiTableColumnFlags_WidthFixed, 60.0f); + ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed, 100.0f); + ImGui::TableSetupColumn("Editor", ImGuiTableColumnFlags_WidthStretch); + + ImGui::TableHeadersRow(); + + // Table data + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + // TODO: Add tree view of files + + ImGui::TableNextColumn(); + // TODO: Add line number + + ImGui::TableNextColumn(); + // TODO: Add address per line + + ImGui::TableNextColumn(); + + auto cpos = text_editor_.GetCursorPosition(); + SetEditorText(); + ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, + cpos.mColumn + 1, text_editor_.GetTotalLines(), + text_editor_.IsOverwrite() ? "Ovr" : "Ins", + text_editor_.CanUndo() ? "*" : " ", + text_editor_.GetLanguageDefinition().mName.c_str(), + current_file_.c_str()); + + text_editor_.Render("##asm_editor"); + + ImGui::EndTable(); +} + void AssemblyEditor::DrawFileMenu() { if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Open", "Ctrl+O")) { diff --git a/src/app/editor/modules/assembly_editor.h b/src/app/editor/modules/assembly_editor.h index 0b2ae9f8..aefdb111 100644 --- a/src/app/editor/modules/assembly_editor.h +++ b/src/app/editor/modules/assembly_editor.h @@ -23,6 +23,9 @@ class AssemblyEditor { private: void DrawFileMenu(); void DrawEditMenu(); + + void DrawFileView(); + void SetEditorText(); bool file_is_loaded_ = false; diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 80c6950f..a27c1315 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -9,6 +9,7 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" +#include "app/core/common.h" #include "app/core/pipeline.h" #include "app/editor/modules/palette_editor.h" #include "app/gfx/bitmap.h" @@ -51,7 +52,6 @@ absl::Status OverworldEditor::Update() { // Draws the toolset for editing the Overworld. RETURN_IF_ERROR(DrawToolset()) - if (ImGui::BeginTable(kOWEditTable.data(), 2, kOWEditFlags, ImVec2(0, 0))) { TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch, ImGui::GetContentRegionAvail().x); @@ -127,8 +127,10 @@ absl::Status OverworldEditor::DrawToolset() { TableNextColumn(); // Palette palette_editor_.DisplayPalette(palette_, overworld_.isLoaded()); + TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator - TableNextColumn(); // Experimental + + TableNextColumn(); // Experimental ImGui::Checkbox("Experimental", &show_experimental); ImGui::EndTable(); @@ -453,8 +455,8 @@ void OverworldEditor::DrawTileSelector() { ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Tile8")) { - if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1); - ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, + if (ImGui::BeginChild(core::ImGuiIdIssuer::GetNewID(), + ImGui::GetContentRegionAvail(), true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) { DrawTile8Selector(); }