fix for Bug #509

This commit is contained in:
Sebastian Wick 2013-03-09 20:40:59 +01:00
parent 1132032599
commit 0ae48c1f83
3 changed files with 37 additions and 8 deletions

View file

@ -1,9 +1,9 @@
#include "list.hpp" #include "list.hpp"
#include <MyGUI_ScrollView.h>
#include <MyGUI_Gui.h> #include <MyGUI_Gui.h>
#include <MyGUI_Button.h> #include <MyGUI_Button.h>
#include <MyGUI_ImageBox.h> #include <MyGUI_ImageBox.h>
#include <MyGUI_ScrollBar.h>
using namespace MWGui; using namespace MWGui;
using namespace MWGui::Widgets; using namespace MWGui::Widgets;
@ -23,7 +23,7 @@ void MWList::initialiseOverride()
if (mClient == 0) if (mClient == 0)
mClient = this; mClient = this;
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>( mScrollView = mClient->createWidgetReal<MWGui::Widgets::MWScrollView>(
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0), "MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView"); MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
} }
@ -48,6 +48,7 @@ void MWList::redraw(bool scrollbarShown)
const int _scrollBarWidth = 24; // fetch this from skin? const int _scrollBarWidth = 24; // fetch this from skin?
const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0; const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0;
const int spacing = 3; const int spacing = 3;
size_t scrollbarPosition = mScrollView->getScrollPosition();
while (mScrollView->getChildCount()) while (mScrollView->getChildCount())
{ {
@ -88,6 +89,11 @@ void MWList::redraw(bool scrollbarShown)
if (!scrollbarShown && mItemHeight > mClient->getSize().height) if (!scrollbarShown && mItemHeight > mClient->getSize().height)
redraw(true); redraw(true);
size_t scrollbarRange = mScrollView->getScrollRange();
if(scrollbarPosition > scrollbarRange)
scrollbarPosition = scrollbarRange;
mScrollView->setScrollPosition(scrollbarPosition);
} }
bool MWList::hasItem(const std::string& name) bool MWList::hasItem(const std::string& name)
@ -138,3 +144,17 @@ MyGUI::Widget* MWList::getItemWidget(const std::string& name)
{ {
return mScrollView->findWidget (getName() + "_item_" + name); return mScrollView->findWidget (getName() + "_item_" + name);
} }
size_t MWScrollView::getScrollPosition()
{
return getVScroll()->getScrollPosition();
}
void MWScrollView::setScrollPosition(size_t position)
{
getVScroll()->setScrollPosition(position);
}
size_t MWScrollView::getScrollRange()
{
return getVScroll()->getScrollRange();
}

View file

@ -2,16 +2,24 @@
#define MWGUI_LIST_HPP #define MWGUI_LIST_HPP
#include <MyGUI_Widget.h> #include <MyGUI_Widget.h>
#include <MyGUI_ScrollView.h>
namespace MyGUI
{
class ScrollView;
}
namespace MWGui namespace MWGui
{ {
namespace Widgets namespace Widgets
{ {
/**
* \brief a custom ScrollView which has access to scrollbar properties
*/
class MWScrollView : public MyGUI::ScrollView
{
MYGUI_RTTI_DERIVED(MWScrollView)
public:
size_t getScrollPosition();
void setScrollPosition(size_t);
size_t getScrollRange();
};
/** /**
* \brief a very simple list widget that supports word-wrapping entries * \brief a very simple list widget that supports word-wrapping entries
* \note if the width or height of the list changes, you must call adjustSize() method * \note if the width or height of the list changes, you must call adjustSize() method
@ -63,7 +71,7 @@ namespace MWGui
void onItemSelected(MyGUI::Widget* _sender); void onItemSelected(MyGUI::Widget* _sender);
private: private:
MyGUI::ScrollView* mScrollView; MWGui::Widgets::MWScrollView* mScrollView;
MyGUI::Widget* mClient; MyGUI::Widget* mClient;
std::vector<std::string> mItems; std::vector<std::string> mItems;

View file

@ -132,6 +132,7 @@ WindowManager::WindowManager(
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::AutoSizedButton>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::AutoSizedButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ImageButton>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ImageButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ExposedWindow>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ExposedWindow>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWScrollView>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer"); MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
MyGUI::ResourceManager::getInstance().load("core.xml"); MyGUI::ResourceManager::getInstance().load("core.xml");