From 74f42f1778404cf1658d102cafd57bfa6d504a28 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Mon, 9 Sep 2019 19:53:03 +0200 Subject: [PATCH] new feature "fit_width_to_header caption text" for a new header with width=0 (cherry picked from commit 23efa5088d742a48e7ad07f273e84bcf50c2d979) --- source/gui/widgets/listbox.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 41347095..0e72f7db 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -167,7 +167,7 @@ namespace nana column(column&& other): caption(std::move(other.caption)), - width_px(other.width_px), + width_px(other.width_px), range_width_px(other.range_width_px), visible_state(other.visible_state), index(other.index), @@ -184,7 +184,13 @@ namespace nana index(pos), ess_(ess) { + if (px == 0) + { + fit_width_to_header(); + } } + + void fit_width_to_header(); private: /// The definition is provided after essence void _m_refresh() noexcept; @@ -2881,6 +2887,23 @@ namespace nana return max_px; } + void es_header::column::fit_width_to_header() + { + std::cout<< "Column: " << to_utf8(caption) ; + std::unique_ptr graph_helper; + auto graph = ess_->graph; + if (graph->empty()) + { + //Creates a helper if widget graph is empty(when its size is 0). + graph_helper.reset(new paint::graphics{ nana::size{ 5, 5 } }); + graph_helper->typeface(ess_->graph->typeface()); + graph = graph_helper.get(); + } + width_px = ess_->scheme_ptr->text_margin * 2; //margin at left/right end. + + width_px += graph->text_extent_size(caption).width; + } + //es_header::column member functions void es_header::column::_m_refresh() noexcept {