[Carousel] Protection

This commit is contained in:
Bertrand Songis
2021-04-06 15:16:24 +02:00
parent da2215d01e
commit e7bcd7b852
2 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ void CarouselWindow::update()
first = max(0, first);
coord_t lastPosition = 0;
coord_t spacing = 10;
if (count > 1)
if (items.size() > 0 && count > 0)
spacing = (width() - items[0]->back->width() * (count - 1) - items[0]->front->width()) / (count - 1);
int index = 0;
+7 -5
View File
@@ -55,7 +55,7 @@ class CarouselWindow: public Window
{
}
void deleteLater(bool detach = true, bool trash = true) override
void deleteLater(bool detach = true, bool trash = true) override // NOLINT(google-default-arguments)
{
if (_deleted)
return;
@@ -86,9 +86,11 @@ class CarouselWindow: public Window
void select(int index, bool scroll = true)
{
selection = index;
auto item = items[selection];
if (item->selectHandler) {
item->selectHandler();
if (selection >= 0) {
auto item = items[selection];
if (item->selectHandler) {
item->selectHandler();
}
}
update();
}
@@ -96,7 +98,7 @@ class CarouselWindow: public Window
protected:
std::vector<CarouselItem *> items;
int selection = 0;
uint8_t count;
unsigned count;
void update();
};