mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 23:39:29 -05: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 const_reference = typename ContainerType::const_reference;
|
||||
using const_iterator = typename ContainerType::const_iterator;
|
||||
using RangeType = std::pair<const_iterator, const_iterator>;
|
||||
|
||||
EntryType& on_packet(const Key key) {
|
||||
auto matching_recent = find(key);
|
||||
@ -80,9 +79,23 @@ public:
|
||||
return entries.empty();
|
||||
}
|
||||
|
||||
RangeType range_around(
|
||||
const_iterator item, const size_t count
|
||||
) const {
|
||||
private:
|
||||
ContainerType entries;
|
||||
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 end = item;
|
||||
size_t i = 0;
|
||||
@ -102,17 +115,6 @@ public:
|
||||
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 {
|
||||
|
||||
using RecentEntriesColumn = std::pair<std::string, size_t>;
|
||||
@ -162,7 +164,7 @@ public:
|
||||
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++) {
|
||||
const auto& entry = *p;
|
||||
|
Loading…
Reference in New Issue
Block a user