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