diff options
| -rw-r--r-- | src/core/window.cpp | 8 | ||||
| -rw-r--r-- | src/debugger/debugger.cpp | 15 | ||||
| -rw-r--r-- | src/debugger/types.h | 14 | ||||
| -rw-r--r-- | src/ui/animated_image.cpp | 3 | ||||
| -rw-r--r-- | src/ui/macro_expander.cpp | 14 | ||||
| -rw-r--r-- | src/ui/preferences.cpp | 7 | ||||
| -rw-r--r-- | src/ui/preferences.h | 6 | ||||
| -rw-r--r-- | src/ui/source_view.cpp | 25 | ||||
| -rw-r--r-- | src/ui/source_view.h | 4 | ||||
| -rw-r--r-- | src/ui/ui.cpp | 765 | ||||
| -rw-r--r-- | src/ui/ui.h | 18 |
11 files changed, 565 insertions, 314 deletions
diff --git a/src/core/window.cpp b/src/core/window.cpp index a87798a..73a57ad 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -63,12 +63,16 @@ namespace Hsdbg m_framebuffer_width = static_cast<uint32_t>(framebuffer_width); m_framebuffer_height = static_cast<uint32_t>(framebuffer_height); - Log::info("window '{}' created at {}x{} ({}x{} framebuffer)", + float content_scale = 1.0f; + glfwGetWindowContentScale(m_handle, &content_scale, nullptr); + + Log::info("window '{}' created at {}x{} ({}x{} framebuffer, {}x content scale)", m_title, m_width, m_height, m_framebuffer_width, - m_framebuffer_height); + m_framebuffer_height, + content_scale); } Window::~Window() diff --git a/src/debugger/debugger.cpp b/src/debugger/debugger.cpp index 7a51a5c..7091c57 100644 --- a/src/debugger/debugger.cpp +++ b/src/debugger/debugger.cpp @@ -125,8 +125,7 @@ namespace Hsdbg if (sysroot.empty()) return; - const std::filesystem::path etc = - std::filesystem::path(sysroot) / "lib" / "rustlib" / "etc"; + const std::filesystem::path etc = std::filesystem::path(sysroot) / "lib" / "rustlib" / "etc"; std::error_code error; if (!std::filesystem::exists(etc / "lldb_commands", error)) @@ -135,8 +134,7 @@ namespace Hsdbg lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); lldb::SBCommandReturnObject result; - const std::string import = - std::format("command script import \"{}\"", (etc / "lldb_lookup.py").string()); + const std::string import = std::format("command script import \"{}\"", (etc / "lldb_lookup.py").string()); interpreter.HandleCommand(import.c_str(), result); if (!result.Succeeded()) @@ -146,8 +144,7 @@ namespace Hsdbg return; } - const std::string source = - std::format("command source \"{}\"", (etc / "lldb_commands").string()); + const std::string source = std::format("command source \"{}\"", (etc / "lldb_commands").string()); interpreter.HandleCommand(source.c_str(), result); if (result.Succeeded()) @@ -1391,8 +1388,7 @@ namespace Hsdbg for (size_t pair = 0; pair < pairs; ++pair) { - const auto backend_id = - static_cast<int32_t>(thread.GetStopReasonDataAtIndex(pair * 2)); + const auto backend_id = static_cast<int32_t>(thread.GetStopReasonDataAtIndex(pair * 2)); const auto trace = std::ranges::find(m_traces, backend_id, &FunctionTrace::entry_backend_id); @@ -1641,8 +1637,7 @@ namespace Hsdbg const InstrOpenCall open = stack.back(); stack.pop_back(); - const double duration = - static_cast<double>(record.timestamp_ns - open.start_ns) / 1.0e9; + const double duration = static_cast<double>(record.timestamp_ns - open.start_ns) / 1.0e9; if (open.span_index < m_timeline.size()) m_timeline[open.span_index].duration = duration; diff --git a/src/debugger/types.h b/src/debugger/types.h index 98f216b..6f16562 100644 --- a/src/debugger/types.h +++ b/src/debugger/types.h @@ -39,13 +39,13 @@ namespace Hsdbg { switch (state) { - case TargetState::NoTarget: return "no target"; - case TargetState::Loaded: return "loaded"; - case TargetState::Launching: return "launching"; - case TargetState::Running: return "running"; - case TargetState::Stopped: return "stopped"; - case TargetState::Exited: return "exited"; - case TargetState::Crashed: return "crashed"; + case TargetState::NoTarget: return "No target"; + case TargetState::Loaded: return "Loaded"; + case TargetState::Launching: return "Launching"; + case TargetState::Running: return "Running"; + case TargetState::Stopped: return "Stopped"; + case TargetState::Exited: return "Exited"; + case TargetState::Crashed: return "Crashed"; } return "unknown"; diff --git a/src/ui/animated_image.cpp b/src/ui/animated_image.cpp index 94ad8bc..50f9336 100644 --- a/src/ui/animated_image.cpp +++ b/src/ui/animated_image.cpp @@ -47,8 +47,7 @@ namespace Hsdbg if (nx < 0 || ny < 0 || nx >= width || ny >= height) continue; - const unsigned char* near = - rgba + (static_cast<std::size_t>(ny) * width + nx) * 4; + const unsigned char* near = rgba + (static_cast<std::size_t>(ny) * width + nx) * 4; if (near[3] == 0) continue; diff --git a/src/ui/macro_expander.cpp b/src/ui/macro_expander.cpp index 93c512d..e7cf755 100644 --- a/src/ui/macro_expander.cpp +++ b/src/ui/macro_expander.cpp @@ -319,22 +319,19 @@ namespace Hsdbg continue; } - const bool paste_operand = - (i + 1 < body.size() && body[i + 1].text == "##") || - (i > 0 && body[i - 1].text == "##"); + const bool paste_operand = (i + 1 < body.size() && body[i + 1].text == "##") || + (i > 0 && body[i - 1].text == "##"); if (const int index = param_index(def, tok.text); index >= 0) { - const std::vector<PpToken> value = - paste_operand ? raw_tokens(index) : expanded_tokens(index); + const std::vector<PpToken> value = paste_operand ? raw_tokens(index) : expanded_tokens(index); out.insert(out.end(), value.begin(), value.end()); continue; } if (def.variadic && tok.text == "__VA_ARGS__") { - const std::vector<PpToken> value = - paste_operand ? raw_varargs() : expanded_varargs(); + const std::vector<PpToken> value = paste_operand ? raw_varargs() : expanded_varargs(); out.insert(out.end(), value.begin(), value.end()); continue; } @@ -409,8 +406,7 @@ namespace Hsdbg auto arity_ok(const MacroDef& def, const ArgList& args) -> bool { - const size_t provided = - args.size() == 1 && args.front().empty() ? 0 : args.size(); + const size_t provided = args.size() == 1 && args.front().empty() ? 0 : args.size(); if (def.variadic) return provided >= def.params.size(); diff --git a/src/ui/preferences.cpp b/src/ui/preferences.cpp index 0b0d70d..c74f0d4 100644 --- a/src/ui/preferences.cpp +++ b/src/ui/preferences.cpp @@ -54,7 +54,9 @@ namespace Hsdbg const std::string_view key(line.data(), equals); const std::string_view value(line.data() + equals + 1, line.size() - equals - 1); - if (key == "ui_scale") + if (key == "theme") + preferences.theme = std::string(value); + else if (key == "ui_scale") preferences.ui_scale = as_float(value, preferences.ui_scale); else if (key == "accent") std::sscanf(std::string(value).c_str(), "%f %f %f", @@ -109,7 +111,8 @@ namespace Hsdbg return std::to_string(c[0]) + ' ' + std::to_string(c[1]) + ' ' + std::to_string(c[2]); }; - file << "ui_scale=" << preferences.ui_scale << '\n' + file << "theme=" << preferences.theme << '\n' + << "ui_scale=" << preferences.ui_scale << '\n' << "accent=" << color(preferences.accent) << '\n' << "rounding=" << preferences.rounding << '\n' << "show_mascot=" << (preferences.show_mascot ? "true" : "false") << '\n' diff --git a/src/ui/preferences.h b/src/ui/preferences.h index 2d14a4b..c3a0a4b 100644 --- a/src/ui/preferences.h +++ b/src/ui/preferences.h @@ -1,14 +1,16 @@ #pragma once #include <filesystem> +#include <string> namespace Hsdbg { struct Preferences { + std::string theme = "midnight"; float ui_scale = 1.0f; - float accent[3] = { 0.30f, 0.72f, 0.78f }; - float rounding = 4.0f; + float accent[3] = { 0.302f, 0.714f, 0.769f }; + float rounding = 6.0f; bool show_mascot = true; float mascot_scale = 1.6f; diff --git a/src/ui/source_view.cpp b/src/ui/source_view.cpp index a98594c..f9a3f85 100644 --- a/src/ui/source_view.cpp +++ b/src/ui/source_view.cpp @@ -259,8 +259,7 @@ namespace Hsdbg while (at < size && is_word(line[at])) ++at; - const std::string_view word = - std::string_view(line).substr(start, at - start); + const std::string_view word = std::string_view(line).substr(start, at - start); SyntaxKind kind = classify_word(word, language); if (kind == SyntaxKind::Default && language == Language::Cpp && @@ -479,25 +478,31 @@ namespace Hsdbg if (m_lines.empty()) { - ImGui::TextDisabled("no source file open"); + ImGui::TextDisabled("No source file open"); return; } + if (m_mono_font != nullptr) + ImGui::PushFont(m_mono_font, 0.0f); + draw_lines(debugger); + + if (m_mono_font != nullptr) + ImGui::PopFont(); } auto SourceView::draw_open_bar() -> void { - ImGui::SetNextItemWidth(-ImGui::CalcTextSize("open").x - ImGui::GetStyle().FramePadding.x * 4.0f); + ImGui::SetNextItemWidth(-ImGui::CalcTextSize("Open").x - ImGui::GetStyle().FramePadding.x * 4.0f); const bool submitted = ImGui::InputTextWithHint("##source_path", - "path to a source file", + "Path to a source file", &m_path_input, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::SameLine(); - if (ImGui::Button("open") || submitted) + if (ImGui::Button("Open") || submitted) { if (const auto result = open(m_path_input); !result) { @@ -530,9 +535,9 @@ namespace Hsdbg m_scroll_to_highlight = false; } - const std::span<const Variable> locals = - (debugger.is_stopped() && m_highlighted_line != 0) ? debugger.locals() - : std::span<const Variable>{}; + const std::span<const Variable> locals = debugger.is_stopped() && m_highlighted_line != 0 + ? debugger.locals() + : std::span<const Variable>{}; ImGuiListClipper clipper; clipper.Begin(static_cast<int>(m_lines.size()), text_height); @@ -743,7 +748,7 @@ namespace Hsdbg const size_t steps = expansion.levels.size() - 1; if (steps == 0) - ImGui::TextDisabled("no expansion"); + ImGui::TextDisabled("No expansion"); else if (!expansion.fully_expanded()) ImGui::TextDisabled("%zu+ levels — click to step through", steps); else diff --git a/src/ui/source_view.h b/src/ui/source_view.h index 8b4c0a3..5673d69 100644 --- a/src/ui/source_view.h +++ b/src/ui/source_view.h @@ -10,6 +10,7 @@ #include <vector> struct ImDrawList; +struct ImFont; namespace Hsdbg { @@ -50,6 +51,8 @@ namespace Hsdbg auto set_syntax_color(size_t kind, unsigned int color) -> void { m_syntax_colors[kind] = color; } auto set_current_line_color(unsigned int color) -> void { m_current_line_color = color; } + auto set_mono_font(ImFont* font) -> void { m_mono_font = font; } + auto path() const -> const std::filesystem::path& { return m_path; } auto line_count() const -> size_t { return m_lines.size(); } auto is_open() const -> bool { return !m_lines.empty(); } @@ -67,6 +70,7 @@ namespace Hsdbg auto draw_macro_span(ImDrawList* draw_list, const std::string& line, const SourceSpan& span) -> void; + ImFont* m_mono_font = nullptr; std::filesystem::path m_path; std::vector<std::string> m_lines; std::vector<std::vector<SourceSpan>> m_spans; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index c956105..8bc27ac 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -3,6 +3,8 @@ #include "core/log.h" #include "core/window.h" #include "debugger/debugger.h" +#include "ui/icons.h" +#include "ui/widgets.h" #include <imgui.h> #include <imgui_internal.h> @@ -28,19 +30,19 @@ namespace Hsdbg { namespace { - constexpr const char* PANEL_SOURCE = "source"; - constexpr const char* PANEL_BREAKPOINTS = "breakpoints"; - constexpr const char* PANEL_CALL_STACK = "call stack"; - constexpr const char* PANEL_THREADS = "threads"; - constexpr const char* PANEL_SOURCE_TREE = "source tree"; - constexpr const char* PANEL_LOCALS = "locals"; - constexpr const char* PANEL_WATCH = "watch"; - constexpr const char* PANEL_REGISTERS = "registers"; - constexpr const char* PANEL_SYMBOLS = "symbols"; - constexpr const char* PANEL_DISASSEMBLY = "disassembly"; - constexpr const char* PANEL_CONSOLE = "console"; - constexpr const char* PANEL_PROFILER = "profiler"; - constexpr const char* PANEL_MACROS = "macros"; + constexpr const char* PANEL_SOURCE = ICON_PH_FILE_CODE " Source###source"; + constexpr const char* PANEL_BREAKPOINTS = ICON_PH_CIRCLE " Breakpoints###breakpoints"; + constexpr const char* PANEL_CALL_STACK = ICON_PH_STACK " Call Stack###call stack"; + constexpr const char* PANEL_THREADS = ICON_PH_BRANCH " Threads###threads"; + constexpr const char* PANEL_SOURCE_TREE = ICON_PH_FOLDER " Source Tree###source tree"; + constexpr const char* PANEL_LOCALS = ICON_PH_CUBE " Locals###locals"; + constexpr const char* PANEL_WATCH = ICON_PH_EYE " Watch###watch"; + constexpr const char* PANEL_REGISTERS = ICON_PH_CPU " Registers###registers"; + constexpr const char* PANEL_SYMBOLS = ICON_PH_FUNCTION " Symbols###symbols"; + constexpr const char* PANEL_DISASSEMBLY = ICON_PH_LIST " Disassembly###disassembly"; + constexpr const char* PANEL_CONSOLE = ICON_PH_TERMINAL " Console###console"; + constexpr const char* PANEL_PROFILER = ICON_PH_GAUGE " Profiler###profiler"; + constexpr const char* PANEL_MACROS = ICON_PH_BRACKETS " Macros###macros"; constexpr const char* LOAD_TARGET_POPUP = "load target"; @@ -308,8 +310,7 @@ namespace Hsdbg break; std::error_code error; - const std::filesystem::path relative = - std::filesystem::relative(file.parent_path(), prefix, error); + const std::filesystem::path relative = std::filesystem::relative(file.parent_path(), prefix, error); const std::string text = relative.generic_string(); if (!error && (text.empty() || text == "." || !text.starts_with(".."))) @@ -438,10 +439,10 @@ namespace Hsdbg ImGui::TableSetupColumn("##gutter", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize, DISASSEMBLY_GUTTER_WIDTH); - ImGui::TableSetupColumn("address", ImGuiTableColumnFlags_WidthFixed, 120.0f); - ImGui::TableSetupColumn("mnemonic", ImGuiTableColumnFlags_WidthFixed, 70.0f); - ImGui::TableSetupColumn("operands"); - ImGui::TableSetupColumn("comment"); + ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed, 120.0f); + ImGui::TableSetupColumn("Mnemonic", ImGuiTableColumnFlags_WidthFixed, 70.0f); + ImGui::TableSetupColumn("Operands"); + ImGui::TableSetupColumn("Comment"); ImGui::TableHeadersRow(); const float row_height = ImGui::GetTextLineHeightWithSpacing(); @@ -590,14 +591,18 @@ namespace Hsdbg io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigWindowsMoveFromTitleBarOnly = true; - io.Fonts->AddFontDefaultVector(); + load_fonts(); + m_source_view.set_mono_font(m_font_mono); m_layout_built = io.IniFilename != nullptr && std::filesystem::exists(io.IniFilename); m_preferences_path = io.IniFilename != nullptr ? std::filesystem::path(io.IniFilename).parent_path() / "hsdbg.ini" : std::filesystem::path("hsdbg.ini"); + + const bool had_preferences = std::filesystem::exists(m_preferences_path); m_preferences = load_preferences(m_preferences_path); + load_selected_theme(!had_preferences); apply_style(); @@ -742,17 +747,22 @@ namespace Hsdbg ImGui::SetNextWindowSize(viewport->WorkSize); ImGui::SetNextWindowViewport(viewport->ID); - constexpr ImGuiWindowFlags root_flags = - ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; + constexpr ImGuiWindowFlags root_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoBringToFrontOnFocus | + ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoScrollbar | + ImGuiWindowFlags_NoScrollWithMouse; ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ROOT_PADDING); + ImGui::PushStyleColor(ImGuiCol_WindowBg, m_theme.bg_low); + ImGui::Begin("##hsdbg_root", nullptr, root_flags); + ImGui::PopStyleColor(); ImGui::PopStyleVar(3); draw_menu_bar(debugger); @@ -767,7 +777,8 @@ namespace Hsdbg ImGui::DockSpace(dockspace_id, ImVec2(0.0f, ImGui::GetContentRegionAvail().y - status_bar_height), - ImGuiDockNodeFlags_PassthruCentralNode); + ImGuiDockNodeFlags_PassthruCentralNode | + static_cast<int>(ImGuiDockNodeFlags_NoWindowMenuButton)); if (!m_layout_built) { @@ -815,9 +826,6 @@ namespace Hsdbg draw_profiler_panel(debugger); draw_macros_panel(debugger); - if (m_visible.demo) - ImGui::ShowDemoWindow(&m_visible.demo); - draw_preferences_window(); draw_command_palette(debugger); @@ -908,68 +916,73 @@ namespace Hsdbg if (!ImGui::BeginMenuBar()) return; - if (ImGui::BeginMenu("file")) + ImGui::AlignTextToFramePadding(); + ImGui::PushFont(m_font_strong, 0.0f); + ImGui::TextUnformatted("hsdbg"); + ImGui::PopFont(); + ImGui::SameLine(0.0f, 18.0f); + + if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("load target...")) + if (ImGui::MenuItem("Load Target…")) { m_target_input = debugger.target_path().string(); m_load_target_pending = true; } - if (ImGui::MenuItem("unload target", nullptr, false, debugger.has_target())) + if (ImGui::MenuItem("Unload Target", nullptr, false, debugger.has_target())) debugger.unload_target(); ImGui::Separator(); - if (ImGui::MenuItem("command palette...", "cmd+k")) + if (ImGui::MenuItem("Command Palette…", "Cmd+K")) m_palette_request = true; - ImGui::MenuItem("preferences...", nullptr, &m_show_preferences); + ImGui::MenuItem("Preferences…", nullptr, &m_show_preferences); ImGui::Separator(); - if (ImGui::MenuItem("quit", "cmd+q")) + if (ImGui::MenuItem("Quit", "Cmd+Q")) m_window->set_should_close(true); ImGui::EndMenu(); } - if (ImGui::BeginMenu("run")) + if (ImGui::BeginMenu("Run")) { const bool has_target = debugger.has_target(); - if (ImGui::MenuItem("continue", "f5", false, has_target)) + if (ImGui::MenuItem("Continue", "F5", false, has_target)) report(debugger.resume(), "continue"); - if (ImGui::MenuItem("pause", nullptr, false, debugger.is_running())) + if (ImGui::MenuItem("Pause", nullptr, false, debugger.is_running())) report(debugger.pause(), "pause"); - if (ImGui::MenuItem("stop", nullptr, false, has_target)) + if (ImGui::MenuItem("Stop", nullptr, false, has_target)) report(debugger.terminate(), "stop"); ImGui::Separator(); - const StepMode step_mode = - m_preferences.step_by_instruction ? StepMode::Instruction : StepMode::Line; + const StepMode step_mode = m_preferences.step_by_instruction ? StepMode::Instruction : StepMode::Line; - if (ImGui::MenuItem("step over", "f10", false, has_target)) - report(debugger.step_over(step_mode), "step over"); + if (ImGui::MenuItem("Step Over", "F10", false, has_target)) + report(debugger.step_over(step_mode), "Step Over"); - if (ImGui::MenuItem("step into", "f11", false, has_target)) - report(debugger.step_into(step_mode), "step into"); + if (ImGui::MenuItem("Step Into", "F11", false, has_target)) + report(debugger.step_into(step_mode), "Step Into"); - if (ImGui::MenuItem("step out", "shift+f11", false, has_target)) - report(debugger.step_out(), "step out"); + if (ImGui::MenuItem("Step Out", "Shift+F11", false, has_target)) + report(debugger.step_out(), "Step Out"); ImGui::Separator(); - if (ImGui::MenuItem("clear breakpoints", nullptr, false, !debugger.breakpoints().empty())) + if (ImGui::MenuItem("Clear Breakpoints", nullptr, false, !debugger.breakpoints().empty())) debugger.clear_breakpoints(); ImGui::EndMenu(); } - if (ImGui::BeginMenu("view")) + if (ImGui::BeginMenu("View")) { ImGui::MenuItem(PANEL_SOURCE, nullptr, &m_visible.source); ImGui::MenuItem(PANEL_SOURCE_TREE, nullptr, &m_visible.source_tree); @@ -987,14 +1000,24 @@ namespace Hsdbg ImGui::Separator(); - if (ImGui::MenuItem("reset layout")) + if (ImGui::MenuItem("Reset Layout")) m_layout_built = false; - ImGui::MenuItem("imgui demo", nullptr, &m_visible.demo); - ImGui::EndMenu(); } + const char* palette_hint = ICON_PH_SEARCH " Run a command Cmd+K"; + const float hint_w = ImGui::CalcTextSize(palette_hint).x; + ImGui::SameLine(ImGui::GetWindowWidth() - hint_w - 14.0f); + ImGui::AlignTextToFramePadding(); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled)); + ImGui::TextUnformatted(palette_hint); + ImGui::PopStyleColor(); + if (ImGui::IsItemClicked()) + m_palette_request = true; + if (ImGui::IsItemHovered()) + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); + ImGui::EndMenuBar(); } @@ -1009,24 +1032,26 @@ namespace Hsdbg m_mascot.load(std::filesystem::path(HSDBG_ASSET_DIR) / "peepocry.gif"); } - const float button_height = ImGui::GetFrameHeight(); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 9.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, TOOLBAR_PADDING); + + const float control = ImGui::GetFrameHeight(); const bool has_mascot = m_preferences.show_mascot && m_mascot.valid() && m_mascot.height() > 0.0f; - const float mascot_height = has_mascot ? button_height * m_preferences.mascot_scale : 0.0f; - const float row_height = std::max(button_height, mascot_height); + const float mascot_height = has_mascot ? control * m_preferences.mascot_scale : 0.0f; + const float row_height = std::max(control, mascot_height); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 6.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, TOOLBAR_PADDING); ImGui::BeginChild("##toolbar", ImVec2(0.0f, row_height + TOOLBAR_PADDING.y * 2.0f)); const float row_top = ImGui::GetCursorPosY(); - ImGui::SetCursorPosY(row_top + (row_height - button_height) * 0.5f); + ImGui::SetCursorPosY(row_top + (row_height - control) * 0.5f); - const StepMode step_mode = - m_preferences.step_by_instruction ? StepMode::Instruction : StepMode::Line; + const StepMode step_mode = m_preferences.step_by_instruction ? StepMode::Instruction : StepMode::Line; - ImGui::BeginDisabled(!has_target || running); - if (ImGui::Button("run")) + const auto gap = [] { ImGui::SameLine(0.0f, 14.0f); }; + + if (Widgets::icon_button("run", ICON_PH_PLAY, has_target && !running, "Run", + !has_target || running, control)) { LaunchSpec spec; spec.executable = debugger.target_path(); @@ -1034,49 +1059,33 @@ namespace Hsdbg report(debugger.launch(spec), "run"); } - ImGui::EndDisabled(); ImGui::SameLine(); - - ImGui::BeginDisabled(!running); - if (ImGui::Button("pause")) + if (Widgets::icon_button("pause", ICON_PH_PAUSE, false, "Pause", !running, control)) report(debugger.pause(), "pause"); - ImGui::EndDisabled(); ImGui::SameLine(); - - ImGui::BeginDisabled(!has_target); - if (ImGui::Button("stop")) + if (Widgets::icon_button("stop", ICON_PH_STOP, false, "Stop", !has_target, control)) report(debugger.terminate(), "stop"); - ImGui::SameLine(); - ImGui::TextDisabled("|"); - ImGui::SameLine(); - - if (ImGui::Button("step over")) - report(debugger.step_over(step_mode), "step over"); + gap(); + if (Widgets::icon_button("step_over", ICON_PH_STEP_OVER, false, "Step Over", + !has_target, control)) + report(debugger.step_over(step_mode), "Step Over"); ImGui::SameLine(); - - if (ImGui::Button("step into")) - report(debugger.step_into(step_mode), "step into"); + if (Widgets::icon_button("step_into", ICON_PH_STEP_INTO, false, "Step Into", + !has_target, control)) + report(debugger.step_into(step_mode), "Step Into"); ImGui::SameLine(); + if (Widgets::icon_button("step_out", ICON_PH_STEP_OUT, false, "Step Out", + !has_target, control)) + report(debugger.step_out(), "Step Out"); - if (ImGui::Button("step out")) - report(debugger.step_out(), "step out"); - ImGui::EndDisabled(); - - ImGui::SameLine(); - ImGui::TextDisabled("|"); - ImGui::SameLine(); - - const bool profiler_open = m_visible.profiler; - - if (profiler_open) - ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive)); - - if (ImGui::Button("profiler")) + gap(); + if (Widgets::icon_button("profiler", ICON_PH_GAUGE, m_visible.profiler, "Profiler", + false, control)) { m_visible.profiler = !m_visible.profiler; @@ -1084,15 +1093,9 @@ namespace Hsdbg m_focus_profiler = true; } - if (profiler_open) - ImGui::PopStyleColor(); - - ImGui::SameLine(); - ImGui::TextDisabled("|"); - ImGui::SameLine(); - - ImGui::AlignTextToFramePadding(); - ImGui::TextColored(state_color(debugger.state()), "%s", to_string(debugger.state()).data()); + gap(); + Widgets::chip(std::string(to_string(debugger.state())).c_str(), + ImGui::ColorConvertFloat4ToU32(state_color(debugger.state()))); if (has_mascot) { @@ -1105,7 +1108,7 @@ namespace Hsdbg ImGui::Dummy(size); if (ImGui::IsItemHovered()) - ImGui::SetTooltip("it's going to be okay"); + ImGui::SetTooltip("It's going to be okay"); const ImVec2 viewport = ImGui::GetMainViewport()->Pos; m_mascot_pending = true; @@ -1134,7 +1137,7 @@ namespace Hsdbg if (debugger.has_target()) ImGui::Text("%s", debugger.target_path().filename().string().c_str()); else - ImGui::TextDisabled("no target"); + ImGui::TextDisabled("No target"); ImGui::SameLine(); ImGui::TextDisabled("|"); @@ -1170,7 +1173,7 @@ namespace Hsdbg if (!ImGui::BeginPopupModal(LOAD_TARGET_POPUP, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) return; - ImGui::TextDisabled("path to an executable to debug"); + ImGui::TextDisabled("Path to an executable to debug"); ImGui::SetNextItemWidth(420.0f); @@ -1178,7 +1181,7 @@ namespace Hsdbg &m_target_input, ImGuiInputTextFlags_EnterReturnsTrue); - if (ImGui::Button("load") || submitted) + if (ImGui::Button("Load") || submitted) { if (const auto result = debugger.load_target(m_target_input); result) { @@ -1193,7 +1196,7 @@ namespace Hsdbg ImGui::SameLine(); - if (ImGui::Button("cancel")) + if (ImGui::Button("Cancel")) ImGui::CloseCurrentPopup(); ImGui::EndPopup(); @@ -1203,6 +1206,14 @@ namespace Hsdbg { ImGui::GetStyle().FontScaleMain = m_preferences.ui_scale; + static bool logged_scale = false; + if (!logged_scale) + { + logged_scale = true; + const ImVec2 fb = ImGui::GetIO().DisplayFramebufferScale; + Log::info("display: framebuffer scale {}x{}", fb.x, fb.y); + } + m_source_view.set_highlighting(m_preferences.syntax_highlighting); m_source_view.set_line_numbers(m_preferences.show_line_numbers); m_source_view.set_highlight_current_line(m_preferences.highlight_current_line); @@ -1229,7 +1240,14 @@ namespace Hsdbg auto Ui::draw_preferences_window() -> void { if (!m_show_preferences) + { + m_prefs_open_prev = false; return; + } + + if (!m_prefs_open_prev) + m_themes = list_themes(themes_directory()); + m_prefs_open_prev = true; const ImGuiViewport* viewport = ImGui::GetMainViewport(); const ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f, @@ -1239,22 +1257,26 @@ namespace Hsdbg ImGui::SetNextWindowSize(ImVec2(560.0f, 380.0f), ImGuiCond_Appearing); ImGui::SetNextWindowSizeConstraints(ImVec2(460.0f, 300.0f), ImVec2(FLT_MAX, FLT_MAX)); - if (!ImGui::Begin("preferences", &m_show_preferences, ImGuiWindowFlags_NoDocking)) + if (!ImGui::Begin("Preferences###preferences", &m_show_preferences, ImGuiWindowFlags_NoDocking)) { ImGui::End(); return; } - static constexpr const char* CATEGORIES[] = { "appearance", "editor", "debugger" }; + static constexpr const char* CATEGORIES[] = { "Appearance", "Editor", "Debugger" }; + static constexpr const char* CATEGORY_ICONS[] = { + ICON_PH_SLIDERS, ICON_PH_FILE_CODE, ICON_PH_BUG + }; bool changed = false; bool restyle = false; const float footer = ImGui::GetFrameHeightWithSpacing() + ImGui::GetStyle().ItemSpacing.y; - ImGui::BeginChild("##pref_categories", ImVec2(150.0f, -footer), ImGuiChildFlags_Borders); + ImGui::BeginChild("##pref_categories", ImVec2(158.0f, -footer), ImGuiChildFlags_Borders); for (int index = 0; index < IM_ARRAYSIZE(CATEGORIES); ++index) { - if (ImGui::Selectable(CATEGORIES[index], m_preferences_tab == index)) + const std::string label = std::string(CATEGORY_ICONS[index]) + " " + CATEGORIES[index]; + if (Widgets::selectable_row(label.c_str(), m_preferences_tab == index)) m_preferences_tab = index; } ImGui::EndChild(); @@ -1282,68 +1304,134 @@ namespace Hsdbg changed = true; }; + const auto toggle_row = [&](const char* label, bool* value, const char* help_text = nullptr) { + const float toggle_h = ImGui::GetFrameHeight() * 0.78f; + const float toggle_w = toggle_h * 1.8f; + ImGui::AlignTextToFramePadding(); + ImGui::TextUnformatted(label); + if (help_text != nullptr) + help(help_text); + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - toggle_w); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (ImGui::GetFrameHeight() - toggle_h) * 0.5f); + if (Widgets::toggle(label, value)) + changed = true; + }; + if (m_preferences_tab == 0) { - ImGui::SeparatorText("interface"); - changed |= ImGui::SliderFloat("ui scale", &m_preferences.ui_scale, 0.75f, 2.0f, "%.2fx"); - help("scales every font. the text stays crisp because it is re-rasterized, not stretched."); + Widgets::section_header("theme"); - if (ImGui::ColorEdit3("accent colour", m_preferences.accent, + const auto swatch = [](ImVec4 colour) { + ImGui::ColorButton("##sw", colour, + ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop, + ImVec2(14.0f, 14.0f)); + ImGui::SameLine(0.0f, 4.0f); + }; + swatch(m_theme.bg); + swatch(m_theme.bg_high); + swatch(m_theme.surface); + swatch(m_theme.text); + swatch(ImVec4(m_preferences.accent[0], m_preferences.accent[1], + m_preferences.accent[2], 1.0f)); + ImGui::NewLine(); + + const char* current = m_preferences.theme.c_str(); + for (const auto& entry : m_themes) + { + if (entry.id == m_preferences.theme) + { + current = entry.name.c_str(); + break; + } + } + + if (ImGui::BeginCombo("Theme", current)) + { + for (const auto& entry : m_themes) + { + const bool selected = entry.id == m_preferences.theme; + if (ImGui::Selectable(entry.name.c_str(), selected)) + select_theme(entry); + if (selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + help("Themes live in assets/themes as .toml files. drop a new one in, reopen this " + "window, and it appears here. picking one resets the tweaks below to its values."); + + Widgets::section_header("interface"); + changed |= Widgets::slider_float("UI scale", &m_preferences.ui_scale, 0.75f, 2.0f, "%.2fx"); + help("Scales every font. the text stays crisp because it is re-rasterized, not stretched."); + + if (ImGui::ColorEdit3("Accent colour", m_preferences.accent, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha)) { changed = true; restyle = true; } - if (ImGui::SliderFloat("corner rounding", &m_preferences.rounding, 0.0f, 12.0f, "%.0f px")) + if (Widgets::slider_float("Corner rounding", &m_preferences.rounding, 0.0f, 12.0f, "%.0f px")) { changed = true; restyle = true; } - changed |= ImGui::Checkbox("show fps in the status bar", &m_preferences.show_fps); + toggle_row("Show FPS in the status bar", &m_preferences.show_fps); - ImGui::SeparatorText("layout"); - if (ImGui::Button("reset window layout")) + Widgets::section_header("layout"); + if (ImGui::Button("Reset window layout")) m_layout_built = false; - help("restores the default arrangement of all the docked panels."); + help("Restores the default arrangement of all the docked panels."); - ImGui::SeparatorText("mascot"); - changed |= ImGui::Checkbox("show the crying pepe", &m_preferences.show_mascot); + Widgets::section_header("mascot"); + toggle_row("Show the crying pepe", &m_preferences.show_mascot); ImGui::BeginDisabled(!m_preferences.show_mascot); - changed |= ImGui::SliderFloat("pepe size", &m_preferences.mascot_scale, 1.0f, 3.0f, "%.1fx"); + changed |= Widgets::slider_float("Pepe size", &m_preferences.mascot_scale, 1.0f, 3.0f, "%.1fx"); ImGui::EndDisabled(); } else if (m_preferences_tab == 1) { - ImGui::SeparatorText("source view"); - changed |= ImGui::Checkbox("syntax highlighting", &m_preferences.syntax_highlighting); - changed |= ImGui::Checkbox("show line numbers", &m_preferences.show_line_numbers); - changed |= ImGui::Checkbox("highlight the current line", - &m_preferences.highlight_current_line); + Widgets::section_header("source view"); + toggle_row("Syntax highlighting", &m_preferences.syntax_highlighting); + toggle_row("Show line numbers", &m_preferences.show_line_numbers); + toggle_row("Highlight the current line", &m_preferences.highlight_current_line); - ImGui::SeparatorText("colours"); + Widgets::section_header("colours"); ImGui::BeginDisabled(!m_preferences.syntax_highlighting); - accent_swatch("keyword", m_preferences.color_keyword); - accent_swatch("type", m_preferences.color_type); - accent_swatch("string", m_preferences.color_string); - accent_swatch("number", m_preferences.color_number); - accent_swatch("comment", m_preferences.color_comment); - accent_swatch("preprocessor", m_preferences.color_preprocessor); + accent_swatch("Keyword", m_preferences.color_keyword); + accent_swatch("Type", m_preferences.color_type); + accent_swatch("String", m_preferences.color_string); + accent_swatch("Number", m_preferences.color_number); + accent_swatch("Comment", m_preferences.color_comment); + accent_swatch("Preprocessor", m_preferences.color_preprocessor); ImGui::EndDisabled(); - accent_swatch("current line", m_preferences.color_current_line); + accent_swatch("Current line", m_preferences.color_current_line); } else if (m_preferences_tab == 2) { - ImGui::SeparatorText("launching"); - changed |= ImGui::Checkbox("break at entry point on launch", &m_preferences.stop_at_entry); - help("stop on the very first instruction instead of running to your breakpoints."); + Widgets::section_header("launching"); + toggle_row("Break at entry point on launch", &m_preferences.stop_at_entry, + "stop on the very first instruction instead of running to your breakpoints."); - ImGui::SeparatorText("stepping"); - changed |= ImGui::Checkbox("step by instruction, not line", - &m_preferences.step_by_instruction); - help("the step over/into buttons advance one machine instruction at a time."); + Widgets::section_header("stepping"); + { + static const char* const step_modes[] = { "Line", "Instruction" }; + const int current_mode = m_preferences.step_by_instruction ? 1 : 0; + const int next_mode = Widgets::segmented("##step_mode", step_modes, 2, current_mode); + ImGui::SameLine(); + ImGui::AlignTextToFramePadding(); + ImGui::TextUnformatted("Step granularity"); + help("The step over/into buttons advance a whole source line, or a single " + "machine instruction."); + if (next_mode != current_mode) + { + m_preferences.step_by_instruction = (next_mode == 1); + changed = true; + } + } } ImGui::PopItemWidth(); @@ -1351,15 +1439,16 @@ namespace Hsdbg ImGui::Separator(); - if (ImGui::Button("reset to defaults")) + if (ImGui::Button("Reset to defaults")) { m_preferences = Preferences{}; + load_selected_theme(false); changed = true; restyle = true; } ImGui::SameLine(); - ImGui::TextDisabled("saved to %s", m_preferences_path.filename().string().c_str()); + ImGui::TextDisabled("Saved to %s", m_preferences_path.filename().string().c_str()); if (changed) save_preferences(m_preferences_path, m_preferences); @@ -1390,7 +1479,7 @@ namespace Hsdbg { if (debugger.breakpoints().empty()) { - ImGui::TextDisabled("no breakpoints, click a gutter in source or disassembly"); + Widgets::empty_state(ICON_PH_CIRCLE, "No breakpoints yet"); } else { @@ -1399,17 +1488,18 @@ namespace Hsdbg if (ImGui::BeginTable("##breakpoints", 8, flags)) { - ImGui::TableSetupColumn("on", ImGuiTableColumnFlags_WidthFixed, 26.0f); - ImGui::TableSetupColumn("id", ImGuiTableColumnFlags_WidthFixed, 30.0f); - ImGui::TableSetupColumn("location"); - ImGui::TableSetupColumn("address"); - ImGui::TableSetupColumn("condition"); - ImGui::TableSetupColumn("skip", ImGuiTableColumnFlags_WidthFixed, 50.0f); - ImGui::TableSetupColumn("hits", ImGuiTableColumnFlags_WidthFixed, 40.0f); + ImGui::TableSetupColumn("On", ImGuiTableColumnFlags_WidthFixed, 26.0f); + ImGui::TableSetupColumn("Id", ImGuiTableColumnFlags_WidthFixed, 30.0f); + ImGui::TableSetupColumn("Location"); + ImGui::TableSetupColumn("Address"); + ImGui::TableSetupColumn("Condition"); + ImGui::TableSetupColumn("Skip", ImGuiTableColumnFlags_WidthFixed, 50.0f); + ImGui::TableSetupColumn("Hits", ImGuiTableColumnFlags_WidthFixed, 40.0f); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 26.0f); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); + ImGui::PushFont(m_font_mono, 0.0f); uint32_t pending_removal = 0; for (const Breakpoint& breakpoint : debugger.breakpoints()) @@ -1466,7 +1556,7 @@ namespace Hsdbg } else { - ImGui::TextDisabled("pending"); + ImGui::TextDisabled("Pending"); } ImGui::TableNextColumn(); @@ -1474,7 +1564,7 @@ namespace Hsdbg ImGui::SetNextItemWidth(-1.0f); if (ImGui::InputTextWithHint("##condition", - "stop when", + "Stop when…", &condition, ImGuiInputTextFlags_EnterReturnsTrue)) { @@ -1496,12 +1586,13 @@ namespace Hsdbg ImGui::Text("%u", breakpoint.hit_count); ImGui::TableNextColumn(); - if (ImGui::SmallButton("x")) + if (Widgets::remove_button("##remove")) pending_removal = breakpoint.id; ImGui::PopID(); } + ImGui::PopFont(); ImGui::EndTable(); if (pending_removal != 0) @@ -1522,7 +1613,7 @@ namespace Hsdbg { if (debugger.call_stack().empty()) { - ImGui::TextDisabled("no call stack"); + Widgets::empty_state(ICON_PH_STACK, "No call stack"); } else { @@ -1531,7 +1622,7 @@ namespace Hsdbg const bool selected = frame.index == debugger.selected_frame(); const std::string label = std::format("{:>2} {}", frame.index, frame.function); - if (ImGui::Selectable(label.c_str(), selected)) + if (Widgets::selectable_row(label.c_str(), selected)) { debugger.select_frame(frame.index); show_frame(frame); @@ -1544,7 +1635,9 @@ namespace Hsdbg continue; ImGui::SameLine(); + ImGui::PushFont(m_font_mono, 0.0f); ImGui::TextDisabled("%s:%u", frame.file.filename().string().c_str(), frame.line); + ImGui::PopFont(); } } } @@ -1561,7 +1654,7 @@ namespace Hsdbg { if (debugger.threads().empty()) { - ImGui::TextDisabled("no threads"); + Widgets::empty_state(ICON_PH_BRANCH, "No threads"); } else { @@ -1570,7 +1663,7 @@ namespace Hsdbg const bool selected = thread.id == debugger.selected_thread(); const std::string label = std::format("{} {}", thread.id, thread.name); - if (ImGui::Selectable(label.c_str(), selected)) + if (Widgets::selectable_row(label.c_str(), selected)) { debugger.select_thread(thread.id); @@ -1599,12 +1692,12 @@ namespace Hsdbg if (files.empty()) { - ImGui::TextDisabled("no source files"); + Widgets::empty_state(ICON_PH_FOLDER, "No source files"); } else { ImGui::SetNextItemWidth(-1.0f); - ImGui::InputTextWithHint("##source_filter", "filter files", &m_source_filter); + ImGui::InputTextWithHint("##source_filter", "Filter files", &m_source_filter); const SourceNode tree = build_source_tree(files); const std::filesystem::path& open = m_source_view.path(); @@ -1625,7 +1718,8 @@ namespace Hsdbg if (selected) ImGui::PushStyleColor(ImGuiCol_Text, SOURCE_OPEN_FILE_COLOR); - const bool clicked = ImGui::Selectable(node.name.c_str(), selected); + const bool clicked = Widgets::selectable_row( + (std::string(ICON_PH_FILE " ") + node.name).c_str(), selected); if (selected) ImGui::PopStyleColor(); @@ -1652,7 +1746,8 @@ namespace Hsdbg ImGui::SetNextItemOpen(true, ImGuiCond_Always); ImGui::PushStyleColor(ImGuiCol_Text, SOURCE_FOLDER_COLOR); - const bool open_node = ImGui::TreeNodeEx(node.name.c_str(), flags); + const bool open_node = ImGui::TreeNodeEx( + (std::string(ICON_PH_FOLDER " ") + node.name).c_str(), flags); ImGui::PopStyleColor(); if (!open_node) @@ -1687,7 +1782,7 @@ namespace Hsdbg }; if (tree.children.empty()) - ImGui::TextDisabled("no source files"); + Widgets::empty_state(ICON_PH_FOLDER, "No source files"); else draw_node(tree); @@ -1707,7 +1802,7 @@ namespace Hsdbg { if (debugger.locals().empty()) { - ImGui::TextDisabled("no locals"); + Widgets::empty_state(ICON_PH_CUBE, "No locals"); } else { @@ -1716,14 +1811,16 @@ namespace Hsdbg if (ImGui::BeginTable("##locals", 3, flags)) { - ImGui::TableSetupColumn("name"); - ImGui::TableSetupColumn("type"); - ImGui::TableSetupColumn("value"); + ImGui::TableSetupColumn("Name"); + ImGui::TableSetupColumn("Type"); + ImGui::TableSetupColumn("Value"); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); + ImGui::PushFont(m_font_mono, 0.0f); for (const Variable& variable : debugger.locals()) draw_variable(variable); + ImGui::PopFont(); ImGui::EndTable(); } @@ -1803,12 +1900,12 @@ namespace Hsdbg m_watch_evaluated = false; ImGui::SetNextItemWidth(-60.0f); - const bool submitted = ImGui::InputTextWithHint("##watch_input", "expression to watch", + const bool submitted = ImGui::InputTextWithHint("##watch_input", "Expression to watch", &m_watch_input, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::SameLine(); - const bool add_clicked = ImGui::Button("watch", ImVec2(-1.0f, 0.0f)); + const bool add_clicked = ImGui::Button("Watch", ImVec2(-1.0f, 0.0f)); if ((submitted || add_clicked) && !m_watch_input.empty()) { @@ -1818,7 +1915,7 @@ namespace Hsdbg if (m_watches.empty()) { - ImGui::TextDisabled("watch an expression; it re-evaluates on every stop"); + ImGui::TextDisabled("Watch an expression; it re-evaluates on every stop"); } else { @@ -1827,12 +1924,13 @@ namespace Hsdbg if (ImGui::BeginTable("##watches", 3, flags)) { - ImGui::TableSetupColumn("expression", ImGuiTableColumnFlags_WidthFixed, 140.0f); - ImGui::TableSetupColumn("value"); + ImGui::TableSetupColumn("Expression", ImGuiTableColumnFlags_WidthFixed, 140.0f); + ImGui::TableSetupColumn("Value"); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 24.0f); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); + ImGui::PushFont(m_font_mono, 0.0f); size_t remove_index = m_watches.size(); for (size_t index = 0; index < m_watches.size(); ++index) @@ -1855,12 +1953,13 @@ namespace Hsdbg watch.value.c_str()); ImGui::TableNextColumn(); - if (ImGui::SmallButton("x")) + if (Widgets::remove_button("##remove")) remove_index = index; ImGui::PopID(); } + ImGui::PopFont(); ImGui::EndTable(); if (remove_index < m_watches.size()) @@ -1881,7 +1980,7 @@ namespace Hsdbg { if (debugger.registers().empty()) { - ImGui::TextDisabled("no registers"); + Widgets::empty_state(ICON_PH_CPU, "No registers"); } else { @@ -1890,11 +1989,12 @@ namespace Hsdbg if (ImGui::BeginTable("##registers", 2, flags)) { - ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthFixed, 70.0f); - ImGui::TableSetupColumn("value"); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 70.0f); + ImGui::TableSetupColumn("Value"); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); + ImGui::PushFont(m_font_mono, 0.0f); for (const Register& entry : debugger.registers()) { ImGui::TableNextRow(); @@ -1903,6 +2003,7 @@ namespace Hsdbg ImGui::TableNextColumn(); ImGui::Text("0x%016llx", static_cast<unsigned long long>(entry.value)); } + ImGui::PopFont(); ImGui::EndTable(); } @@ -1923,12 +2024,12 @@ namespace Hsdbg if (symbols.empty()) { - ImGui::TextDisabled("no symbols"); + Widgets::empty_state(ICON_PH_FUNCTION, "No symbols"); } else { ImGui::SetNextItemWidth(-1.0f); - ImGui::InputTextWithHint("##symbol_filter", "filter symbols", &m_symbol_filter); + ImGui::InputTextWithHint("##symbol_filter", "Filter symbols", &m_symbol_filter); std::vector<size_t> visible; @@ -1946,11 +2047,12 @@ namespace Hsdbg if (ImGui::BeginTable("##symbols", 2, flags)) { - ImGui::TableSetupColumn("address", ImGuiTableColumnFlags_WidthFixed, 110.0f); - ImGui::TableSetupColumn("name"); + ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed, 110.0f); + ImGui::TableSetupColumn("Name"); ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableHeadersRow(); + ImGui::PushFont(m_font_mono, 0.0f); const float row_height = ImGui::GetTextLineHeightWithSpacing(); if (m_scroll_to_symbol) @@ -2002,6 +2104,7 @@ namespace Hsdbg ImGui::PopID(); } } + ImGui::PopFont(); ImGui::EndTable(); } @@ -2022,14 +2125,16 @@ namespace Hsdbg if (instructions.empty()) { - ImGui::TextDisabled("no disassembly"); + Widgets::empty_state(ICON_PH_LIST, "No disassembly"); } else { if (!debugger.disassembly_name().empty()) ImGui::TextUnformatted(debugger.disassembly_name().data()); + ImGui::PushFont(m_font_mono, 0.0f); draw_instruction_table(debugger, instructions, m_scroll_to_program_counter); + ImGui::PopFont(); m_scroll_to_program_counter = false; } } @@ -2048,6 +2153,7 @@ namespace Hsdbg if (ImGui::BeginChild("##console_output", ImVec2(0.0f, -input_height))) { + ImGui::PushFont(m_font_mono, 0.0f); for (const std::string& line : debugger.console_output()) draw_ansi_line(line); @@ -2059,6 +2165,7 @@ namespace Hsdbg ImGui::SetScrollHereY(1.0f); m_console_scroll_pending = false; } + ImGui::PopFont(); } ImGui::EndChild(); @@ -2066,7 +2173,7 @@ namespace Hsdbg ImGui::SetNextItemWidth(-1.0f); const bool submitted = ImGui::InputTextWithHint("##console_input", - "expression to evaluate", + "Expression to evaluate", &m_console_input, ImGuiInputTextFlags_EnterReturnsTrue); @@ -2099,7 +2206,7 @@ namespace Hsdbg if (instrumented) { - ImGui::TextDisabled("instrumented target — every function timed automatically"); + ImGui::TextDisabled("Instrumented target — every function timed automatically"); } else { @@ -2121,12 +2228,12 @@ namespace Hsdbg if (ImGui::CollapsingHeader("function timings", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::SetNextItemWidth(-70.0f); - const bool submitted = ImGui::InputTextWithHint("##trace_input", "function to time", + const bool submitted = ImGui::InputTextWithHint("##trace_input", "Function to time", &m_trace_input, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::SameLine(); - const bool add_clicked = ImGui::Button("trace", ImVec2(-1.0f, 0.0f)); + const bool add_clicked = ImGui::Button("Trace", ImVec2(-1.0f, 0.0f)); if ((submitted || add_clicked) && !m_trace_input.empty()) { @@ -2136,17 +2243,17 @@ namespace Hsdbg if (traces.empty()) { - ImGui::TextDisabled("name a function above to count and time its calls"); + ImGui::TextDisabled("Name a function above to count and time its calls"); } else if (ImGui::BeginTable("##traces", 6, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Resizable)) { - ImGui::TableSetupColumn("function"); - ImGui::TableSetupColumn("calls", ImGuiTableColumnFlags_WidthFixed, 52.0f); - ImGui::TableSetupColumn("avg", ImGuiTableColumnFlags_WidthFixed, 72.0f); - ImGui::TableSetupColumn("min", ImGuiTableColumnFlags_WidthFixed, 72.0f); - ImGui::TableSetupColumn("max", ImGuiTableColumnFlags_WidthFixed, 72.0f); + ImGui::TableSetupColumn("Function"); + ImGui::TableSetupColumn("Calls", ImGuiTableColumnFlags_WidthFixed, 52.0f); + ImGui::TableSetupColumn("Avg", ImGuiTableColumnFlags_WidthFixed, 72.0f); + ImGui::TableSetupColumn("Min", ImGuiTableColumnFlags_WidthFixed, 72.0f); + ImGui::TableSetupColumn("Max", ImGuiTableColumnFlags_WidthFixed, 72.0f); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 24.0f); ImGui::TableHeadersRow(); @@ -2186,7 +2293,7 @@ namespace Hsdbg ImGui::TableNextColumn(); ImGui::PushID(static_cast<int>(trace.id)); - if (ImGui::SmallButton("x")) + if (Widgets::remove_button("##remove")) remove_id = trace.id; ImGui::PopID(); } @@ -2205,7 +2312,7 @@ namespace Hsdbg ImGui::Text("%.1f MB", memory.latest()); ImGui::SameLine(); - ImGui::TextDisabled("peak %.1f MB", memory.maximum()); + ImGui::TextDisabled("Peak %.1f MB", memory.maximum()); ImGui::PlotLines("##target_memory", memory.values(), memory.count(), memory.offset(), nullptr, 0.0f, FLT_MAX, ImVec2(-1.0f, 60.0f)); @@ -2218,24 +2325,23 @@ namespace Hsdbg m_profiler.set_paused(paused); ImGui::SameLine(); - if (ImGui::SmallButton("reset")) + if (ImGui::SmallButton("Reset")) m_profiler.reset(); const TimeSeries& frame_ms = m_profiler.frame_times(); const TimeSeries& fps = m_profiler.frame_rates(); - const std::string frame_overlay = - std::format("{:.2f} ms (avg {:.2f} peak {:.2f})", - frame_ms.latest(), frame_ms.average(), frame_ms.maximum()); + const std::string frame_overlay = std::format("{:.2f} ms (avg {:.2f} peak {:.2f})", + frame_ms.latest(), frame_ms.average(), + frame_ms.maximum()); - ImGui::TextUnformatted("frame time"); + ImGui::TextUnformatted("Frame time"); ImGui::PlotLines("##frame_ms", frame_ms.values(), frame_ms.count(), frame_ms.offset(), frame_overlay.c_str(), 0.0f, FLT_MAX, ImVec2(-1.0f, 70.0f)); - const std::string fps_overlay = - std::format("{:.0f} fps (avg {:.0f})", fps.latest(), fps.average()); + const std::string fps_overlay = std::format("{:.0f} fps (avg {:.0f})", fps.latest(), fps.average()); - ImGui::TextUnformatted("frame rate"); + ImGui::TextUnformatted("Frame rate"); ImGui::PlotLines("##fps", fps.values(), fps.count(), fps.offset(), fps_overlay.c_str(), 0.0f, FLT_MAX, ImVec2(-1.0f, 70.0f)); } @@ -2251,11 +2357,11 @@ namespace Hsdbg if (spans.empty()) { if (debugger.instrumentation_active()) - ImGui::TextDisabled("instrumented target — run it to lay out its calls here"); + ImGui::TextDisabled("Instrumented target — run it to lay out its calls here"); else if (debugger.sampling_enabled()) - ImGui::TextDisabled("sampling — run the target and the calls will appear here"); + ImGui::TextDisabled("Sampling — run the target and the calls will appear here"); else - ImGui::TextDisabled("turn on sampling, or trace a function below, then run"); + ImGui::TextDisabled("Turn on sampling, or trace a function below, then run"); return; } @@ -2327,11 +2433,11 @@ namespace Hsdbg { ImGui::BeginTooltip(); ImGui::TextUnformatted(name_of(span.trace_id)); - ImGui::Text("start %.3f ms", (span.start - t_min) * 1000.0); + ImGui::Text("Start %.3f ms", (span.start - t_min) * 1000.0); if (span.duration > 0.0) - ImGui::Text("duration %.3f ms", span.duration * 1000.0); + ImGui::Text("Duration %.3f ms", span.duration * 1000.0); else - ImGui::TextDisabled("running..."); + ImGui::TextDisabled("Running…"); ImGui::EndTooltip(); } } @@ -2348,17 +2454,17 @@ namespace Hsdbg { const MacroTable& table = m_source_view.macros(); - ImGui::TextDisabled("unroll a #define one layer per level"); + ImGui::TextDisabled("Unroll a #define one layer per level"); ImGui::SetNextItemWidth(-FLT_MIN); if (ImGui::InputTextWithHint("##macro_input", - "click a macro in source, or type one like MAX(a, b)", + "Click a macro in Source, or type one like MAX(a, b)", &m_macro_input)) m_macro_level = 0; if (table.empty()) - ImGui::TextDisabled("no #define macros found in the open source file"); + ImGui::TextDisabled("No #define macros found in the open source file"); if (m_macro_input.empty()) { @@ -2395,33 +2501,32 @@ namespace Hsdbg } else { - ImGui::TextDisabled("nothing to expand here"); + ImGui::TextDisabled("Nothing to expand here"); ImGui::SameLine(); } ImGui::SameLine(); - if (ImGui::SmallButton("full")) + if (ImGui::SmallButton("Full")) m_macro_level = max_level; ImGui::SameLine(); - if (ImGui::SmallButton("reset")) + if (ImGui::SmallButton("Reset")) m_macro_level = 0; if (max_level == 0) - ImGui::TextDisabled("already fully expanded"); + ImGui::TextDisabled("Already fully expanded"); else if (m_macro_level == max_level && expansion.fully_expanded()) - ImGui::TextDisabled("level %d of %d — fully expanded", m_macro_level, max_level); + ImGui::TextDisabled("Level %d of %d — fully expanded", m_macro_level, max_level); else if (m_macro_level == max_level) - ImGui::TextDisabled("level %d — stopped at the expansion cap", m_macro_level); + ImGui::TextDisabled("Level %d — stopped at the expansion cap", m_macro_level); else - ImGui::TextDisabled("level %d of %d", m_macro_level, max_level); + ImGui::TextDisabled("Level %d of %d", m_macro_level, max_level); if (m_macro_level < max_level) { - const std::vector<std::string>& next = - expansion.expanded[static_cast<size_t>(m_macro_level) + 1]; + const std::vector<std::string>& next = expansion.expanded[static_cast<size_t>(m_macro_level) + 1]; if (!next.empty()) { @@ -2454,8 +2559,7 @@ namespace Hsdbg auto Ui::draw_command_palette(Debugger& debugger) -> void { - const bool open_requested = - ImGui::IsKeyChordPressed(ImGuiMod_Ctrl | ImGuiKey_K) || m_palette_request; + const bool open_requested = ImGui::IsKeyChordPressed(ImGuiMod_Ctrl | ImGuiKey_K) || m_palette_request; m_palette_request = false; @@ -2520,9 +2624,9 @@ namespace Hsdbg add_command(stopped, Continue, "continue"); add_command(running, Pause, "pause"); add_command(has_target, Stop, "stop"); - add_command(stopped, StepOver, "step over"); - add_command(stopped, StepInto, "step into"); - add_command(stopped, StepOut, "step out"); + add_command(stopped, StepOver, "Step Over"); + add_command(stopped, StepInto, "Step Into"); + add_command(stopped, StepOut, "Step Out"); add_command(true, ToggleProfiler, m_visible.profiler ? "hide profiler" : "show profiler"); if (!m_palette_query.empty()) @@ -2591,9 +2695,9 @@ namespace Hsdbg case Continue: report(debugger.resume(), "continue"); break; case Pause: report(debugger.pause(), "pause"); break; case Stop: report(debugger.terminate(), "stop"); break; - case StepOver: report(debugger.step_over(), "step over"); break; - case StepInto: report(debugger.step_into(), "step into"); break; - case StepOut: report(debugger.step_out(), "step out"); break; + case StepOver: report(debugger.step_over(), "Step Over"); break; + case StepInto: report(debugger.step_into(), "Step Into"); break; + case StepOut: report(debugger.step_out(), "Step Out"); break; case ToggleProfiler: m_visible.profiler = !m_visible.profiler; if (m_visible.profiler) @@ -2615,7 +2719,7 @@ namespace Hsdbg ImGui::SetNextItemWidth(-FLT_MIN); const bool submitted = ImGui::InputTextWithHint("##palette_query", - "jump to a file or symbol, or run a command", + "Jump to a file or symbol, or run a command", &m_palette_query, ImGuiInputTextFlags_EnterReturnsTrue); @@ -2630,7 +2734,7 @@ namespace Hsdbg if (entries.empty()) { - ImGui::TextDisabled("no matches"); + ImGui::TextDisabled("No matches"); } else { @@ -2686,6 +2790,117 @@ namespace Hsdbg push_console(std::format("{} failed: {}", action, result.error())); } + auto Ui::load_fonts() -> void + { + ImGuiIO& io = ImGui::GetIO(); + const std::filesystem::path dir = std::filesystem::path(HSDBG_ASSET_DIR) / "fonts"; + + static const ImWchar icon_range[] = { ICON_MIN_PH, ICON_MAX_PH, 0 }; + + const auto load = [&](const char* file, float size, bool merge_icons) -> ImFont* { + const std::string path = (dir / file).string(); + + ImFontConfig base; + base.RasterizerMultiply = 1.03f; + + ImFont* font = io.Fonts->AddFontFromFileTTF(path.c_str(), size, &base); + if (font == nullptr) + { + Log::warn("fonts: could not load '{}'", path); + return nullptr; + } + if (merge_icons) + { + ImFontConfig cfg; + cfg.MergeMode = true; + cfg.PixelSnapH = true; + cfg.GlyphMinAdvanceX = size; + cfg.GlyphOffset = ImVec2(0.0f, 1.0f); + io.Fonts->AddFontFromFileTTF((dir / "Phosphor.ttf").string().c_str(), + size, &cfg, icon_range); + } + return font; + }; + + constexpr float UI_SIZE = 16.0f; + + m_font_ui = load("Nunito-Medium.ttf", UI_SIZE, true); + m_font_strong = load("Nunito-Bold.ttf", UI_SIZE, true); + m_font_mono = load("JetBrainsMono-Regular.ttf", UI_SIZE, false); + + if (m_font_ui == nullptr) + { + Log::warn("fonts: bundled faces missing, using the built-in font"); + m_font_ui = io.Fonts->AddFontDefaultVector(); + } + if (m_font_strong == nullptr) + m_font_strong = m_font_ui; + if (m_font_mono == nullptr) + m_font_mono = m_font_ui; + + io.FontDefault = m_font_ui; + Widgets::set_fonts(m_font_ui, m_font_strong, m_font_mono); + } + + auto Ui::themes_directory() -> std::filesystem::path + { + return std::filesystem::path(HSDBG_ASSET_DIR) / "themes"; + } + + auto Ui::seed_preferences_from_theme() -> void + { + const auto copy = [](const ImVec4& from, float (&to)[3]) { + to[0] = from.x; + to[1] = from.y; + to[2] = from.z; + }; + + copy(m_theme.accent, m_preferences.accent); + m_preferences.rounding = m_theme.rounding; + copy(m_theme.syntax_keyword, m_preferences.color_keyword); + copy(m_theme.syntax_type, m_preferences.color_type); + copy(m_theme.syntax_string, m_preferences.color_string); + copy(m_theme.syntax_number, m_preferences.color_number); + copy(m_theme.syntax_comment, m_preferences.color_comment); + copy(m_theme.syntax_preprocessor, m_preferences.color_preprocessor); + copy(m_theme.current_line, m_preferences.color_current_line); + } + + auto Ui::load_selected_theme(bool seed_preferences) -> void + { + m_themes = list_themes(themes_directory()); + + std::filesystem::path path; + for (const auto& entry : m_themes) + { + if (entry.id == m_preferences.theme) + { + path = entry.path; + break; + } + } + if (path.empty() && !m_themes.empty()) + { + path = m_themes.front().path; + m_preferences.theme = m_themes.front().id; + } + + m_theme = path.empty() ? default_theme() : load_theme(path); + + if (seed_preferences) + seed_preferences_from_theme(); + } + + auto Ui::select_theme(const ThemeEntry& entry) -> void + { + m_preferences.theme = entry.id; + m_theme = load_theme(entry.path); + + seed_preferences_from_theme(); + m_restyle_pending = true; + save_preferences(m_preferences_path, m_preferences); + } + auto Ui::apply_style() -> void { ImGuiStyle& style = ImGui::GetStyle(); @@ -2700,19 +2915,29 @@ namespace Hsdbg style.GrabRounding = radius; style.TabRounding = radius; - style.WindowBorderSize = 1.0f; + style.WindowBorderSize = m_theme.window_border; style.FrameBorderSize = 0.0f; - style.WindowPadding = ImVec2(8.0f, 8.0f); - style.FramePadding = ImVec2(8.0f, 4.0f); - style.ItemSpacing = ImVec2(8.0f, 5.0f); + style.WindowPadding = ImVec2(9.0f, 7.0f); + style.FramePadding = ImVec2(9.0f, 5.0f); + style.ItemSpacing = ImVec2(7.0f, 5.0f); + style.ItemInnerSpacing = ImVec2(6.0f, 4.0f); + style.IndentSpacing = 16.0f; + style.CellPadding = ImVec2(7.0f, 4.0f); style.ScrollbarSize = 11.0f; - style.GrabMinSize = 9.0f; + style.GrabMinSize = 10.0f; + style.TabBarBorderSize = 0.0f; + style.DockingSeparatorSize = 7.0f; style.WindowTitleAlign = ImVec2(0.0f, 0.5f); style.SeparatorTextBorderSize = 1.0f; + const ImVec4 text = m_theme.text; + const ImVec4 bg = m_theme.bg; + const ImVec4 bg_low = m_theme.bg_low; + const ImVec4 bg_high = m_theme.bg_high; + const ImVec4 surface = m_theme.surface; + const ImVec4 accent(m_preferences.accent[0], m_preferences.accent[1], m_preferences.accent[2], 1.0f); - const ImVec4 base(0.18f, 0.18f, 0.22f, 1.0f); const auto mix = [](ImVec4 from, ImVec4 to, float t) { return ImVec4(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t, @@ -2721,59 +2946,61 @@ namespace Hsdbg const auto fade = [](ImVec4 colour, float alpha) { return ImVec4(colour.x, colour.y, colour.z, alpha); }; + const auto emphasis = [&](ImVec4 colour, float t) { return mix(colour, text, t); }; const ImVec4 accent_bright = mix(accent, ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 0.14f); - const ImVec4 accent_hover = mix(base, accent, 0.42f); - const ImVec4 accent_active = mix(base, accent, 0.68f); + const ImVec4 accent_hover = mix(surface, accent, 0.42f); + const ImVec4 accent_active = mix(surface, accent, 0.68f); + const ImVec4 grab = emphasis(bg, 0.18f); ImVec4* colors = style.Colors; - colors[ImGuiCol_Text] = ImVec4(0.86f, 0.86f, 0.88f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.44f, 0.44f, 0.48f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.09f, 0.09f, 0.11f, 1.00f); - colors[ImGuiCol_ChildBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.12f, 0.12f, 0.15f, 1.00f); - colors[ImGuiCol_Border] = ImVec4(0.20f, 0.20f, 0.24f, 1.00f); + colors[ImGuiCol_Text] = text; + colors[ImGuiCol_TextDisabled] = m_theme.text_dim; + colors[ImGuiCol_WindowBg] = bg; + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_PopupBg] = bg_high; + colors[ImGuiCol_Border] = m_theme.border; colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.16f, 0.19f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.21f, 0.21f, 0.26f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.25f, 0.25f, 0.31f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.11f, 0.11f, 0.14f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.11f, 0.11f, 0.14f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.09f, 0.09f, 0.11f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.24f, 0.29f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.30f, 0.30f, 0.36f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.36f, 0.43f, 1.00f); + colors[ImGuiCol_FrameBg] = bg_high; + colors[ImGuiCol_FrameBgHovered] = emphasis(bg_high, 0.06f); + colors[ImGuiCol_FrameBgActive] = emphasis(bg_high, 0.10f); + colors[ImGuiCol_TitleBg] = bg_low; + colors[ImGuiCol_TitleBgActive] = emphasis(bg_low, 0.05f); + colors[ImGuiCol_TitleBgCollapsed] = bg_low; + colors[ImGuiCol_MenuBarBg] = emphasis(bg_low, 0.04f); + colors[ImGuiCol_ScrollbarBg] = bg; + colors[ImGuiCol_ScrollbarGrab] = grab; + colors[ImGuiCol_ScrollbarGrabHovered] = emphasis(bg, 0.28f); + colors[ImGuiCol_ScrollbarGrabActive] = emphasis(bg, 0.38f); colors[ImGuiCol_CheckMark] = accent; colors[ImGuiCol_SliderGrab] = accent; colors[ImGuiCol_SliderGrabActive] = accent_bright; - colors[ImGuiCol_Button] = base; + colors[ImGuiCol_Button] = surface; colors[ImGuiCol_ButtonHovered] = accent_hover; colors[ImGuiCol_ButtonActive] = accent_active; - colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.25f, 1.00f); + colors[ImGuiCol_Header] = surface; colors[ImGuiCol_HeaderHovered] = accent_hover; colors[ImGuiCol_HeaderActive] = accent_active; - colors[ImGuiCol_Separator] = ImVec4(0.20f, 0.20f, 0.24f, 1.00f); + colors[ImGuiCol_Separator] = m_theme.border; colors[ImGuiCol_SeparatorHovered] = fade(accent, 0.60f); colors[ImGuiCol_SeparatorActive] = accent; - colors[ImGuiCol_ResizeGrip] = ImVec4(0.24f, 0.24f, 0.29f, 1.00f); + colors[ImGuiCol_ResizeGrip] = grab; colors[ImGuiCol_ResizeGripHovered] = fade(accent, 0.60f); colors[ImGuiCol_ResizeGripActive] = accent; - colors[ImGuiCol_Tab] = ImVec4(0.11f, 0.11f, 0.14f, 1.00f); - colors[ImGuiCol_TabHovered] = accent_hover; - colors[ImGuiCol_TabSelected] = mix(base, accent, 0.30f); + colors[ImGuiCol_Tab] = bg_low; + colors[ImGuiCol_TabHovered] = emphasis(bg_low, 0.10f); + colors[ImGuiCol_TabSelected] = bg; colors[ImGuiCol_TabSelectedOverline] = accent; - colors[ImGuiCol_TabDimmed] = ImVec4(0.09f, 0.09f, 0.11f, 1.00f); - colors[ImGuiCol_TabDimmedSelected] = mix(ImVec4(0.14f, 0.14f, 0.17f, 1.0f), accent, 0.16f); + colors[ImGuiCol_TabDimmed] = bg_low; + colors[ImGuiCol_TabDimmedSelected] = bg; colors[ImGuiCol_DockingPreview] = fade(accent, 0.50f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); - colors[ImGuiCol_TableHeaderBg] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f); - colors[ImGuiCol_TableBorderStrong] = ImVec4(0.20f, 0.20f, 0.24f, 1.00f); - colors[ImGuiCol_TableBorderLight] = ImVec4(0.16f, 0.16f, 0.19f, 1.00f); + colors[ImGuiCol_DockingEmptyBg] = bg_low; + colors[ImGuiCol_TableHeaderBg] = bg_high; + colors[ImGuiCol_TableBorderStrong] = m_theme.border; + colors[ImGuiCol_TableBorderLight] = mix(bg, m_theme.border, 0.5f); colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.02f); + colors[ImGuiCol_TableRowBgAlt] = fade(text, 0.03f); colors[ImGuiCol_TextSelectedBg] = fade(accent, 0.35f); colors[ImGuiCol_NavCursor] = accent; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 0dcb7e6..251a2b4 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -6,6 +6,7 @@ #include "ui/preferences.h" #include "ui/profiler.h" #include "ui/source_view.h" +#include "ui/theme.h" #include <cstdint> #include <filesystem> @@ -53,10 +54,17 @@ namespace Hsdbg bool profiler = false; bool macros = false; - bool demo = false; }; auto apply_style() -> void; + + auto load_fonts() -> void; + + auto load_selected_theme(bool seed_preferences) -> void; + auto seed_preferences_from_theme() -> void; + auto select_theme(const ThemeEntry& entry) -> void; + static auto themes_directory() -> std::filesystem::path; + static auto build_default_layout(uint32_t dockspace_id) -> void; auto draw_command_palette(Debugger& debugger) -> void; @@ -106,6 +114,14 @@ namespace Hsdbg bool m_restyle_pending = false; int m_preferences_tab = 0; + Theme m_theme; + std::vector<ThemeEntry> m_themes; + bool m_prefs_open_prev = false; + + ImFont* m_font_ui = nullptr; + ImFont* m_font_strong = nullptr; + ImFont* m_font_mono = nullptr; + AnimatedImage m_mascot; ImageRenderer m_image_renderer; bool m_mascot_loaded = false; |
