Refactor includes and formatting in GUI header files for clarity; remove unused headers and improve code style

This commit is contained in:
scawful
2024-11-13 08:52:02 -05:00
parent 84f30f45d0
commit 2fd1b1fe94
3 changed files with 116 additions and 116 deletions

View File

@@ -66,13 +66,16 @@ 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) ref_saved_style = style; if (init && ref == NULL)
ref_saved_style = style;
init = false; init = false;
if (ref == NULL) ref = &ref_saved_style; if (ref == NULL)
ref = &ref_saved_style;
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
if (ImGui::ShowStyleSelector("Colors##Selector")) ref_saved_style = style; if (ImGui::ShowStyleSelector("Colors##Selector"))
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
@@ -103,9 +106,11 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
} }
// Save/Revert button // Save/Revert button
if (ImGui::Button("Save Ref")) *ref = ref_saved_style = style; if (ImGui::Button("Save Ref"))
*ref = ref_saved_style = style;
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Revert Ref")) style = *ref; if (ImGui::Button("Revert Ref"))
style = *ref;
ImGui::SameLine(); ImGui::SameLine();
ImGui::Separator(); ImGui::Separator();
@@ -121,8 +126,9 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
20.0f, "%.0f"); 20.0f, "%.0f");
ImGui::SliderFloat2("ItemInnerSpacing", (float *)&style.ItemInnerSpacing, ImGui::SliderFloat2("ItemInnerSpacing", (float *)&style.ItemInnerSpacing,
0.0f, 20.0f, "%.0f"); 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, ImGui::SliderFloat2("TouchExtraPadding",
0.0f, 10.0f, "%.0f"); (float *)&style.TouchExtraPadding, 0.0f, 10.0f,
"%.0f");
ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f,
"%.0f"); "%.0f");
ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f, ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f,
@@ -276,7 +282,8 @@ 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)) continue; if (!filter.PassFilter(name))
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);
@@ -353,7 +360,8 @@ 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) ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos()); if (show_samples)
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();
@@ -519,6 +527,45 @@ void ColorsYaze() {
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
} }
void DrawBitmapViewer(const std::vector<gfx::Bitmap> &bitmaps, float scale,
int &current_bitmap_id) {
if (bitmaps.empty()) {
ImGui::Text("No bitmaps available.");
return;
}
// Display the current bitmap index and total count.
ImGui::Text("Viewing Bitmap %d / %zu", current_bitmap_id + 1, bitmaps.size());
// Buttons to navigate through bitmaps.
if (ImGui::Button("<- Prev")) {
if (current_bitmap_id > 0) {
--current_bitmap_id;
}
}
ImGui::SameLine();
if (ImGui::Button("Next ->")) {
if (current_bitmap_id < bitmaps.size() - 1) {
++current_bitmap_id;
}
}
// Display the current bitmap.
const gfx::Bitmap &current_bitmap = bitmaps[current_bitmap_id];
// Assuming Bitmap has a function to get its texture ID, and width and
// height.
ImTextureID tex_id = (ImTextureID)(intptr_t)current_bitmap.texture();
ImVec2 size(current_bitmap.width() * scale, current_bitmap.height() * scale);
// ImGui::Image(tex_id, size);
// Scroll if the image is larger than the display area.
if (ImGui::BeginChild("BitmapScrollArea", ImVec2(0, 0), false,
ImGuiWindowFlags_HorizontalScrollbar)) {
ImGui::Image(tex_id, size);
ImGui::EndChild();
}
}
// ============================================================================ // ============================================================================
// 65816 LanguageDefinition // 65816 LanguageDefinition
// ============================================================================ // ============================================================================
@@ -548,7 +595,8 @@ static const char* const kIdentifiers[] = {
TextEditor::LanguageDefinition GetAssemblyLanguageDef() { TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
TextEditor::LanguageDefinition language_65816; TextEditor::LanguageDefinition language_65816;
for (auto& k : kKeywords) language_65816.mKeywords.emplace(k); for (auto &k : kKeywords)
language_65816.mKeywords.emplace(k);
for (auto &k : kIdentifiers) { for (auto &k : kIdentifiers) {
TextEditor::Identifier id; TextEditor::Identifier id;

View File

@@ -12,7 +12,6 @@
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h" #include "imgui/misc/cpp/imgui_stdlib.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
namespace gui { namespace gui {
@@ -41,53 +40,8 @@ void ColorsYaze();
TextEditor::LanguageDefinition GetAssemblyLanguageDef(); TextEditor::LanguageDefinition GetAssemblyLanguageDef();
class BitmapViewer { void DrawBitmapViewer(const std::vector<gfx::Bitmap> &bitmaps, float scale,
public: int &current_bitmap);
BitmapViewer() : current_bitmap_index_(0) {}
void Display(const std::vector<gfx::Bitmap>& bitmaps, float scale = 1.0f) {
if (bitmaps.empty()) {
ImGui::Text("No bitmaps available.");
return;
}
// Display the current bitmap index and total count.
ImGui::Text("Viewing Bitmap %d / %zu", current_bitmap_index_ + 1,
bitmaps.size());
// Buttons to navigate through bitmaps.
if (ImGui::Button("<- Prev")) {
if (current_bitmap_index_ > 0) {
--current_bitmap_index_;
}
}
ImGui::SameLine();
if (ImGui::Button("Next ->")) {
if (current_bitmap_index_ < bitmaps.size() - 1) {
++current_bitmap_index_;
}
}
// Display the current bitmap.
const gfx::Bitmap& current_bitmap = bitmaps[current_bitmap_index_];
// Assuming Bitmap has a function to get its texture ID, and width and
// height.
ImTextureID tex_id = (ImTextureID)(intptr_t)current_bitmap.texture();
ImVec2 size(current_bitmap.width() * scale,
current_bitmap.height() * scale);
// ImGui::Image(tex_id, size);
// Scroll if the image is larger than the display area.
if (ImGui::BeginChild("BitmapScrollArea", ImVec2(0, 0), false,
ImGuiWindowFlags_HorizontalScrollbar)) {
ImGui::Image(tex_id, size);
ImGui::EndChild();
}
}
private:
int current_bitmap_index_;
};
// ============================================================================ // ============================================================================

View File

@@ -5,10 +5,8 @@
#include <cctype> #include <cctype>
#include <functional> #include <functional>
#include <iostream>
#include <map> #include <map>
#include <memory> #include <memory>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>