From 49cac136a5fa71792741e70fba096cb2b5821e2c Mon Sep 17 00:00:00 2001 From: DanS Date: Fri, 20 Nov 2026 13:04:58 -0600 Subject: [PATCH] feat(contacts): search clear (x) + Esc, name/recently-added sort toggle (F089) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UX audit, Contacts surface — search & sort affordances (choice a): - A trailing (x) clears the search box, and Escape clears it while focused. - Cards & List gain a sort toggle (name / recently added) in the toolbar, beside the view switch; Table keeps its own sortable headers. "Recently added" uses storage/append order (newest first). New strings (English). Build + tests green. Co-Authored-By: Claude Opus 4.8 --- src/ui/windows/contacts_tab.cpp | 48 +++++++++++++++++++++++++++------ src/util/i18n.cpp | 3 +++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/ui/windows/contacts_tab.cpp b/src/ui/windows/contacts_tab.cpp index efa2a78..0d803ce 100644 --- a/src/ui/windows/contacts_tab.cpp +++ b/src/ui/windows/contacts_tab.cpp @@ -54,6 +54,7 @@ static char s_edit_address[512] = ""; static char s_edit_notes[512] = ""; static bool s_edit_global = false; // add/edit dialog: "visible in every wallet" toggle static char s_search[128] = ""; +static int s_contactsSort = 0; // Cards/List sort: 0 = name, 1 = recently added (F089) // Avatar being edited: "" = default Z/T badge, "icon:", or "img:". static std::string s_edit_avatar; static int s_edit_avatar_mode = 0; // 0 = badge, 1 = icon, 2 = image (segmented picker) @@ -1128,10 +1129,26 @@ void RenderContactsTab(App* app) const float segH = ImGui::GetFrameHeight(); const float segW = 44.0f * dp * 3.0f; const float segGap = 6.0f * dp; - const float grpW = segW + segGap + segH; // view toggle + gap + a square settings gear + // Sort toggle (name / recently added) shows only for Cards & List — Table has sortable headers. (F089) + const bool showSort = (viewMode != 2); + const float sortW = showSort ? (segH + segGap) : 0.0f; + const float grpW = sortW + segW + segGap + segH; // [sort] view toggle + gap + a square settings gear ImGui::SameLine(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + std::max(0.0f, ImGui::GetContentRegionAvail().x - grpW)); - ImVec2 segOrigin = ImGui::GetCursorScreenPos(); + ImVec2 clusterOrigin = ImGui::GetCursorScreenPos(); + if (showSort) { + material::IconButtonStyle sst; + sst.tooltip = (s_contactsSort == 1) ? TR("contacts_sort_recent") : TR("contacts_sort_name"); + sst.hoverBg = material::WithAlpha(material::OnSurface(), 30); + sst.restBg = material::WithAlpha(material::OnSurface(), 20); + sst.bgRounding = 7.0f * dp; + if (material::IconButton("##contactsSort", + s_contactsSort == 1 ? ICON_MD_SCHEDULE : ICON_MD_SORT_BY_ALPHA, + material::Type().iconSmall(), ImVec2(segH, segH), sst)) + s_contactsSort ^= 1; + } + ImVec2 segOrigin(clusterOrigin.x + sortW, clusterOrigin.y); + ImGui::SetCursorScreenPos(segOrigin); int segClk = material::SegmentedControl(ImGui::GetWindowDrawList(), segOrigin, segW, segH, segIcons, 3, viewMode, material::Type().iconSmall(), "##contactsView", dp); @@ -1150,15 +1167,25 @@ void RenderContactsTab(App* app) if (material::IconButton("##contactsSettings", ICON_MD_SETTINGS, material::Type().iconSmall(), ImVec2(segH, segH), gst)) s_show_contacts_settings = true; - ImGui::SetCursorScreenPos(segOrigin); + ImGui::SetCursorScreenPos(clusterOrigin); ImGui::Dummy(ImVec2(grpW, segH)); } // Search / filter (tight against the toolbar row above — no extra spacer) - ImGui::SetNextItemWidth(std::min(ImGui::GetContentRegionAvail().x, 700.0f * dp)); + const bool hasSearch = s_search[0] != '\0'; + const float clearW = hasSearch ? (ImGui::GetFrameHeight() + 4.0f * dp) : 0.0f; // room for the (x) (F089) + ImGui::SetNextItemWidth(std::min(ImGui::GetContentRegionAvail().x - clearW, 700.0f * dp)); ImGui::InputTextWithHint("##ContactSearch", TR("contacts_search_placeholder"), s_search, sizeof(s_search)); bool searchActive = ImGui::IsItemActive(); + if (searchActive && ImGui::IsKeyPressed(ImGuiKey_Escape)) s_search[0] = '\0'; // Esc clears (F089) + if (hasSearch) { + ImGui::SameLine(0, 4.0f * dp); + material::IconButtonStyle xst; xst.tooltip = TR("clear_search"); + if (material::IconButton("##clrSearch", ICON_MD_CLOSE, material::Type().iconSmall(), + ImVec2(ImGui::GetFrameHeight(), ImGui::GetFrameHeight()), xst)) + s_search[0] = '\0'; + } std::string needle = toLower(s_search); ImGui::Spacing(); @@ -1322,12 +1349,17 @@ void RenderContactsTab(App* app) } else { // ── CARDS (0) / LIST (1) mode — tactile Material items, no grid lines. ── const bool asCard = (viewMode == 0); - // Cards/list have no interactive sort header — sort by label ascending. + // Cards/List sort: by label (default) or recently added (storage/append order, newest first). (F089) { const auto& entries = book.entries(); - std::stable_sort(visibleRows.begin(), visibleRows.end(), [&](size_t a, size_t b) { - return util::compareIgnoreCase(entries[a].label, entries[b].label) < 0; - }); + if (s_contactsSort == 1) { + std::stable_sort(visibleRows.begin(), visibleRows.end(), + [](size_t a, size_t b) { return a > b; }); + } else { + std::stable_sort(visibleRows.begin(), visibleRows.end(), [&](size_t a, size_t b) { + return util::compareIgnoreCase(entries[a].label, entries[b].label) < 0; + }); + } } // Frosted-glass list container so the contacts area blurs the backdrop (peers_tab pattern: // glass behind a NoBackground list child) instead of showing the raw texture through the pane. diff --git a/src/util/i18n.cpp b/src/util/i18n.cpp index be17da0..8fb1c76 100644 --- a/src/util/i18n.cpp +++ b/src/util/i18n.cpp @@ -2048,6 +2048,9 @@ void I18n::loadBuiltinEnglish() strings_["contacts_delete_armed_tip"] = "Click again to delete \"%s\" \xE2\x80\x94 cannot be undone"; strings_["contacts_avatar_del"] = "Delete this image"; strings_["contacts_avatar_del_armed"] = "Click again to permanently delete this image. Contacts using it show the default badge."; + strings_["clear_search"] = "Clear search"; + strings_["contacts_sort_name"] = "Sort: name (click for recently added)"; + strings_["contacts_sort_recent"] = "Sort: recently added (click for name)"; strings_["address_book_count_one"] = "%zu address saved"; strings_["address_book_deleted"] = "Entry deleted"; strings_["address_book_edit"] = "Edit Address";