From fb8ade6557f432c6172845783e4f500cfeefdc51 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 31 Jan 2019 07:08:45 +0800 Subject: [PATCH] some modifications to #357 and #383 --- include/nana/gui/widgets/detail/compset.hpp | 8 +++-- include/nana/gui/widgets/treebox.hpp | 2 +- source/gui/widgets/listbox.cpp | 5 ++- source/gui/widgets/treebox.cpp | 37 ++++++++++++++------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/include/nana/gui/widgets/detail/compset.hpp b/include/nana/gui/widgets/detail/compset.hpp index 3991fe4e..8518b85c 100644 --- a/include/nana/gui/widgets/detail/compset.hpp +++ b/include/nana/gui/widgets/detail/compset.hpp @@ -1,6 +1,6 @@ /* * Concept of Component Set - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -60,17 +60,19 @@ namespace nana{ namespace widgets{ namespace detail /// Widget scheme. typedef WidgetScheme widget_scheme_t; - widget_scheme_t * wdg_scheme_ptr_{ nullptr }; + //widget_scheme_t * wdg_scheme_ptr_{ nullptr }; //deprecated public: /// The destructor. virtual ~compset_placer(){} + /* /// Init the scheme pointer - void init_scheme(widget_scheme_t* wdg_scheme_ptr) + void init_scheme(widget_scheme_t* wdg_scheme_ptr) //deprecated { wdg_scheme_ptr_ = wdg_scheme_ptr; } + */ /// Enable/Disable the specified component. virtual void enable(component_t, bool) = 0; diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index 4ff78e99..0d78bbde 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -1,7 +1,7 @@ /** * A Tree Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE or copy at diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 4b902c43..895b2829 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -6195,8 +6195,9 @@ namespace nana return; std::vector new_idx; for(size_type i=first_col; i<=last_col; ++i) new_idx.push_back(i); - const item_proxy & ip_row=this->at(row); + internal_scope_guard lock; + const item_proxy ip_row = this->at(row); const nana::any *pnany=_m_ess().lister.anyobj(row,false); std::sort(new_idx.begin(), new_idx.end(), [&](size_type col1, size_type col2) @@ -6205,6 +6206,8 @@ namespace nana ip_row.text(col2), col2, pnany, reverse); }); + + //Only change the view position of columns for(size_t i=0; icrook_size : 0), (enable_icon_ ? wdg_scheme_ptr_->icon_size : 0)); + auto m = std::max((enable_crook_ ? scheme_.crook_size : 0), (enable_icon_ ? scheme_.icon_size : 0)); + +#if 1 + unsigned as = 0, ds = 0, il; + graph.text_metrics(as, ds, il); + return std::max(as + ds + 8, m); +#else #ifdef _nana_std_has_string_view return std::max(m, graph.text_extent_size(std::wstring_view{ L"jH{", 3 }).height + 8); #else return std::max(m, graph.text_extent_size(L"jH{", 3).height + 8); +#endif #endif } virtual unsigned item_width(graph_reference graph, const item_attribute_t& attr) const override { - return graph.text_extent_size(attr.text).width + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0) + (enable_icon_ ? wdg_scheme_ptr_ ->icon_size: 0) + (wdg_scheme_ptr_->text_offset << 1) + wdg_scheme_ptr_->item_offset; + return graph.text_extent_size(attr.text).width + (enable_crook_ ? scheme_.crook_size : 0) + (enable_icon_ ? scheme_.icon_size : 0) + (scheme_.text_offset << 1) + scheme_.item_offset; } // Locate a component through the specified coordinate. @@ -1389,7 +1400,7 @@ namespace nana case component_t::expander: if(attr.has_children) { - r->width = wdg_scheme_ptr_->item_offset; + r->width = scheme_.item_offset; return true; } return false; @@ -1398,26 +1409,26 @@ namespace nana case component_t::crook: if(enable_crook_) { - r->x += wdg_scheme_ptr_->item_offset; - r->width = wdg_scheme_ptr_->crook_size; + r->x += scheme_.item_offset; + r->width = scheme_.crook_size; return true; } return false; case component_t::icon: if(enable_icon_) { - r->x += wdg_scheme_ptr_->item_offset + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0); + r->x += scheme_.item_offset + (enable_crook_ ? scheme_.crook_size : 0); r->y = 2; - r->width = wdg_scheme_ptr_->icon_size; + r->width = scheme_.icon_size; r->height -= 2; return true; } return false; case component_t::text: { - auto text_pos = wdg_scheme_ptr_->item_offset + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0) + (enable_icon_ ? wdg_scheme_ptr_->icon_size : 0) + wdg_scheme_ptr_->text_offset; + auto text_pos = scheme_.item_offset + (enable_crook_ ? scheme_.crook_size : 0) + (enable_icon_ ? scheme_.icon_size : 0) + scheme_.text_offset; r->x += text_pos; - r->width -= (text_pos + wdg_scheme_ptr_->text_offset); + r->width -= (text_pos + scheme_.text_offset); }; return true; default: @@ -1426,6 +1437,7 @@ namespace nana return false; } private: + const scheme& scheme_; bool enable_crook_{ false }; bool enable_icon_{ false }; }; @@ -1680,7 +1692,7 @@ namespace nana { impl_->data.trigger_ptr = this; impl_->data.renderer = nana::pat::cloneable(internal_renderer()); - impl_->data.comp_placer = nana::pat::cloneable(internal_placer()); + //impl_->data.comp_placer = nana::pat::cloneable(internal_placer()); //deprecated impl_->adjust.timer.elapse([this] { @@ -1946,7 +1958,8 @@ namespace nana widget.bgcolor(colors::white); impl_->data.widget_ptr = static_cast<::nana::treebox*>(&widget); impl_->data.scheme_ptr = static_cast<::nana::treebox::scheme_type*>(API::dev::get_scheme(widget)); - impl_->data.comp_placer->init_scheme(impl_->data.scheme_ptr); + //impl_->data.comp_placer->init_scheme(impl_->data.scheme_ptr); //deprecated + impl_->data.comp_placer = nana::pat::cloneable(internal_placer{ *impl_->data.scheme_ptr }); widget.caption("nana treebox"); }