yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
style.cc
Go to the documentation of this file.
1#include "style.h"
2
5#include "gui/color.h"
6#include "imgui/imgui.h"
7#include "imgui/imgui_internal.h"
8
9namespace yaze {
10namespace gui {
11
12namespace {
13Color ParseColor(const std::string &color) {
14 Color result;
15 if (color.size() == 7 && color[0] == '#') {
16 result.red = std::stoi(color.substr(1, 2), nullptr, 16) / 255.0f;
17 result.green = std::stoi(color.substr(3, 2), nullptr, 16) / 255.0f;
18 result.blue = std::stoi(color.substr(5, 2), nullptr, 16) / 255.0f;
19 } else {
20 throw std::invalid_argument("Invalid color format: " + color);
21 }
22 return result;
23}
24
25absl::Status ParseThemeContents(const std::string &key,
26 const std::string &value, Theme &theme) {
27 try {
28 if (key == "MenuBarBg") {
29 theme.menu_bar_bg = ParseColor(value);
30 } else if (key == "TitleBgActive") {
31 theme.title_bg_active = ParseColor(value);
32 } else if (key == "TitleBgCollapsed") {
33 theme.title_bg_collapsed = ParseColor(value);
34 } else if (key == "Tab") {
35 theme.tab = ParseColor(value);
36 } else if (key == "TabHovered") {
37 theme.tab_hovered = ParseColor(value);
38 } else if (key == "TabActive") {
39 theme.tab_active = ParseColor(value);
40 }
41 } catch (const std::exception &e) {
42 return absl::InvalidArgumentError(e.what());
43 }
44 return absl::OkStatus();
45}
46
47} // namespace
48
49absl::StatusOr<Theme> LoadTheme(const std::string &filename) {
50 std::string theme_contents;
51 try {
52 theme_contents = core::LoadFile(filename);
53 } catch (const std::exception &e) {
54 return absl::InternalError(e.what());
55 }
56
57 Theme theme;
58 std::istringstream theme_stream(theme_contents);
59 while (theme_stream.good()) {
60 std::string line;
61 std::getline(theme_stream, line);
62 if (line.empty()) {
63 continue;
64 }
65
66 std::istringstream line_stream(line);
67 std::string key;
68 std::string value;
69 std::getline(line_stream, key, '=');
70 std::getline(line_stream, value);
71 RETURN_IF_ERROR(ParseThemeContents(key, value, theme));
72 }
73 return theme;
74}
75
76absl::Status SaveTheme(const Theme &theme) {
77 std::ostringstream theme_stream;
78 theme_stream << theme.name << "Theme\n";
79 theme_stream << "MenuBarBg=#" << gui::ColorToHexString(theme.menu_bar_bg)
80 << "\n";
81 theme_stream << "TitleBg=#" << gui::ColorToHexString(theme.title_bar_bg) << "\n";
82 theme_stream << "Header=#" << gui::ColorToHexString(theme.header) << "\n";
83 theme_stream << "HeaderHovered=#" << gui::ColorToHexString(theme.header_hovered) << "\n";
84 theme_stream << "HeaderActive=#" << gui::ColorToHexString(theme.header_active) << "\n";
85 theme_stream << "TitleBgActive=#" << gui::ColorToHexString(theme.title_bg_active) << "\n";
86 theme_stream << "TitleBgCollapsed=#" << gui::ColorToHexString(theme.title_bg_collapsed) << "\n";
87 theme_stream << "Tab=#" << gui::ColorToHexString(theme.tab) << "\n";
88 theme_stream << "TabHovered=#" << gui::ColorToHexString(theme.tab_hovered) << "\n";
89 theme_stream << "TabActive=#" << gui::ColorToHexString(theme.tab_active) << "\n";
90 theme_stream << "Button=#" << gui::ColorToHexString(theme.button) << "\n";
91 theme_stream << "ButtonHovered=#" << gui::ColorToHexString(theme.button_hovered) << "\n";
92 theme_stream << "ButtonActive=#" << gui::ColorToHexString(theme.button_active) << "\n";
93
94 // Save the theme to a file.
95
96 return absl::OkStatus();
97}
98
99void ApplyTheme(const Theme &theme) {
100 ImGuiStyle *style = &ImGui::GetStyle();
101 ImVec4 *colors = style->Colors;
102
103 colors[ImGuiCol_MenuBarBg] = gui::ConvertColorToImVec4(theme.menu_bar_bg);
104 colors[ImGuiCol_TitleBg] = gui::ConvertColorToImVec4(theme.title_bar_bg);
105 colors[ImGuiCol_Header] = gui::ConvertColorToImVec4(theme.header);
106 colors[ImGuiCol_HeaderHovered] = gui::ConvertColorToImVec4(theme.header_hovered);
107 colors[ImGuiCol_HeaderActive] = gui::ConvertColorToImVec4(theme.header_active);
108 colors[ImGuiCol_TitleBgActive] = gui::ConvertColorToImVec4(theme.title_bg_active);
109 colors[ImGuiCol_TitleBgCollapsed] = gui::ConvertColorToImVec4(theme.title_bg_collapsed);
110 colors[ImGuiCol_Tab] = gui::ConvertColorToImVec4(theme.tab);
111 colors[ImGuiCol_TabHovered] = gui::ConvertColorToImVec4(theme.tab_hovered);
112 colors[ImGuiCol_TabActive] = gui::ConvertColorToImVec4(theme.tab_active);
113 colors[ImGuiCol_Button] = gui::ConvertColorToImVec4(theme.button);
114 colors[ImGuiCol_ButtonHovered] = gui::ConvertColorToImVec4(theme.button_hovered);
115 colors[ImGuiCol_ButtonActive] = gui::ConvertColorToImVec4(theme.button_active);
116}
117
119 ImGuiStyle *style = &ImGui::GetStyle();
120 ImVec4 *colors = style->Colors;
121
122 style->WindowPadding = ImVec2(10.f, 10.f);
123 style->FramePadding = ImVec2(10.f, 2.f);
124 style->CellPadding = ImVec2(4.f, 5.f);
125 style->ItemSpacing = ImVec2(10.f, 5.f);
126 style->ItemInnerSpacing = ImVec2(5.f, 5.f);
127 style->TouchExtraPadding = ImVec2(0.f, 0.f);
128 style->IndentSpacing = 20.f;
129 style->ScrollbarSize = 14.f;
130 style->GrabMinSize = 15.f;
131
132 style->WindowBorderSize = 0.f;
133 style->ChildBorderSize = 1.f;
134 style->PopupBorderSize = 1.f;
135 style->FrameBorderSize = 0.f;
136 style->TabBorderSize = 0.f;
137
138 style->WindowRounding = 0.f;
139 style->ChildRounding = 0.f;
140 style->FrameRounding = 5.f;
141 style->PopupRounding = 0.f;
142 style->ScrollbarRounding = 5.f;
143
144 auto alttpDarkGreen = ImVec4(0.18f, 0.26f, 0.18f, 1.0f);
145 auto alttpMidGreen = ImVec4(0.28f, 0.36f, 0.28f, 1.0f);
146 auto allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f);
147 auto allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f);
148
149 colors[ImGuiCol_MenuBarBg] = alttpDarkGreen;
150 colors[ImGuiCol_TitleBg] = alttpMidGreen;
151
152 colors[ImGuiCol_Header] = alttpDarkGreen;
153 colors[ImGuiCol_HeaderHovered] = allttpLightGreen;
154 colors[ImGuiCol_HeaderActive] = alttpMidGreen;
155
156 colors[ImGuiCol_TitleBgActive] = alttpDarkGreen;
157 colors[ImGuiCol_TitleBgCollapsed] = alttpMidGreen;
158
159 colors[ImGuiCol_Tab] = alttpDarkGreen;
160 colors[ImGuiCol_TabHovered] = alttpMidGreen;
161 colors[ImGuiCol_TabActive] = ImVec4(0.347f, 0.466f, 0.347f, 1.000f);
162
163 colors[ImGuiCol_Button] = alttpMidGreen;
164 colors[ImGuiCol_ButtonHovered] = allttpLightestGreen;
165 colors[ImGuiCol_ButtonActive] = allttpLightGreen;
166
167 colors[ImGuiCol_ScrollbarBg] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
168 colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.45f, 0.36f, 0.30f);
169 colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.36f, 0.45f, 0.36f, 0.40f);
170 colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
171
172 colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
173 colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
174 colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f);
175 colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
176 colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f);
177 colors[ImGuiCol_Border] = allttpLightGreen;
178 colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
179
180 colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f);
181 colors[ImGuiCol_FrameBgHovered] = ImVec4(0.28f, 0.36f, 0.28f, 0.40f);
182 colors[ImGuiCol_FrameBgActive] = ImVec4(0.28f, 0.36f, 0.28f, 0.69f);
183
184 colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
185 colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
186 colors[ImGuiCol_SliderGrabActive] = ImVec4(0.36f, 0.45f, 0.36f, 0.60f);
187
188 colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f);
189 colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f);
190 colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f);
191 colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
192 colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f);
193 colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f);
194
195 colors[ImGuiCol_TabUnfocused] =
196 ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
197 colors[ImGuiCol_TabUnfocusedActive] =
198 ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f);
199 colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
200 colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
201 colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
202 colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
203 colors[ImGuiCol_TableHeaderBg] = alttpDarkGreen;
204 colors[ImGuiCol_TableBorderStrong] = alttpMidGreen;
205 colors[ImGuiCol_TableBorderLight] =
206 ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
207 colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
208 colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
209 colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
210 colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
211 colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];
212 colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
213 colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
214 colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
215}
216
217void DrawBitmapViewer(const std::vector<gfx::Bitmap> &bitmaps, float scale,
218 int &current_bitmap_id) {
219 if (bitmaps.empty()) {
220 ImGui::Text("No bitmaps available.");
221 return;
222 }
223
224 // Display the current bitmap index and total count.
225 ImGui::Text("Viewing Bitmap %d / %zu", current_bitmap_id + 1, bitmaps.size());
226
227 // Buttons to navigate through bitmaps.
228 if (ImGui::Button("<- Prev")) {
229 if (current_bitmap_id > 0) {
230 --current_bitmap_id;
231 }
232 }
233 ImGui::SameLine();
234 if (ImGui::Button("Next ->")) {
235 if (current_bitmap_id < bitmaps.size() - 1) {
236 ++current_bitmap_id;
237 }
238 }
239
240 // Display the current bitmap.
241 const gfx::Bitmap &current_bitmap = bitmaps[current_bitmap_id];
242 // Assuming Bitmap has a function to get its texture ID, and width and
243 // height.
244 ImTextureID tex_id = (ImTextureID)(intptr_t)current_bitmap.texture();
245 ImVec2 size(current_bitmap.width() * scale, current_bitmap.height() * scale);
246 // ImGui::Image(tex_id, size);
247
248 // Scroll if the image is larger than the display area.
249 if (ImGui::BeginChild("BitmapScrollArea", ImVec2(0, 0), false,
250 ImGuiWindowFlags_HorizontalScrollbar)) {
251 ImGui::Image(tex_id, size);
252 ImGui::EndChild();
253 }
254}
255
256static const char *const kKeywords[] = {
257 "ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE", "BPL",
258 "BRA", "BRL", "BVC", "BVS", "CLC", "CLD", "CLI", "CLV", "CMP", "CPX",
259 "CPY", "DEC", "DEX", "DEY", "EOR", "INC", "INX", "INY", "JMP", "JSR",
260 "JSL", "LDA", "LDX", "LDY", "LSR", "MVN", "NOP", "ORA", "PEA", "PER",
261 "PHA", "PHB", "PHD", "PHP", "PHX", "PHY", "PLA", "PLB", "PLD", "PLP",
262 "PLX", "PLY", "REP", "ROL", "ROR", "RTI", "RTL", "RTS", "SBC", "SEC",
263 "SEI", "SEP", "STA", "STP", "STX", "STY", "STZ", "TAX", "TAY", "TCD",
264 "TCS", "TDC", "TRB", "TSB", "TSC", "TSX", "TXA", "TXS", "TXY", "TYA",
265 "TYX", "WAI", "WDM", "XBA", "XCE", "ORG", "LOROM", "HIROM"};
266
267static const char *const kIdentifiers[] = {
268 "abort", "abs", "acos", "asin", "atan", "atexit",
269 "atof", "atoi", "atol", "ceil", "clock", "cosh",
270 "ctime", "div", "exit", "fabs", "floor", "fmod",
271 "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
272 "ispunct", "isspace", "isupper", "kbhit", "log10", "log2",
273 "log", "memcmp", "modf", "pow", "putchar", "putenv",
274 "puts", "rand", "remove", "rename", "sinh", "sqrt",
275 "srand", "strcat", "strcmp", "strerror", "time", "tolower",
276 "toupper"};
277
279 TextEditor::LanguageDefinition language_65816;
280 for (auto &k : kKeywords)
281 language_65816.mKeywords.emplace(k);
282
283 for (auto &k : kIdentifiers) {
285 id.mDeclaration = "Built-in function";
286 language_65816.mIdentifiers.insert(std::make_pair(std::string(k), id));
287 }
288
289 language_65816.mTokenRegexStrings.push_back(
290 std::make_pair<std::string, TextEditor::PaletteIndex>(
291 "[ \\t]*#[ \\t]*[a-zA-Z_]+", TextEditor::PaletteIndex::Preprocessor));
292 language_65816.mTokenRegexStrings.push_back(
293 std::make_pair<std::string, TextEditor::PaletteIndex>(
294 "L?\\\"(\\\\.|[^\\\"])*\\\"", TextEditor::PaletteIndex::String));
295 language_65816.mTokenRegexStrings.push_back(
296 std::make_pair<std::string, TextEditor::PaletteIndex>(
297 "\\'\\\\?[^\\']\\'", TextEditor::PaletteIndex::CharLiteral));
298 language_65816.mTokenRegexStrings.push_back(
299 std::make_pair<std::string, TextEditor::PaletteIndex>(
300 "[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",
302 language_65816.mTokenRegexStrings.push_back(
303 std::make_pair<std::string, TextEditor::PaletteIndex>(
304 "[+-]?[0-9]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
305 language_65816.mTokenRegexStrings.push_back(
306 std::make_pair<std::string, TextEditor::PaletteIndex>(
307 "0[0-7]+[Uu]?[lL]?[lL]?", TextEditor::PaletteIndex::Number));
308 language_65816.mTokenRegexStrings.push_back(
309 std::make_pair<std::string, TextEditor::PaletteIndex>(
310 "0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?",
312 language_65816.mTokenRegexStrings.push_back(
313 std::make_pair<std::string, TextEditor::PaletteIndex>(
314 "[a-zA-Z_][a-zA-Z0-9_]*", TextEditor::PaletteIndex::Identifier));
315 language_65816.mTokenRegexStrings.push_back(
316 std::make_pair<std::string, TextEditor::PaletteIndex>(
317 "[\\[\\]\\{\\}\\!\\%\\^\\&\\*\\(\\)\\-\\+\\=\\~\\|\\<\\>\\?\\/"
318 "\\;\\,\\.]",
320
321 language_65816.mCommentStart = "/*";
322 language_65816.mCommentEnd = "*/";
323 language_65816.mSingleLineComment = ";";
324
325 language_65816.mCaseSensitive = false;
326 language_65816.mAutoIndentation = true;
327
328 language_65816.mName = "65816";
329
330 return language_65816;
331}
332
333// TODO: Add more display settings to popup windows.
334void BeginWindowWithDisplaySettings(const char *id, bool *active,
335 const ImVec2 &size,
336 ImGuiWindowFlags flags) {
337 ImGuiStyle *ref = &ImGui::GetStyle();
338 static float childBgOpacity = 0.75f;
339 auto color = ref->Colors[ImGuiCol_WindowBg];
340
341 ImGui::PushStyleColor(ImGuiCol_WindowBg, color);
342 ImGui::PushStyleColor(ImGuiCol_ChildBg, color);
343 ImGui::PushStyleColor(ImGuiCol_Border, color);
344
345 ImGui::Begin(id, active, flags | ImGuiWindowFlags_MenuBar);
346 ImGui::BeginMenuBar();
347 if (ImGui::BeginMenu("Display Settings")) {
348 ImGui::SliderFloat("Child Background Opacity", &childBgOpacity, 0.0f, 1.0f);
349 ImGui::EndMenu();
350 }
351 ImGui::EndMenuBar();
352}
353
355 ImGui::End();
356 ImGui::PopStyleColor(3);
357}
358
359void BeginPadding(int i) {
360 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(i, i));
361 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(i, i));
362}
364
366 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
367 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
368}
369void EndNoPadding() { ImGui::PopStyleVar(2); }
370
371void BeginChildWithScrollbar(const char *str_id) {
372 ImGui::BeginChild(str_id, ImGui::GetContentRegionAvail(), true,
373 ImGuiWindowFlags_AlwaysVerticalScrollbar);
374}
375
377 ImGuiID child_id = ImGui::GetID((void *)(intptr_t)id);
378 ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
379 ImGuiWindowFlags_AlwaysVerticalScrollbar |
380 ImGuiWindowFlags_AlwaysHorizontalScrollbar);
381}
382
383void DrawDisplaySettings(ImGuiStyle *ref) {
384 // You can pass in a reference ImGuiStyle structure to compare to, revert to
385 // and save to (without a reference style pointer, we will use one compared
386 // locally as a reference)
387 ImGuiStyle &style = ImGui::GetStyle();
388 static ImGuiStyle ref_saved_style;
389
390 // Default to using internal storage as reference
391 static bool init = true;
392 if (init && ref == NULL)
393 ref_saved_style = style;
394 init = false;
395 if (ref == NULL)
396 ref = &ref_saved_style;
397
398 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
399
400 if (ImGui::ShowStyleSelector("Colors##Selector"))
401 ref_saved_style = style;
402 ImGui::ShowFontSelector("Fonts##Selector");
403
404 // Simplified Settings (expose floating-pointer border sizes as boolean
405 // representing 0.0f or 1.0f)
406 if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
407 "%.0f"))
408 style.GrabRounding = style.FrameRounding; // Make GrabRounding always the
409 // same value as FrameRounding
410 {
411 bool border = (style.WindowBorderSize > 0.0f);
412 if (ImGui::Checkbox("WindowBorder", &border)) {
413 style.WindowBorderSize = border ? 1.0f : 0.0f;
414 }
415 }
416 ImGui::SameLine();
417 {
418 bool border = (style.FrameBorderSize > 0.0f);
419 if (ImGui::Checkbox("FrameBorder", &border)) {
420 style.FrameBorderSize = border ? 1.0f : 0.0f;
421 }
422 }
423 ImGui::SameLine();
424 {
425 bool border = (style.PopupBorderSize > 0.0f);
426 if (ImGui::Checkbox("PopupBorder", &border)) {
427 style.PopupBorderSize = border ? 1.0f : 0.0f;
428 }
429 }
430
431 // Save/Revert button
432 if (ImGui::Button("Save Ref"))
433 *ref = ref_saved_style = style;
434 ImGui::SameLine();
435 if (ImGui::Button("Revert Ref"))
436 style = *ref;
437 ImGui::SameLine();
438
439 ImGui::Separator();
440
441 if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) {
442 if (ImGui::BeginTabItem("Sizes")) {
443 ImGui::SeparatorText("Main");
444 ImGui::SliderFloat2("WindowPadding", (float *)&style.WindowPadding, 0.0f,
445 20.0f, "%.0f");
446 ImGui::SliderFloat2("FramePadding", (float *)&style.FramePadding, 0.0f,
447 20.0f, "%.0f");
448 ImGui::SliderFloat2("ItemSpacing", (float *)&style.ItemSpacing, 0.0f,
449 20.0f, "%.0f");
450 ImGui::SliderFloat2("ItemInnerSpacing", (float *)&style.ItemInnerSpacing,
451 0.0f, 20.0f, "%.0f");
452 ImGui::SliderFloat2("TouchExtraPadding",
453 (float *)&style.TouchExtraPadding, 0.0f, 10.0f,
454 "%.0f");
455 ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f,
456 "%.0f");
457 ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f,
458 "%.0f");
459 ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f,
460 "%.0f");
461
462 ImGui::SeparatorText("Borders");
463 ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f,
464 1.0f, "%.0f");
465 ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f,
466 "%.0f");
467 ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f,
468 "%.0f");
469 ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f,
470 "%.0f");
471 ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f,
472 "%.0f");
473 ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f,
474 2.0f, "%.0f");
475
476 ImGui::SeparatorText("Rounding");
477 ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f,
478 "%.0f");
479 ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f,
480 "%.0f");
481 ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f,
482 "%.0f");
483 ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f,
484 "%.0f");
485 ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f,
486 12.0f, "%.0f");
487 ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f,
488 "%.0f");
489 ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f,
490 "%.0f");
491
492 ImGui::SeparatorText("Tables");
493 ImGui::SliderFloat2("CellPadding", (float *)&style.CellPadding, 0.0f,
494 20.0f, "%.0f");
495 ImGui::SliderAngle("TableAngledHeadersAngle",
496 &style.TableAngledHeadersAngle, -50.0f, +50.0f);
497
498 ImGui::SeparatorText("Widgets");
499 ImGui::SliderFloat2("WindowTitleAlign", (float *)&style.WindowTitleAlign,
500 0.0f, 1.0f, "%.2f");
501 ImGui::Combo("ColorButtonPosition", (int *)&style.ColorButtonPosition,
502 "Left\0Right\0");
503 ImGui::SliderFloat2("ButtonTextAlign", (float *)&style.ButtonTextAlign,
504 0.0f, 1.0f, "%.2f");
505 ImGui::SameLine();
506
507 ImGui::SliderFloat2("SelectableTextAlign",
508 (float *)&style.SelectableTextAlign, 0.0f, 1.0f,
509 "%.2f");
510 ImGui::SameLine();
511
512 ImGui::SliderFloat("SeparatorTextBorderSize",
513 &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f");
514 ImGui::SliderFloat2("SeparatorTextAlign",
515 (float *)&style.SeparatorTextAlign, 0.0f, 1.0f,
516 "%.2f");
517 ImGui::SliderFloat2("SeparatorTextPadding",
518 (float *)&style.SeparatorTextPadding, 0.0f, 40.0f,
519 "%.0f");
520 ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f,
521 12.0f, "%.0f");
522
523 ImGui::SeparatorText("Tooltips");
524 for (int n = 0; n < 2; n++)
525 if (ImGui::TreeNodeEx(n == 0 ? "HoverFlagsForTooltipMouse"
526 : "HoverFlagsForTooltipNav")) {
527 ImGuiHoveredFlags *p = (n == 0) ? &style.HoverFlagsForTooltipMouse
528 : &style.HoverFlagsForTooltipNav;
529 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNone", p,
530 ImGuiHoveredFlags_DelayNone);
531 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayShort", p,
532 ImGuiHoveredFlags_DelayShort);
533 ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNormal", p,
534 ImGuiHoveredFlags_DelayNormal);
535 ImGui::CheckboxFlags("ImGuiHoveredFlags_Stationary", p,
536 ImGuiHoveredFlags_Stationary);
537 ImGui::CheckboxFlags("ImGuiHoveredFlags_NoSharedDelay", p,
538 ImGuiHoveredFlags_NoSharedDelay);
539 ImGui::TreePop();
540 }
541
542 ImGui::SeparatorText("Misc");
543 ImGui::SliderFloat2("DisplaySafeAreaPadding",
544 (float *)&style.DisplaySafeAreaPadding, 0.0f, 30.0f,
545 "%.0f");
546 ImGui::SameLine();
547
548 ImGui::EndTabItem();
549 }
550
551 if (ImGui::BeginTabItem("Colors")) {
552 static int output_dest = 0;
553 static bool output_only_modified = true;
554 if (ImGui::Button("Export")) {
555 if (output_dest == 0)
556 ImGui::LogToClipboard();
557 else
558 ImGui::LogToTTY();
559 ImGui::LogText("ImVec4* colors = ImGui::GetStyle().Colors;" IM_NEWLINE);
560 for (int i = 0; i < ImGuiCol_COUNT; i++) {
561 const ImVec4 &col = style.Colors[i];
562 const char *name = ImGui::GetStyleColorName(i);
563 if (!output_only_modified ||
564 memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0)
565 ImGui::LogText(
566 "colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, "
567 "%.2ff);" IM_NEWLINE,
568 name, 23 - (int)strlen(name), "", col.x, col.y, col.z, col.w);
569 }
570 ImGui::LogFinish();
571 }
572 ImGui::SameLine();
573 ImGui::SetNextItemWidth(120);
574 ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0");
575 ImGui::SameLine();
576 ImGui::Checkbox("Only Modified Colors", &output_only_modified);
577
578 static ImGuiTextFilter filter;
579 filter.Draw("Filter colors", ImGui::GetFontSize() * 16);
580
581 static ImGuiColorEditFlags alpha_flags = 0;
582 if (ImGui::RadioButton("Opaque",
583 alpha_flags == ImGuiColorEditFlags_None)) {
584 alpha_flags = ImGuiColorEditFlags_None;
585 }
586 ImGui::SameLine();
587 if (ImGui::RadioButton("Alpha",
588 alpha_flags == ImGuiColorEditFlags_AlphaPreview)) {
589 alpha_flags = ImGuiColorEditFlags_AlphaPreview;
590 }
591 ImGui::SameLine();
592 if (ImGui::RadioButton(
593 "Both", alpha_flags == ImGuiColorEditFlags_AlphaPreviewHalf)) {
594 alpha_flags = ImGuiColorEditFlags_AlphaPreviewHalf;
595 }
596 ImGui::SameLine();
597
598 ImGui::SetNextWindowSizeConstraints(
599 ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 10),
600 ImVec2(FLT_MAX, FLT_MAX));
601 ImGui::BeginChild("##colors", ImVec2(0, 0), ImGuiChildFlags_Border,
602 ImGuiWindowFlags_AlwaysVerticalScrollbar |
603 ImGuiWindowFlags_AlwaysHorizontalScrollbar |
604 ImGuiWindowFlags_NavFlattened);
605 ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
606 for (int i = 0; i < ImGuiCol_COUNT; i++) {
607 const char *name = ImGui::GetStyleColorName(i);
608 if (!filter.PassFilter(name))
609 continue;
610 ImGui::PushID(i);
611 ImGui::ColorEdit4("##color", (float *)&style.Colors[i],
612 ImGuiColorEditFlags_AlphaBar | alpha_flags);
613 if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) {
614 // Tips: in a real user application, you may want to merge and use
615 // an icon font into the main font, so instead of "Save"/"Revert"
616 // you'd use icons! Read the FAQ and docs/FONTS.md about using icon
617 // fonts. It's really easy and super convenient!
618 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
619 if (ImGui::Button("Save")) {
620 ref->Colors[i] = style.Colors[i];
621 }
622 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
623 if (ImGui::Button("Revert")) {
624 style.Colors[i] = ref->Colors[i];
625 }
626 }
627 ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
628 ImGui::TextUnformatted(name);
629 ImGui::PopID();
630 }
631 ImGui::PopItemWidth();
632 ImGui::EndChild();
633
634 ImGui::EndTabItem();
635 }
636
637 if (ImGui::BeginTabItem("Fonts")) {
638 ImGuiIO &io = ImGui::GetIO();
639 ImFontAtlas *atlas = io.Fonts;
640 ImGui::ShowFontAtlas(atlas);
641
642 // Post-baking font scaling. Note that this is NOT the nice way of
643 // scaling fonts, read below. (we enforce hard clamping manually as by
644 // default DragFloat/SliderFloat allows CTRL+Click text to get out of
645 // bounds).
646 const float MIN_SCALE = 0.3f;
647 const float MAX_SCALE = 2.0f;
648
649 static float window_scale = 1.0f;
650 ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
651 if (ImGui::DragFloat(
652 "window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE,
653 "%.2f",
654 ImGuiSliderFlags_AlwaysClamp)) // Scale only this window
655 ImGui::SetWindowFontScale(window_scale);
656 ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE,
657 MAX_SCALE, "%.2f",
658 ImGuiSliderFlags_AlwaysClamp); // Scale everything
659 ImGui::PopItemWidth();
660
661 ImGui::EndTabItem();
662 }
663
664 if (ImGui::BeginTabItem("Rendering")) {
665 ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines);
666 ImGui::SameLine();
667
668 ImGui::Checkbox("Anti-aliased lines use texture",
669 &style.AntiAliasedLinesUseTex);
670 ImGui::SameLine();
671
672 ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
673 ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
674 ImGui::DragFloat("Curve Tessellation Tolerance",
675 &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f,
676 "%.2f");
677 if (style.CurveTessellationTol < 0.10f)
678 style.CurveTessellationTol = 0.10f;
679
680 // When editing the "Circle Segment Max Error" value, draw a preview of
681 // its effect on auto-tessellated circles.
682 ImGui::DragFloat("Circle Tessellation Max Error",
683 &style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f,
684 "%.2f", ImGuiSliderFlags_AlwaysClamp);
685 const bool show_samples = ImGui::IsItemActive();
686 if (show_samples)
687 ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
688 if (show_samples && ImGui::BeginTooltip()) {
689 ImGui::TextUnformatted("(R = radius, N = number of segments)");
690 ImGui::Spacing();
691 ImDrawList *draw_list = ImGui::GetWindowDrawList();
692 const float min_widget_width = ImGui::CalcTextSize("N: MMM\nR: MMM").x;
693 for (int n = 0; n < 8; n++) {
694 const float RAD_MIN = 5.0f;
695 const float RAD_MAX = 70.0f;
696 const float rad =
697 RAD_MIN + (RAD_MAX - RAD_MIN) * (float)n / (8.0f - 1.0f);
698
699 ImGui::BeginGroup();
700
701 ImGui::Text("R: %.f\nN: %d", rad,
702 draw_list->_CalcCircleAutoSegmentCount(rad));
703
704 const float canvas_width = std::max(min_widget_width, rad * 2.0f);
705 const float offset_x = floorf(canvas_width * 0.5f);
706 const float offset_y = floorf(RAD_MAX);
707
708 const ImVec2 p1 = ImGui::GetCursorScreenPos();
709 draw_list->AddCircle(ImVec2(p1.x + offset_x, p1.y + offset_y), rad,
710 ImGui::GetColorU32(ImGuiCol_Text));
711 ImGui::Dummy(ImVec2(canvas_width, RAD_MAX * 2));
712
713 /*
714 const ImVec2 p2 = ImGui::GetCursorScreenPos();
715 draw_list->AddCircleFilled(ImVec2(p2.x + offset_x, p2.y + offset_y),
716 rad, ImGui::GetColorU32(ImGuiCol_Text));
717 ImGui::Dummy(ImVec2(canvas_width, RAD_MAX * 2));
718 */
719
720 ImGui::EndGroup();
721 ImGui::SameLine();
722 }
723 ImGui::EndTooltip();
724 }
725 ImGui::SameLine();
726
727 ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f,
728 "%.2f"); // Not exposing zero here so user doesn't
729 // "lose" the UI (zero alpha clips all
730 // widgets). But application code could have a
731 // toggle to switch between zero and non-zero.
732 ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f,
733 1.0f, "%.2f");
734 ImGui::SameLine();
735
736 ImGui::PopItemWidth();
737
738 ImGui::EndTabItem();
739 }
740
741 ImGui::EndTabBar();
742 }
743
744 ImGui::PopItemWidth();
745}
746
747void TextWithSeparators(const absl::string_view &text) {
748 ImGui::Separator();
749 ImGui::Text("%s", text.data());
750 ImGui::Separator();
751}
752
754 ImGuiIO& io = ImGui::GetIO();
755 ImFontAtlas* atlas = io.Fonts;
756
757 static ImFont* current_font = atlas->Fonts[0];
758 static int current_font_index = 0;
759 static int font_size = 16;
760 static bool font_selected = false;
761
762 ImGui::Text("Loaded fonts");
763 for (const auto& loaded_font : core::global_font_state.fonts) {
764 ImGui::Text("%s", loaded_font.font_path);
765 }
766 ImGui::Separator();
767
768 ImGui::Text("Current Font: %s", current_font->GetDebugName());
769 ImGui::Text("Font Size: %d", font_size);
770
771 if (ImGui::BeginCombo("Fonts", current_font->GetDebugName())) {
772 for (int i = 0; i < atlas->Fonts.Size; i++) {
773 bool is_selected = (current_font == atlas->Fonts[i]);
774 if (ImGui::Selectable(atlas->Fonts[i]->GetDebugName(), is_selected)) {
775 current_font = atlas->Fonts[i];
776 current_font_index = i;
777 font_selected = true;
778 }
779 if (is_selected) {
780 ImGui::SetItemDefaultFocus();
781 }
782 }
783 ImGui::EndCombo();
784 }
785
786 ImGui::Separator();
787 if (ImGui::SliderInt("Font Size", &font_size, 8, 32)) {
788 current_font->Scale = font_size / 16.0f;
789 }
790}
791
792} // namespace gui
793} // namespace yaze
Represents a bitmap image.
Definition bitmap.h:66
int height() const
Definition bitmap.h:159
int width() const
Definition bitmap.h:158
auto texture() const
Definition bitmap.h:168
#define RETURN_IF_ERROR(expression)
Definition macro.h:62
std::string LoadFile(const std::string &filename)
Color ParseColor(const std::string &color)
Definition style.cc:13
absl::Status ParseThemeContents(const std::string &key, const std::string &value, Theme &theme)
Definition style.cc:25
Graphical User Interface (GUI) components for the application.
Definition canvas.cc:15
void DrawBitmapViewer(const std::vector< gfx::Bitmap > &bitmaps, float scale, int &current_bitmap_id)
Definition style.cc:217
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:21
void DrawFontManager()
Definition style.cc:753
absl::StatusOr< Theme > LoadTheme(const std::string &filename)
Definition style.cc:49
void BeginPadding(int i)
Definition style.cc:359
void BeginChildBothScrollbars(int id)
Definition style.cc:376
void EndNoPadding()
Definition style.cc:369
TextEditor::LanguageDefinition GetAssemblyLanguageDef()
Definition style.cc:278
void DrawDisplaySettings(ImGuiStyle *ref)
Definition style.cc:383
void EndPadding()
Definition style.cc:363
absl::Status SaveTheme(const Theme &theme)
Definition style.cc:76
void BeginNoPadding()
Definition style.cc:365
void EndWindowWithDisplaySettings()
Definition style.cc:354
std::string ColorToHexString(const Color &color)
Definition color.h:25
void ColorsYaze()
Definition style.cc:118
void BeginWindowWithDisplaySettings(const char *id, bool *active, const ImVec2 &size, ImGuiWindowFlags flags)
Definition style.cc:334
void TextWithSeparators(const absl::string_view &text)
Definition style.cc:747
void BeginChildWithScrollbar(const char *str_id)
Definition style.cc:371
void ApplyTheme(const Theme &theme)
Definition style.cc:99
Main namespace for the application.
Definition controller.cc:18
TokenRegexStrings mTokenRegexStrings
float green
Definition color.h:17
Color button_active
Definition style.h:35
Color tab_hovered
Definition style.h:30
Color title_bar_bg
Definition style.h:20
Color header
Definition style.h:22
Color menu_bar_bg
Definition style.h:19
std::string name
Definition style.h:17
Color title_bg_collapsed
Definition style.h:27
Color header_active
Definition style.h:24
Color header_hovered
Definition style.h:23
Color title_bg_active
Definition style.h:26
Color tab_active
Definition style.h:31
Color button
Definition style.h:33
Color button_hovered
Definition style.h:34