From 419d615505a9dff81c8ac392adc2de5c890a53ce Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 27 Mar 2020 07:28:48 +0800 Subject: [PATCH] listbox::hovered now returns absolute position fix related issue #528 --- include/nana/gui/widgets/listbox.hpp | 12 +++++++++++- source/gui/widgets/listbox.cpp | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index cd2da24b..4856a7f3 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1,7 +1,7 @@ /** * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -1511,8 +1511,18 @@ the nana::detail::basic_window member pointer scheme /// Returns the index pair of the item which contains the specified "screen" point. index_pair cast(const point & screen_pos) const; + /// Converts the index between absolute position and display position + /** + * @param idx The index to be converted + * @param from_display_order If this parameter is true, the method converts a display position to an absolute position. + * If the parameter is false, the method converts an absolute position to a display position. + * @return a display position or an absolute position that are depending on from_display_order. + */ + index_pair index_cast(index_pair idx, bool from_display_order) const; + /// Returns the item which is hovered /** + * The item position is an absolute position. * @param return_end Indicates whether to return an end position instead of an empty position if no item is hovered. * @return The position of the hovered item. If return_end is true and no item is hovered it returns the position next to the last item of last category. */ diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index d9561985..2464b3d7 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1,7 +1,7 @@ /* * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -5736,6 +5736,14 @@ namespace nana return index_pair{ npos, npos }; } + listbox::index_pair listbox::index_cast(index_pair idx, bool from_display_order) const + { + internal_scope_guard lock; + + idx.item = at(idx.cat).index_cast(idx.item, from_display_order); + return idx; + } + listbox::index_pair listbox::hovered(bool return_end) const { using parts = drawerbase::listbox::essence::parts; @@ -5755,9 +5763,11 @@ namespace nana if (0 < pos.cat) --pos.cat; pos.item = this->size_item(pos.cat); - } - return pos; + return pos; + } + + return index_cast(pos, true); } else if (return_end) return index_pair{ this->size_categ() - 1, this->size_item(this->size_categ() - 1) };