fix bug that listbox fit_content may not work

This commit is contained in:
Jinhao 2018-06-20 00:40:22 +08:00
parent 094830b8a7
commit b5a9374f8f

View File

@ -2757,6 +2757,17 @@ namespace nana
unsigned es_lister::column_content_pixels(size_type pos) const
{
unsigned max_px = 0;
std::unique_ptr<paint::graphics> 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();
}
for (auto & cat : categories_)
{
for (std::size_t i = 0; i < cat.items.size(); ++i)
@ -2768,14 +2779,14 @@ namespace nana
if (pos >= model_cells.size())
continue;
content_px = ess_->graph->text_extent_size(model_cells[pos].text).width;
content_px = graph->text_extent_size(model_cells[pos].text).width;
}
else
{
if (pos >= cat.items[i].cells->size())
continue;
content_px = ess_->graph->text_extent_size((*cat.items[i].cells)[pos].text).width;
content_px = graph->text_extent_size((*cat.items[i].cells)[pos].text).width;
}
if (content_px > max_px)