mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-05 15:55:45 +00:00
Improve performance of ItemView resize (reposition widgets instead of recreate)
This commit is contained in:
parent
084cc857d4
commit
ddba9e5854
@ -56,6 +56,43 @@ void ItemView::initialiseOverride()
|
|||||||
mScrollView->setCanvasAlign(MyGUI::Align::Left | MyGUI::Align::Top);
|
mScrollView->setCanvasAlign(MyGUI::Align::Left | MyGUI::Align::Top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemView::layoutWidgets()
|
||||||
|
{
|
||||||
|
if (!mScrollView->getChildCount())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
int maxHeight = mScrollView->getSize().height - 58;
|
||||||
|
|
||||||
|
MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
|
||||||
|
|
||||||
|
for (unsigned int i=0; i<dragArea->getChildCount(); ++i)
|
||||||
|
{
|
||||||
|
MyGUI::Widget* w = dragArea->getChildAt(i);
|
||||||
|
|
||||||
|
w->setPosition(x, y);
|
||||||
|
|
||||||
|
y += 42;
|
||||||
|
if (y > maxHeight)
|
||||||
|
{
|
||||||
|
x += 42;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += 42;
|
||||||
|
|
||||||
|
MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);
|
||||||
|
|
||||||
|
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||||
|
mScrollView->setVisibleVScroll(false);
|
||||||
|
mScrollView->setVisibleHScroll(false);
|
||||||
|
mScrollView->setCanvasSize(size);
|
||||||
|
mScrollView->setVisibleVScroll(true);
|
||||||
|
mScrollView->setVisibleHScroll(true);
|
||||||
|
dragArea->setSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
void ItemView::update()
|
void ItemView::update()
|
||||||
{
|
{
|
||||||
while (mScrollView->getChildCount())
|
while (mScrollView->getChildCount())
|
||||||
@ -64,10 +101,6 @@ void ItemView::update()
|
|||||||
if (!mModel)
|
if (!mModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int x = 0;
|
|
||||||
int y = 0;
|
|
||||||
int maxHeight = mScrollView->getSize().height - 58;
|
|
||||||
|
|
||||||
mModel->update();
|
mModel->update();
|
||||||
|
|
||||||
MyGUI::Widget* dragArea = mScrollView->createWidget<MyGUI::Widget>("",0,0,mScrollView->getWidth(),mScrollView->getHeight(),
|
MyGUI::Widget* dragArea = mScrollView->createWidget<MyGUI::Widget>("",0,0,mScrollView->getWidth(),mScrollView->getHeight(),
|
||||||
@ -80,9 +113,8 @@ void ItemView::update()
|
|||||||
{
|
{
|
||||||
const ItemStack& item = mModel->getItem(i);
|
const ItemStack& item = mModel->getItem(i);
|
||||||
|
|
||||||
/// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them
|
|
||||||
ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
|
ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
|
||||||
MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default);
|
MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
|
||||||
itemWidget->setUserString("ToolTipType", "ItemModelIndex");
|
itemWidget->setUserString("ToolTipType", "ItemModelIndex");
|
||||||
itemWidget->setUserData(std::make_pair(i, mModel));
|
itemWidget->setUserData(std::make_pair(i, mModel));
|
||||||
ItemWidget::ItemState state = ItemWidget::None;
|
ItemWidget::ItemState state = ItemWidget::None;
|
||||||
@ -104,25 +136,9 @@ void ItemView::update()
|
|||||||
text->setTextShadow(true);
|
text->setTextShadow(true);
|
||||||
text->setTextShadowColour(MyGUI::Colour(0,0,0));
|
text->setTextShadowColour(MyGUI::Colour(0,0,0));
|
||||||
text->setCaption(getCountString(item.mCount));
|
text->setCaption(getCountString(item.mCount));
|
||||||
|
|
||||||
y += 42;
|
|
||||||
if (y > maxHeight)
|
|
||||||
{
|
|
||||||
x += 42;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
x += 42;
|
|
||||||
MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);
|
|
||||||
|
|
||||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
layoutWidgets();
|
||||||
mScrollView->setVisibleVScroll(false);
|
|
||||||
mScrollView->setVisibleHScroll(false);
|
|
||||||
mScrollView->setCanvasSize(size);
|
|
||||||
mScrollView->setVisibleVScroll(true);
|
|
||||||
mScrollView->setVisibleHScroll(true);
|
|
||||||
dragArea->setSize(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemView::onSelectedItem(MyGUI::Widget *sender)
|
void ItemView::onSelectedItem(MyGUI::Widget *sender)
|
||||||
@ -149,7 +165,7 @@ void ItemView::setSize(const MyGUI::IntSize &_value)
|
|||||||
bool changed = (_value.width != getWidth() || _value.height != getHeight());
|
bool changed = (_value.width != getWidth() || _value.height != getHeight());
|
||||||
Base::setSize(_value);
|
Base::setSize(_value);
|
||||||
if (changed)
|
if (changed)
|
||||||
update();
|
layoutWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemView::setSize(int _width, int _height)
|
void ItemView::setSize(int _width, int _height)
|
||||||
@ -162,7 +178,7 @@ void ItemView::setCoord(const MyGUI::IntCoord &_value)
|
|||||||
bool changed = (_value.width != getWidth() || _value.height != getHeight());
|
bool changed = (_value.width != getWidth() || _value.height != getHeight());
|
||||||
Base::setCoord(_value);
|
Base::setCoord(_value);
|
||||||
if (changed)
|
if (changed)
|
||||||
update();
|
layoutWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemView::setCoord(int _left, int _top, int _width, int _height)
|
void ItemView::setCoord(int _left, int _top, int _width, int _height)
|
||||||
|
@ -35,6 +35,8 @@ namespace MWGui
|
|||||||
private:
|
private:
|
||||||
virtual void initialiseOverride();
|
virtual void initialiseOverride();
|
||||||
|
|
||||||
|
void layoutWidgets();
|
||||||
|
|
||||||
virtual void setSize(const MyGUI::IntSize& _value);
|
virtual void setSize(const MyGUI::IntSize& _value);
|
||||||
virtual void setCoord(const MyGUI::IntCoord& _value);
|
virtual void setCoord(const MyGUI::IntCoord& _value);
|
||||||
void setSize(int _width, int _height);
|
void setSize(int _width, int _height);
|
||||||
|
Loading…
Reference in New Issue
Block a user