Add Carousel::getSelection() method

This commit is contained in:
Bertrand Songis
2020-04-06 09:26:49 +02:00
parent 2a0b3b30b6
commit db58d78388
2 changed files with 23 additions and 4 deletions
+1 -4
View File
@@ -25,10 +25,7 @@ void CarouselWindow::update()
first = max(0, first);
coord_t lastPosition = 0;
for (auto & item: items) {
item.front->detach();
item.back->detach();
}
detachItems();
for (uint8_t index = first; lastPosition < width() && index < items.size(); index++) {
auto & item = items[index];
+22
View File
@@ -47,6 +47,16 @@ class CarouselWindow: public Window {
{
}
~CarouselWindow() override
{
detachItems();
// TODO memory leak here
// for (auto & item: items) {
// item.front->deleteLater();
// item.back->deleteLater();
// }
}
void addItem(CarouselItem item)
{
items.emplace_back(item);
@@ -70,6 +80,14 @@ class CarouselWindow: public Window {
protected:
std::vector<CarouselItem> items;
void detachItems()
{
for (auto & item: items) {
item.front->detach();
item.back->detach();
}
}
void update();
};
@@ -104,6 +122,10 @@ class Carousel: public Window {
nextButton->enable(index < (int)body->items.size() - 1);
}
int getSelection()
{
return body->selection;
}
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;