mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-06-08 04:08:35 +00:00
RecentEntries: Extract range_around().
This commit is contained in:
parent
42d98c3b45
commit
b596d0697c
@ -41,7 +41,6 @@ public:
|
|||||||
using ContainerType = std::list<EntryType>;
|
using ContainerType = std::list<EntryType>;
|
||||||
using const_reference = typename ContainerType::const_reference;
|
using const_reference = typename ContainerType::const_reference;
|
||||||
using const_iterator = typename ContainerType::const_iterator;
|
using const_iterator = typename ContainerType::const_iterator;
|
||||||
using RangeType = std::pair<const_iterator, const_iterator>;
|
|
||||||
|
|
||||||
EntryType& on_packet(const Key key) {
|
EntryType& on_packet(const Key key) {
|
||||||
auto matching_recent = find(key);
|
auto matching_recent = find(key);
|
||||||
@ -80,9 +79,23 @@ public:
|
|||||||
return entries.empty();
|
return entries.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeType range_around(
|
private:
|
||||||
const_iterator item, const size_t count
|
ContainerType entries;
|
||||||
) const {
|
const size_t entries_max = 64;
|
||||||
|
|
||||||
|
void truncate_entries() {
|
||||||
|
while(entries.size() > entries_max) {
|
||||||
|
entries.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ContainerType>
|
||||||
|
static std::pair<typename ContainerType::const_iterator, typename ContainerType::const_iterator> range_around(
|
||||||
|
const ContainerType& entries,
|
||||||
|
typename ContainerType::const_iterator item,
|
||||||
|
const size_t count
|
||||||
|
) {
|
||||||
auto start = item;
|
auto start = item;
|
||||||
auto end = item;
|
auto end = item;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@ -100,18 +113,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { start, end };
|
return { start, end };
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
ContainerType entries;
|
|
||||||
const size_t entries_max = 64;
|
|
||||||
|
|
||||||
void truncate_entries() {
|
|
||||||
while(entries.size() > entries_max) {
|
|
||||||
entries.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@ -162,7 +164,7 @@ public:
|
|||||||
selected = std::begin(recent);
|
selected = std::begin(recent);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto range = recent.range_around(selected, visible_item_count);
|
auto range = range_around(recent, selected, visible_item_count);
|
||||||
|
|
||||||
for(auto p = range.first; p != range.second; p++) {
|
for(auto p = range.first; p != range.second; p++) {
|
||||||
const auto& entry = *p;
|
const auto& entry = *p;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user