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

@@ -8,10 +8,10 @@ namespace app {
namespace gui { namespace gui {
// TODO: Add more display settings to popup windows. // TODO: Add more display settings to popup windows.
void BeginWindowWithDisplaySettings(const char* id, bool* active, void BeginWindowWithDisplaySettings(const char *id, bool *active,
const ImVec2& size, const ImVec2 &size,
ImGuiWindowFlags flags) { ImGuiWindowFlags flags) {
ImGuiStyle* ref = &ImGui::GetStyle(); ImGuiStyle *ref = &ImGui::GetStyle();
static float childBgOpacity = 0.75f; static float childBgOpacity = 0.75f;
auto color = ref->Colors[ImGuiCol_WindowBg]; auto color = ref->Colors[ImGuiCol_WindowBg];
@@ -45,42 +45,45 @@ void BeginNoPadding() {
} }
void EndNoPadding() { ImGui::PopStyleVar(2); } void EndNoPadding() { ImGui::PopStyleVar(2); }
void BeginChildWithScrollbar(const char* str_id) { void BeginChildWithScrollbar(const char *str_id) {
ImGui::BeginChild(str_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(str_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar); ImGuiWindowFlags_AlwaysVerticalScrollbar);
} }
void BeginChildBothScrollbars(int id) { void BeginChildBothScrollbars(int id) {
ImGuiID child_id = ImGui::GetID((void*)(intptr_t)id); ImGuiID child_id = ImGui::GetID((void *)(intptr_t)id);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysVerticalScrollbar |
ImGuiWindowFlags_AlwaysHorizontalScrollbar); ImGuiWindowFlags_AlwaysHorizontalScrollbar);
} }
void DrawDisplaySettings(ImGuiStyle* ref) { void DrawDisplaySettings(ImGuiStyle *ref) {
// You can pass in a reference ImGuiStyle structure to compare to, revert to // You can pass in a reference ImGuiStyle structure to compare to, revert to
// and save to (without a reference style pointer, we will use one compared // and save to (without a reference style pointer, we will use one compared
// locally as a reference) // locally as a reference)
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle &style = ImGui::GetStyle();
static ImGuiStyle ref_saved_style; static ImGuiStyle ref_saved_style;
// 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
// representing 0.0f or 1.0f) // representing 0.0f or 1.0f)
if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
"%.0f")) "%.0f"))
style.GrabRounding = style.FrameRounding; // Make GrabRounding always the style.GrabRounding = style.FrameRounding; // Make GrabRounding always the
// same value as FrameRounding // same value as FrameRounding
{ {
bool border = (style.WindowBorderSize > 0.0f); bool border = (style.WindowBorderSize > 0.0f);
if (ImGui::Checkbox("WindowBorder", &border)) { if (ImGui::Checkbox("WindowBorder", &border)) {
@@ -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();
@@ -113,16 +118,17 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) { if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) {
if (ImGui::BeginTabItem("Sizes")) { if (ImGui::BeginTabItem("Sizes")) {
ImGui::SeparatorText("Main"); ImGui::SeparatorText("Main");
ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, ImGui::SliderFloat2("WindowPadding", (float *)&style.WindowPadding, 0.0f,
20.0f, "%.0f"); 20.0f, "%.0f");
ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, ImGui::SliderFloat2("FramePadding", (float *)&style.FramePadding, 0.0f,
20.0f, "%.0f"); 20.0f, "%.0f");
ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, ImGui::SliderFloat2("ItemSpacing", (float *)&style.ItemSpacing, 0.0f,
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,
@@ -161,32 +167,32 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
"%.0f"); "%.0f");
ImGui::SeparatorText("Tables"); ImGui::SeparatorText("Tables");
ImGui::SliderFloat2("CellPadding", (float*)&style.CellPadding, 0.0f, ImGui::SliderFloat2("CellPadding", (float *)&style.CellPadding, 0.0f,
20.0f, "%.0f"); 20.0f, "%.0f");
ImGui::SliderAngle("TableAngledHeadersAngle", ImGui::SliderAngle("TableAngledHeadersAngle",
&style.TableAngledHeadersAngle, -50.0f, +50.0f); &style.TableAngledHeadersAngle, -50.0f, +50.0f);
ImGui::SeparatorText("Widgets"); ImGui::SeparatorText("Widgets");
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, ImGui::SliderFloat2("WindowTitleAlign", (float *)&style.WindowTitleAlign,
0.0f, 1.0f, "%.2f"); 0.0f, 1.0f, "%.2f");
ImGui::Combo("ColorButtonPosition", (int*)&style.ColorButtonPosition, ImGui::Combo("ColorButtonPosition", (int *)&style.ColorButtonPosition,
"Left\0Right\0"); "Left\0Right\0");
ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, ImGui::SliderFloat2("ButtonTextAlign", (float *)&style.ButtonTextAlign,
0.0f, 1.0f, "%.2f"); 0.0f, 1.0f, "%.2f");
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat2("SelectableTextAlign", ImGui::SliderFloat2("SelectableTextAlign",
(float*)&style.SelectableTextAlign, 0.0f, 1.0f, (float *)&style.SelectableTextAlign, 0.0f, 1.0f,
"%.2f"); "%.2f");
ImGui::SameLine(); ImGui::SameLine();
ImGui::SliderFloat("SeparatorTextBorderSize", ImGui::SliderFloat("SeparatorTextBorderSize",
&style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f"); &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f");
ImGui::SliderFloat2("SeparatorTextAlign", ImGui::SliderFloat2("SeparatorTextAlign",
(float*)&style.SeparatorTextAlign, 0.0f, 1.0f, (float *)&style.SeparatorTextAlign, 0.0f, 1.0f,
"%.2f"); "%.2f");
ImGui::SliderFloat2("SeparatorTextPadding", ImGui::SliderFloat2("SeparatorTextPadding",
(float*)&style.SeparatorTextPadding, 0.0f, 40.0f, (float *)&style.SeparatorTextPadding, 0.0f, 40.0f,
"%.0f"); "%.0f");
ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f, ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f,
12.0f, "%.0f"); 12.0f, "%.0f");
@@ -195,7 +201,7 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
for (int n = 0; n < 2; n++) for (int n = 0; n < 2; n++)
if (ImGui::TreeNodeEx(n == 0 ? "HoverFlagsForTooltipMouse" if (ImGui::TreeNodeEx(n == 0 ? "HoverFlagsForTooltipMouse"
: "HoverFlagsForTooltipNav")) { : "HoverFlagsForTooltipNav")) {
ImGuiHoveredFlags* p = (n == 0) ? &style.HoverFlagsForTooltipMouse ImGuiHoveredFlags *p = (n == 0) ? &style.HoverFlagsForTooltipMouse
: &style.HoverFlagsForTooltipNav; : &style.HoverFlagsForTooltipNav;
ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNone", p, ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNone", p,
ImGuiHoveredFlags_DelayNone); ImGuiHoveredFlags_DelayNone);
@@ -212,7 +218,7 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
ImGui::SeparatorText("Misc"); ImGui::SeparatorText("Misc");
ImGui::SliderFloat2("DisplaySafeAreaPadding", ImGui::SliderFloat2("DisplaySafeAreaPadding",
(float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, (float *)&style.DisplaySafeAreaPadding, 0.0f, 30.0f,
"%.0f"); "%.0f");
ImGui::SameLine(); ImGui::SameLine();
@@ -229,8 +235,8 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
ImGui::LogToTTY(); ImGui::LogToTTY();
ImGui::LogText("ImVec4* colors = ImGui::GetStyle().Colors;" IM_NEWLINE); ImGui::LogText("ImVec4* colors = ImGui::GetStyle().Colors;" IM_NEWLINE);
for (int i = 0; i < ImGuiCol_COUNT; i++) { for (int i = 0; i < ImGuiCol_COUNT; i++) {
const ImVec4& col = style.Colors[i]; const ImVec4 &col = style.Colors[i];
const char* name = ImGui::GetStyleColorName(i); const char *name = ImGui::GetStyleColorName(i);
if (!output_only_modified || if (!output_only_modified ||
memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0) memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0)
ImGui::LogText( ImGui::LogText(
@@ -275,10 +281,11 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
ImGuiWindowFlags_NavFlattened); ImGuiWindowFlags_NavFlattened);
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);
if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) { if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) {
// Tips: in a real user application, you may want to merge and use // Tips: in a real user application, you may want to merge and use
@@ -305,8 +312,8 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
} }
if (ImGui::BeginTabItem("Fonts")) { if (ImGui::BeginTabItem("Fonts")) {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
ImFontAtlas* atlas = io.Fonts; ImFontAtlas *atlas = io.Fonts;
ImGui::ShowFontAtlas(atlas); ImGui::ShowFontAtlas(atlas);
// Post-baking font scaling. Note that this is NOT the nice way of // Post-baking font scaling. Note that this is NOT the nice way of
@@ -321,11 +328,11 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
if (ImGui::DragFloat( if (ImGui::DragFloat(
"window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE,
"%.2f", "%.2f",
ImGuiSliderFlags_AlwaysClamp)) // Scale only this window ImGuiSliderFlags_AlwaysClamp)) // Scale only this window
ImGui::SetWindowFontScale(window_scale); ImGui::SetWindowFontScale(window_scale);
ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE,
MAX_SCALE, "%.2f", MAX_SCALE, "%.2f",
ImGuiSliderFlags_AlwaysClamp); // Scale everything ImGuiSliderFlags_AlwaysClamp); // Scale everything
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::EndTabItem(); ImGui::EndTabItem();
@@ -353,11 +360,12 @@ 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();
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList *draw_list = ImGui::GetWindowDrawList();
const float min_widget_width = ImGui::CalcTextSize("N: MMM\nR: MMM").x; const float min_widget_width = ImGui::CalcTextSize("N: MMM\nR: MMM").x;
for (int n = 0; n < 8; n++) { for (int n = 0; n < 8; n++) {
const float RAD_MIN = 5.0f; const float RAD_MIN = 5.0f;
@@ -394,10 +402,10 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
ImGui::SameLine(); ImGui::SameLine();
ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f,
"%.2f"); // Not exposing zero here so user doesn't "%.2f"); // Not exposing zero here so user doesn't
// "lose" the UI (zero alpha clips all // "lose" the UI (zero alpha clips all
// widgets). But application code could have a // widgets). But application code could have a
// toggle to switch between zero and non-zero. // toggle to switch between zero and non-zero.
ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f, ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f,
1.0f, "%.2f"); 1.0f, "%.2f");
ImGui::SameLine(); ImGui::SameLine();
@@ -413,7 +421,7 @@ void DrawDisplaySettings(ImGuiStyle* ref) {
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
void TextWithSeparators(const absl::string_view& text) { void TextWithSeparators(const absl::string_view &text) {
ImGui::Separator(); ImGui::Separator();
ImGui::Text("%s", text.data()); ImGui::Text("%s", text.data());
ImGui::Separator(); ImGui::Separator();
@@ -421,8 +429,8 @@ void TextWithSeparators(const absl::string_view& text) {
// TODO: Make the ColorsYaze style into a configuration file. // TODO: Make the ColorsYaze style into a configuration file.
void ColorsYaze() { void ColorsYaze() {
ImGuiStyle* style = &ImGui::GetStyle(); ImGuiStyle *style = &ImGui::GetStyle();
ImVec4* colors = style->Colors; ImVec4 *colors = style->Colors;
style->WindowPadding = ImVec2(10.f, 10.f); style->WindowPadding = ImVec2(10.f, 10.f);
style->FramePadding = ImVec2(10.f, 2.f); style->FramePadding = ImVec2(10.f, 2.f);
@@ -508,7 +516,7 @@ void ColorsYaze() {
colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen; colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen;
colors[ImGuiCol_TableBorderStrong] = alttpMidGreen; colors[ImGuiCol_TableBorderStrong] = alttpMidGreen;
colors[ImGuiCol_TableBorderLight] = colors[ImGuiCol_TableBorderLight] =
ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f); colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
@@ -519,11 +527,50 @@ 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
// ============================================================================ // ============================================================================
static const char* const kKeywords[] = { static const char *const kKeywords[] = {
"ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE", "ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE",
"BPL", "BRA", "BRL", "BVC", "BVS", "CLC", "CLD", "CLI", "CLV", "BPL", "BRA", "BRL", "BVC", "BVS", "CLC", "CLD", "CLI", "CLV",
"CMP", "CPX", "CPY", "DEC", "DEX", "DEY", "EOR", "INC", "INX", "CMP", "CPX", "CPY", "DEC", "DEX", "DEY", "EOR", "INC", "INX",
@@ -535,7 +582,7 @@ static const char* const kKeywords[] = {
"TRB", "TSB", "TSC", "TSX", "TXA", "TXS", "TXY", "TYA", "TYX", "TRB", "TSB", "TSC", "TSX", "TXA", "TXS", "TXY", "TYA", "TYX",
"WAI", "WDM", "XBA", "XCE", "ORG", "LOROM", "HIROM", "NAMESPACE", "DB"}; "WAI", "WDM", "XBA", "XCE", "ORG", "LOROM", "HIROM", "NAMESPACE", "DB"};
static const char* const kIdentifiers[] = { static const char *const kIdentifiers[] = {
"abort", "abs", "acos", "asin", "atan", "atexit", "abort", "abs", "acos", "asin", "atan", "atexit",
"atof", "atoi", "atol", "ceil", "clock", "cosh", "atof", "atoi", "atol", "ceil", "clock", "cosh",
"ctime", "div", "exit", "fabs", "floor", "fmod", "ctime", "div", "exit", "fabs", "floor", "fmod",
@@ -548,9 +595,10 @@ 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;
id.mDeclaration = "Built-in function"; id.mDeclaration = "Built-in function";
language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id)); language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id));
@@ -600,6 +648,6 @@ TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
return language_65816; return language_65816;
} }
} // namespace gui } // namespace gui
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -12,13 +12,12 @@
#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 {
void BeginWindowWithDisplaySettings(const char* id, bool* active, void BeginWindowWithDisplaySettings(const char *id, bool *active,
const ImVec2& size = ImVec2(0, 0), const ImVec2 &size = ImVec2(0, 0),
ImGuiWindowFlags flags = 0); ImGuiWindowFlags flags = 0);
void EndWindowWithDisplaySettings(); void EndWindowWithDisplaySettings();
@@ -29,69 +28,24 @@ void EndPadding();
void BeginNoPadding(); void BeginNoPadding();
void EndNoPadding(); void EndNoPadding();
void BeginChildWithScrollbar(const char* str_id); void BeginChildWithScrollbar(const char *str_id);
void BeginChildBothScrollbars(int id); void BeginChildBothScrollbars(int id);
void DrawDisplaySettings(ImGuiStyle* ref = nullptr); void DrawDisplaySettings(ImGuiStyle *ref = nullptr);
void TextWithSeparators(const absl::string_view& text); void TextWithSeparators(const absl::string_view &text);
void ColorsYaze(); 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_;
};
// ============================================================================ // ============================================================================
static const char* ExampleNames[] = { static const char *ExampleNames[] = {
"Artichoke", "Arugula", "Asparagus", "Avocado", "Artichoke", "Arugula", "Asparagus", "Avocado",
"Bamboo Shoots", "Bean Sprouts", "Beans", "Beet", "Bamboo Shoots", "Bean Sprouts", "Beans", "Beet",
"Belgian Endive", "Bell Pepper", "Bitter Gourd", "Bok Choy", "Belgian Endive", "Bell Pepper", "Bitter Gourd", "Bok Choy",
@@ -113,7 +67,7 @@ struct MultiSelectWithClipper {
ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY)) { ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY)) {
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape |
ImGuiMultiSelectFlags_BoxSelect1d; ImGuiMultiSelectFlags_BoxSelect1d;
ImGuiMultiSelectIO* ms_io = ImGuiMultiSelectIO *ms_io =
ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT); ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT);
selection.ApplyRequests(ms_io); selection.ApplyRequests(ms_io);
@@ -121,7 +75,7 @@ struct MultiSelectWithClipper {
clipper.Begin(ITEMS_COUNT); clipper.Begin(ITEMS_COUNT);
if (ms_io->RangeSrcItem != -1) if (ms_io->RangeSrcItem != -1)
clipper.IncludeItemByIndex( clipper.IncludeItemByIndex(
(int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped. (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
while (clipper.Step()) { while (clipper.Step()) {
for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++) { for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++) {
char label[64]; char label[64];
@@ -141,8 +95,8 @@ struct MultiSelectWithClipper {
} }
}; };
} // namespace gui } // namespace gui
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze
#endif #endif

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>