From 7b2e0f133d42c9c52b7d20351fa6bc67f7dda730 Mon Sep 17 00:00:00 2001 From: GigabiteStudios Date: Thu, 18 Jun 2026 16:43:34 -0500 Subject: [PATCH] refactor(toolbar): center icon actions with tooltips --- src/main.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0a76957..f15d942 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -558,9 +558,16 @@ void draw_details() { ImGui::EndChild(); } -void toolbar_button(const char* label, const char* notice) { - if (ImGui::Button(label, {ui(68), ui(34)})) g_notice = notice; - ImGui::SameLine(); +bool toolbar_action(const char* id, const char* icon, const char* tooltip) { + ImGui::PushID(id); + const bool clicked = ImGui::Button(icon, {ui(36), ui(36)}); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) { + ImGui::BeginTooltip(); + ImGui::TextUnformatted(tooltip); + ImGui::EndTooltip(); + } + ImGui::PopID(); + return clicked; } void external_link(const char* label, const char* url) { @@ -785,13 +792,24 @@ void draw_app() { for (const auto& branch : repo().local_branches) ImGui::Selectable(branch.c_str(), branch == repo().branch); ImGui::EndCombo(); } - ImGui::SameLine(ui(350)); - toolbar_button(ICON_FA_DOWNLOAD " Pull", "Pull is not wired yet"); - toolbar_button(ICON_FA_UPLOAD " Push", "Push is not wired yet"); - toolbar_button(ICON_FA_CODE_BRANCH " Branch", "Branch creation is not wired yet"); - toolbar_button(ICON_FA_BOX_ARCHIVE " Stash", "Stash is not wired yet"); - toolbar_button(ICON_FA_BOX_OPEN " Pop", "Stash pop is not wired yet"); - if (ImGui::Button(ICON_FA_ROTATE " Refresh", {ui(82), ui(34)}) && repo().repo) load_repository_data(); + constexpr int action_count = 6; + const float action_size = ui(36.0f); + const float action_spacing = ui(7.0f); + const float action_group_width = action_size * action_count + action_spacing * (action_count - 1); + const float centered_x = (ImGui::GetWindowWidth() - action_group_width) * 0.5f; + ImGui::SetCursorPos({std::max(ui(350.0f), centered_x), ui(10.0f)}); + + if (toolbar_action("pull", ICON_FA_DOWNLOAD, "Pull from remote")) g_notice = "Pull is not wired yet"; + ImGui::SameLine(0, action_spacing); + if (toolbar_action("push", ICON_FA_UPLOAD, "Push to remote")) g_notice = "Push is not wired yet"; + ImGui::SameLine(0, action_spacing); + if (toolbar_action("branch", ICON_FA_CODE_BRANCH, "Create branch")) g_notice = "Branch creation is not wired yet"; + ImGui::SameLine(0, action_spacing); + if (toolbar_action("stash", ICON_FA_BOX_ARCHIVE, "Stash changes")) g_notice = "Stash is not wired yet"; + ImGui::SameLine(0, action_spacing); + if (toolbar_action("pop", ICON_FA_BOX_OPEN, "Pop latest stash")) g_notice = "Stash pop is not wired yet"; + ImGui::SameLine(0, action_spacing); + if (toolbar_action("refresh", ICON_FA_ROTATE, "Refresh repository")) load_repository_data(); ImGui::EndChild(); draw_sidebar(ui(g_sidebar_width));