Carousel update
This commit is contained in:
+5
-2
@@ -21,9 +21,12 @@
|
||||
|
||||
void CarouselWindow::update()
|
||||
{
|
||||
auto first = min<int>(selection - 2, items.size() - 5);
|
||||
auto first = min<int>(selection - 2, items.size() - count);
|
||||
first = max(0, first);
|
||||
coord_t lastPosition = 0;
|
||||
coord_t spacing = 10;
|
||||
if (count > 1)
|
||||
spacing = (width() - items[0]->back->width() * (count - 1) - items[0]->front->width()) / (count - 1);
|
||||
|
||||
int index = 0;
|
||||
for (auto & item: items) {
|
||||
@@ -41,7 +44,7 @@ void CarouselWindow::update()
|
||||
window->setTop((height() - window->height()) / 2);
|
||||
if (index == first)
|
||||
setScrollPositionX(lastPosition);
|
||||
lastPosition += window->width() + CAROUSEL_SPACING;
|
||||
lastPosition += window->width() + spacing;
|
||||
index += 1;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -23,8 +23,6 @@
|
||||
#include <vector>
|
||||
#include "button.h"
|
||||
|
||||
constexpr coord_t CAROUSEL_SPACING = 20;
|
||||
|
||||
class CarouselItem {
|
||||
public:
|
||||
CarouselItem(Window * front, Window * back):
|
||||
@@ -50,8 +48,9 @@ class CarouselWindow: public Window {
|
||||
friend class Carousel;
|
||||
|
||||
public:
|
||||
CarouselWindow(Window * parent, const rect_t & rect):
|
||||
Window(parent, rect, NO_SCROLLBAR)
|
||||
CarouselWindow(Window * parent, const rect_t & rect, uint8_t count):
|
||||
Window(parent, rect, NO_SCROLLBAR),
|
||||
count(count)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -90,6 +89,7 @@ class CarouselWindow: public Window {
|
||||
protected:
|
||||
std::vector<CarouselItem *> items;
|
||||
int selection = 0;
|
||||
uint8_t count;
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user