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