fix bug that listbox incorrect scrolls if content is sorted(#245)

This commit is contained in:
Jinhao 2017-08-24 05:49:19 +08:00
parent 1be4b4e667
commit 4e18d81f90
2 changed files with 11 additions and 9 deletions

View File

@ -1403,7 +1403,9 @@ the nana::detail::basic_window member pointer scheme
/// Scrolls the view to the first or last item of a specified category
void scroll(bool to_bottom, size_type cat_pos = ::nana::npos);
void scroll(bool to_bottom, const index_pair& pos);
/// Scrolls the view to show an item sepcified by absolute position at top/bottom of the listbox.
void scroll(bool to_bottom, const index_pair& abs_pos);
/// Appends a new column with a header text and the specified width at the end, and return it position
size_type append_header(std::string text_utf8, unsigned width = 120);

View File

@ -963,7 +963,7 @@ namespace nana
return prstatus;
}
void scroll(const index_pair& pos, bool to_bottom);
void scroll(const index_pair& abs_pos, bool to_bottom);
/// Append a new category with a specified name and return a pointer to it.
category_t* create_cat(native_string_type&& text)
@ -2840,16 +2840,16 @@ namespace nana
std::vector<std::pair<index_type, inline_pane*>> panes_;
};
void es_lister::scroll(const index_pair& pos, bool to_bottom)
void es_lister::scroll(const index_pair& abs_pos, bool to_bottom)
{
auto& cat = *get(pos.cat);
auto& cat = *get(abs_pos.cat);
if ((pos.item != nana::npos) && (pos.item >= cat.items.size()))
if ((abs_pos.item != nana::npos) && (abs_pos.item >= cat.items.size()))
throw std::invalid_argument("listbox: invalid pos to scroll");
if (!cat.expand)
{
this->expand(pos.cat, true);
this->expand(abs_pos.cat, true);
ess_->calc_content_size();
}
else if (!ess_->auto_draw)
@ -2862,7 +2862,7 @@ namespace nana
auto origin = ess_->content_view->origin();
origin.y = 0;
auto off = this->distance(this->first(), pos) * ess_->item_height();
auto off = this->distance(this->first(), this->index_cast(abs_pos, false)) * ess_->item_height();
auto screen_px = ess_->content_view->view_area().height;
@ -5222,9 +5222,9 @@ namespace nana
ess.update();
}
void listbox::scroll(bool to_bottom, const index_pair& pos)
void listbox::scroll(bool to_bottom, const index_pair& abs_pos)
{
_m_ess().lister.scroll(pos, to_bottom);
_m_ess().lister.scroll(abs_pos, to_bottom);
_m_ess().update();
}