mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-23 21:40:57 -05:00
Added two new scroll bar types. Fixed for ListView with equal height elements and PreRendered which require whole list render - not recommended for big lists but works with not equal heights elements. Applied new types to all lists in Pure. Various cleanups and refactors inside models and listView.
86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#pragma once
|
|
|
|
#include <module-gui/gui/widgets/ListItemProvider.hpp>
|
|
#include <vector>
|
|
|
|
#include "Application.hpp"
|
|
|
|
namespace app
|
|
{
|
|
|
|
template <class T> class InternalModel
|
|
{
|
|
|
|
protected:
|
|
int modelIndex = 0;
|
|
unsigned int internalOffset = 0;
|
|
unsigned int internalLimit = 0;
|
|
std::vector<T> internalData;
|
|
|
|
virtual ~InternalModel()
|
|
{
|
|
eraseInternalData();
|
|
}
|
|
|
|
void eraseInternalData()
|
|
{
|
|
for (auto item : internalData) {
|
|
delete item;
|
|
}
|
|
internalData.clear();
|
|
}
|
|
|
|
void setupModel(const uint32_t offset, const uint32_t limit)
|
|
{
|
|
modelIndex = 0;
|
|
internalOffset = offset;
|
|
internalLimit = limit;
|
|
}
|
|
|
|
gui::ListItem *getRecord(gui::Order order)
|
|
{
|
|
auto index = 0;
|
|
if (order == gui::Order::Previous) {
|
|
index = internalOffset + internalLimit - 1 + modelIndex;
|
|
|
|
modelIndex--;
|
|
}
|
|
if (order == gui::Order::Next) {
|
|
index = internalOffset + modelIndex;
|
|
|
|
modelIndex++;
|
|
}
|
|
|
|
return getInternalDataElement(index, order);
|
|
}
|
|
|
|
[[nodiscard]] bool isIndexValid(unsigned int index, gui::Order order) const noexcept
|
|
{
|
|
return (index < internalData.size()) || (order == gui::Order::Previous && index < internalOffset);
|
|
}
|
|
|
|
void clearItemProperties(T Item)
|
|
{
|
|
Item->setFocus(false);
|
|
Item->setVisible(true);
|
|
Item->clearNavigationItem(gui::NavigationDirection::UP);
|
|
Item->clearNavigationItem(gui::NavigationDirection::DOWN);
|
|
}
|
|
|
|
[[nodiscard]] gui::ListItem *getInternalDataElement(unsigned int index, gui::Order order)
|
|
{
|
|
if (isIndexValid(index, order)) {
|
|
clearItemProperties(internalData[index]);
|
|
return internalData[index];
|
|
}
|
|
else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
};
|
|
|
|
} /* namespace app */
|