Changed time picker box to highlight closest value.

This commit is contained in:
23rd 2022-04-19 16:57:10 +03:00
parent 8faa65fdf3
commit 101e795af8
3 changed files with 21 additions and 13 deletions

View file

@ -185,9 +185,9 @@ void PickMuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> 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

View file

@ -173,13 +173,13 @@ void TTLBox(not_null<Ui::GenericBox*> 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

View file

@ -31,9 +31,17 @@ Fn<TimeId()> 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<Ui::FixedHeightWidget>(