yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_STYLE_H
2#define YAZE_APP_CORE_STYLE_H
3
4#include "ImGuiColorTextEdit/TextEditor.h"
5#include "imgui/imgui.h"
6#include "imgui/misc/cpp/imgui_stdlib.h"
7
8#include <functional>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/strings/string_view.h"
13#include "app/core/constants.h"
14#include "app/gfx/bitmap.h"
15
16namespace yaze {
17namespace app {
18namespace gui {
19
20void BeginWindowWithDisplaySettings(const char* id, bool* active,
21 const ImVec2& size = ImVec2(0, 0),
22 ImGuiWindowFlags flags = 0);
23
25
26void BeginPadding(int i);
27void EndPadding();
28
29void BeginNoPadding();
30void EndNoPadding();
31
32void BeginChildWithScrollbar(const char* str_id);
33
34void BeginChildBothScrollbars(int id);
35
36void DrawDisplaySettings(ImGuiStyle* ref = nullptr);
37
38void TextWithSeparators(const absl::string_view& text);
39
40void ColorsYaze();
41
42TextEditor::LanguageDefinition GetAssemblyLanguageDef();
43
45 public:
47
48 void Display(const std::vector<gfx::Bitmap>& bitmaps, float scale = 1.0f) {
49 if (bitmaps.empty()) {
50 ImGui::Text("No bitmaps available.");
51 return;
52 }
53
54 // Display the current bitmap index and total count.
55 ImGui::Text("Viewing Bitmap %d / %zu", current_bitmap_index_ + 1,
56 bitmaps.size());
57
58 // Buttons to navigate through bitmaps.
59 if (ImGui::Button("<- Prev")) {
60 if (current_bitmap_index_ > 0) {
62 }
63 }
64 ImGui::SameLine();
65 if (ImGui::Button("Next ->")) {
66 if (current_bitmap_index_ < bitmaps.size() - 1) {
68 }
69 }
70
71 // Display the current bitmap.
72 const gfx::Bitmap& current_bitmap = bitmaps[current_bitmap_index_];
73 // Assuming Bitmap has a function to get its texture ID, and width and
74 // height.
75 ImTextureID tex_id = current_bitmap.texture();
76 ImVec2 size(current_bitmap.width() * scale,
77 current_bitmap.height() * scale);
78 // ImGui::Image(tex_id, size);
79
80 // Scroll if the image is larger than the display area.
81 if (ImGui::BeginChild("BitmapScrollArea", ImVec2(0, 0), false,
82 ImGuiWindowFlags_HorizontalScrollbar)) {
83 ImGui::Image(tex_id, size);
84 ImGui::EndChild();
85 }
86 }
87
88 private:
90};
91
92// ============================================================================
93
94static const char* ExampleNames[] = {
95 "Artichoke", "Arugula", "Asparagus", "Avocado",
96 "Bamboo Shoots", "Bean Sprouts", "Beans", "Beet",
97 "Belgian Endive", "Bell Pepper", "Bitter Gourd", "Bok Choy",
98 "Broccoli", "Brussels Sprouts", "Burdock Root", "Cabbage",
99 "Calabash", "Capers", "Carrot", "Cassava",
100 "Cauliflower", "Celery", "Celery Root", "Celcuce",
101 "Chayote", "Chinese Broccoli", "Corn", "Cucumber"};
102
104 const int ITEMS_COUNT = 10000;
105 void Update() {
106 // Use default selection.Adapter: Pass index to
107 // SetNextItemSelectionUserData(), store index in Selection
108 static ImGuiSelectionBasicStorage selection;
109
110 ImGui::Text("Selection: %d/%d", selection.Size, ITEMS_COUNT);
111 if (ImGui::BeginChild(
112 "##Basket", ImVec2(-FLT_MIN, ImGui::GetFontSize() * 20),
113 ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY)) {
114 ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape |
115 ImGuiMultiSelectFlags_BoxSelect1d;
116 ImGuiMultiSelectIO* ms_io =
117 ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT);
118 selection.ApplyRequests(ms_io);
119
120 ImGuiListClipper clipper;
121 clipper.Begin(ITEMS_COUNT);
122 if (ms_io->RangeSrcItem != -1)
123 clipper.IncludeItemByIndex(
124 (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
125 while (clipper.Step()) {
126 for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++) {
127 char label[64];
128 // sprintf(label, "Object %05d: %s", n,
129 // ExampleNames[n % IM_ARRAYSIZE(ExampleNames)]);
130 bool item_is_selected = selection.Contains((ImGuiID)n);
131 ImGui::SetNextItemSelectionUserData(n);
132 ImGui::Selectable(label, item_is_selected);
133 }
134 }
135
136 ms_io = ImGui::EndMultiSelect();
137 selection.ApplyRequests(ms_io);
138 }
139 ImGui::EndChild();
140 ImGui::TreePop();
141 }
142};
143
144} // namespace gui
145} // namespace app
146} // namespace yaze
147
148#endif
Represents a bitmap image.
Definition bitmap.h:70
auto texture() const
Definition bitmap.h:193
int height() const
Definition bitmap.h:180
int width() const
Definition bitmap.h:179
void Display(const std::vector< gfx::Bitmap > &bitmaps, float scale=1.0f)
Definition style.h:48
void DrawDisplaySettings(ImGuiStyle *ref)
Definition style.cc:60
TextEditor::LanguageDefinition GetAssemblyLanguageDef()
Definition style.cc:549
void EndPadding()
Definition style.cc:40
void BeginChildWithScrollbar(const char *str_id)
Definition style.cc:48
void BeginPadding(int i)
Definition style.cc:36
void BeginWindowWithDisplaySettings(const char *id, bool *active, const ImVec2 &size, ImGuiWindowFlags flags)
Definition style.cc:11
void BeginChildBothScrollbars(int id)
Definition style.cc:53
void ColorsYaze()
Definition style.cc:423
void EndNoPadding()
Definition style.cc:46
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:416
void BeginNoPadding()
Definition style.cc:42
void EndWindowWithDisplaySettings()
Definition style.cc:31
Definition common.cc:21