mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-22 09:07:05 +02:00
Changed time picker box to highlight closest value.
This commit is contained in:
parent
8faa65fdf3
commit
101e795af8
3 changed files with 21 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>(
|
||||
|
|
Loading…
Add table
Reference in a new issue