listbox auto_width set the column width to fit the current longest text

This commit is contained in:
qPCR4vir
2015-05-07 22:50:26 +02:00
parent 444449dfaa
commit 371633f23f
2 changed files with 27 additions and 7 deletions

View File

@@ -412,7 +412,7 @@ namespace nana
{
m.pixels = width;
return;
}
}
}
unsigned item_width(size_type pos) const
@@ -4008,6 +4008,24 @@ namespace nana
ess.update();
return *this;
}
unsigned listbox::auto_width(size_type pos, unsigned max)
{
unsigned max_w{0};
auto & ess = _m_ess();
for (const auto &cat : ess.lister.cat_container())
for (const auto &it : cat.items )
{
if (pos >= it.cells.size()) continue;
// precalcule text geometry
unsigned ts = static_cast<unsigned> ( ess.graph->text_extent_size(it.cells[pos].text).width);
if (max_w < ts)
max_w = ts;
}
if (!max_w) return 0;
header_width(pos, max_w < max ? max_w : max);
ess.update();
return max_w;
}
unsigned listbox::header_width(size_type pos) const
{