Add Carousel::getSelection() method
This commit is contained in:
+1
-4
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user