Experimental MP lobby: scroll to selected game less often
The lobby calls tlistbox::set_row_shown() every single time there is *any* change in the gamelist. Most of the time, the visibility of rows hasn't even changed. Tlistbox::set_row_shown() calls content_resize_request() to determine if twindow::invalidate_layout() needs to be called. Content_resize_request() unconditionally calls show_content_rect() that checks if the selected item is visible and scrolls to it if it isn't. With this commit, set_row_shown() returns early if visibility of rows hasn't changed. This reduces the frequency of scrolling. This commit isn't a complete fix, since the selected game will still come into view when, for example, a new game is created. However, at least this improves the situation.
This commit is contained in:
parent
722600a313
commit
667064a8af
2 changed files with 19 additions and 0 deletions
|
@ -18,6 +18,8 @@
|
||||||
#include "widget.hpp"
|
#include "widget.hpp"
|
||||||
#include "tstring.hpp"
|
#include "tstring.hpp"
|
||||||
|
|
||||||
|
#include <boost/dynamic_bitset.hpp>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
typedef std::map<std::string, t_string> string_map;
|
typedef std::map<std::string, t_string> string_map;
|
||||||
|
@ -117,6 +119,17 @@ public:
|
||||||
/** Returns whether the item is shown. */
|
/** Returns whether the item is shown. */
|
||||||
virtual bool get_item_shown(const unsigned index) const = 0;
|
virtual bool get_item_shown(const unsigned index) const = 0;
|
||||||
|
|
||||||
|
/** Returns the visibility of all the items as a bit set. */
|
||||||
|
boost::dynamic_bitset<> get_items_shown()
|
||||||
|
{
|
||||||
|
boost::dynamic_bitset<> items_shown(get_item_count());
|
||||||
|
for (unsigned int i = 0u; i < get_item_count(); ++i)
|
||||||
|
{
|
||||||
|
items_shown[i] = get_item_shown(i);
|
||||||
|
}
|
||||||
|
return items_shown;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the number of items. */
|
/** Returns the number of items. */
|
||||||
virtual unsigned get_item_count() const = 0;
|
virtual unsigned get_item_count() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,12 @@ void tlistbox::set_row_shown(const boost::dynamic_bitset<>& shown)
|
||||||
assert(generator_);
|
assert(generator_);
|
||||||
assert(shown.size() == get_item_count());
|
assert(shown.size() == get_item_count());
|
||||||
|
|
||||||
|
if (generator_->get_items_shown() == shown)
|
||||||
|
{
|
||||||
|
LOG_GUI_G << LOG_HEADER << " returning early" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
twindow* window = get_window();
|
twindow* window = get_window();
|
||||||
assert(window);
|
assert(window);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue