1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

better approach for scrollbar

This commit is contained in:
Laserlicht
2024-11-02 15:16:38 +01:00
parent 9009dffebd
commit 0ab4b66026
5 changed files with 8 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -116,12 +116,12 @@ void CListBox::updatePositions()
(elem)->moveTo(itemPos); (elem)->moveTo(itemPos);
itemPos += itemOffset; itemPos += itemOffset;
} }
if (isActive()) if(slider)
{ {
redraw(); slider->scrollTo((int)first);
if (slider) moveChildForeground(slider.get());
slider->scrollTo((int)first);
} }
redraw();
} }
void CListBox::reset() void CListBox::reset()
@ -185,9 +185,6 @@ void CListBox::scrollTo(size_t which)
//scroll down //scroll down
else if (first + items.size() <= which && which < totalSize) else if (first + items.size() <= which && which < totalSize)
moveToPos(which - items.size() + 1); moveToPos(which - items.size() + 1);
if(slider)
slider->scrollTo(which);
} }
void CListBox::moveToPos(size_t which) void CListBox::moveToPos(size_t which)

View File

@ -240,8 +240,8 @@ CStackWindow::ActiveSpellsSection::ActiveSpellsSection(CStackWindow * owner, int
} }
} }
CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t lineIndex, bool noScroll) CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t lineIndex)
: CWindowSection(owner, ImagePath::builtin(noScroll ? "stackWindow/bonus-effects-noscroll" : "stackWindow/bonus-effects"), 0) : CWindowSection(owner, ImagePath::builtin("stackWindow/bonus-effects"), 0)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
@ -324,7 +324,7 @@ CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset,
auto onCreate = [=](size_t index) -> std::shared_ptr<CIntObject> auto onCreate = [=](size_t index) -> std::shared_ptr<CIntObject>
{ {
return std::make_shared<BonusLineSection>(owner, index, totalSize <= 3); return std::make_shared<BonusLineSection>(owner, index);
}; };
lines = std::make_shared<CListBox>(onCreate, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, totalSize > 3 ? 1 : 0, Rect(pos.w - 15, 0, pos.h, pos.h)); lines = std::make_shared<CListBox>(onCreate, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, totalSize > 3 ? 1 : 0, Rect(pos.w - 15, 0, pos.h, pos.h));

View File

@ -89,7 +89,7 @@ class CStackWindow : public CWindowObject
std::array<std::shared_ptr<GraphicalPrimitiveCanvas>, 2> frame; std::array<std::shared_ptr<GraphicalPrimitiveCanvas>, 2> frame;
std::array<std::vector<std::shared_ptr<CLabel>>, 2> bonusSource; std::array<std::vector<std::shared_ptr<CLabel>>, 2> bonusSource;
public: public:
BonusLineSection(CStackWindow * owner, size_t lineIndex, bool noScroll); BonusLineSection(CStackWindow * owner, size_t lineIndex);
}; };
class BonusesSection : public CWindowSection class BonusesSection : public CWindowSection