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