Backport irrlicht changes to CGUISTKListBox

This commit is contained in:
CodingJellyfish 2024-04-21 14:05:34 +08:00
parent 2a60d6508b
commit af1238d688
2 changed files with 17 additions and 6 deletions

View File

@ -40,11 +40,8 @@ CGUISTKListBox::CGUISTKListBox(IGUIEnvironment* environment, IGUIElement* parent
#endif #endif
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
const s32 s = skin->getSize(EGDS_SCROLLBAR_SIZE);
ScrollBar = Environment->addScrollBar(false, ScrollBar = Environment->addScrollBar(false, core::recti(0, 0, 1, 1), this, -1);
core::rect<s32>(RelativeRect.getWidth() - s, 0,
RelativeRect.getWidth(), RelativeRect.getHeight()), this, -1);
ScrollBar->grab(); ScrollBar->grab();
ScrollBar->setSubElement(true); ScrollBar->setSubElement(true);
ScrollBar->setTabStop(false); ScrollBar->setTabStop(false);
@ -52,6 +49,8 @@ CGUISTKListBox::CGUISTKListBox(IGUIEnvironment* environment, IGUIElement* parent
ScrollBar->setVisible(false); ScrollBar->setVisible(false);
ScrollBar->setPos(0); ScrollBar->setPos(0);
updateScrollBarSize(skin->getSize(EGDS_SCROLLBAR_SIZE));
setNotClipped(!clip); setNotClipped(!clip);
// this element can be tabbed to // this element can be tabbed to
@ -478,6 +477,7 @@ void CGUISTKListBox::draw()
recalculateItemHeight(); // if the font changed recalculateItemHeight(); // if the font changed
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
updateScrollBarSize(skin->getSize(EGDS_SCROLLBAR_SIZE));
core::rect<s32>* clipRect = 0; core::rect<s32>* clipRect = 0;
@ -489,7 +489,7 @@ void CGUISTKListBox::draw()
core::rect<s32> clientClip(AbsoluteRect); core::rect<s32> clientClip(AbsoluteRect);
clientClip.UpperLeftCorner.Y += 1; clientClip.UpperLeftCorner.Y += 1;
if (ScrollBar->isVisible()) if (ScrollBar->isVisible())
clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize(EGDS_SCROLLBAR_SIZE); clientClip.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth();
clientClip.LowerRightCorner.Y -= 1; clientClip.LowerRightCorner.Y -= 1;
clientClip.clipAgainst(AbsoluteClippingRect); clientClip.clipAgainst(AbsoluteClippingRect);
@ -501,7 +501,7 @@ void CGUISTKListBox::draw()
frameRect = AbsoluteRect; frameRect = AbsoluteRect;
if (ScrollBar->isVisible()) if (ScrollBar->isVisible())
frameRect.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize(EGDS_SCROLLBAR_SIZE); frameRect.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth();
frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight; frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight;
@ -817,6 +817,16 @@ void CGUISTKListBox::setDrawBackground(bool draw)
} }
void CGUISTKListBox::updateScrollBarSize(s32 size)
{
if (size != ScrollBar->getRelativePosition().getWidth())
{
core::recti r(RelativeRect.getWidth() - size, 0, RelativeRect.getWidth(), RelativeRect.getHeight());
ScrollBar->setRelativePosition(r);
}
}
} // end namespace gui } // end namespace gui
} // end namespace irr } // end namespace irr

View File

@ -183,6 +183,7 @@ namespace irr
void recalculateItemHeight(); void recalculateItemHeight();
void selectNew(s32 ypos, bool onlyHover=false); void selectNew(s32 ypos, bool onlyHover=false);
void recalculateScrollPos(); void recalculateScrollPos();
void updateScrollBarSize(s32 size);
// extracted that function to avoid copy&paste code // extracted that function to avoid copy&paste code
void recalculateIconWidth(); void recalculateIconWidth();