From 101e795af8c6010377ac37d5de9cc8b02f3e92b5 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 19 Apr 2022 16:57:10 +0300 Subject: [PATCH] Changed time picker box to highlight closest value. --- Telegram/SourceFiles/menu/menu_mute.cpp | 6 +++--- Telegram/SourceFiles/menu/menu_ttl.cpp | 14 +++++++------- Telegram/SourceFiles/ui/boxes/time_picker_box.cpp | 14 +++++++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 38a4bd66d..addbf1018 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -185,9 +185,9 @@ void PickMuteBox(not_null box, not_null peer) { (84600 * 3), (84600 * 7 * 1), (84600 * 7 * 2), - (84600 * 30 * 1), - (84600 * 30 * 2), - (84600 * 30 * 3), + (84600 * 31 * 1), + (84600 * 31 * 2), + (84600 * 31 * 3), }; const auto phrases = ranges::views::all( seconds diff --git a/Telegram/SourceFiles/menu/menu_ttl.cpp b/Telegram/SourceFiles/menu/menu_ttl.cpp index 9d77a6a73..0b2eb509d 100644 --- a/Telegram/SourceFiles/menu/menu_ttl.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl.cpp @@ -173,13 +173,13 @@ void TTLBox(not_null box, Args args) { (86400 * 7 * 1), (86400 * 7 * 2), (86400 * 7 * 3), - (86400 * 30 * 1), - (86400 * 30 * 2), - (86400 * 30 * 3), - (86400 * 30 * 4), - (86400 * 30 * 5), - (86400 * 30 * 6), - (86400 * 30 * 12), + (86400 * 31 * 1), + (86400 * 31 * 2), + (86400 * 31 * 3), + (86400 * 31 * 4), + (86400 * 31 * 5), + (86400 * 31 * 6), + (86400 * 365), }; const auto phrases = ranges::views::all( ttls diff --git a/Telegram/SourceFiles/ui/boxes/time_picker_box.cpp b/Telegram/SourceFiles/ui/boxes/time_picker_box.cpp index 2547f919f..3e001e9ef 100644 --- a/Telegram/SourceFiles/ui/boxes/time_picker_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/time_picker_box.cpp @@ -31,9 +31,17 @@ Fn TimePickerBox( TimeId startValue) { Expects(phrases.size() == values.size()); - const auto startIndex = [&] { - const auto it = ranges::find(values, startValue); - return (it == end(values)) ? 0 : std::distance(begin(values), it); + const auto startIndex = [&, &v = startValue] { + const auto it = ranges::lower_bound(values, v); + if (it == begin(values)) { + return 0; + } + const auto left = *(it - 1); + const auto right = *it; + const auto shift = (std::abs(v - left) < std::abs(v - right)) + ? -1 + : 0; + return int(std::distance(begin(values), it - shift)); }(); const auto content = box->addRow(object_ptr(