fix menu shortkey underline issue

This commit is contained in:
Jinhao 2016-04-15 20:38:35 +08:00
parent bdd3806aa4
commit 6a5623f098

View File

@ -398,24 +398,28 @@ namespace nana
//Draw text, the text is transformed from orignal for hotkey character //Draw text, the text is transformed from orignal for hotkey character
wchar_t hotkey; wchar_t hotkey;
std::string::size_type hotkey_pos; std::string::size_type hotkey_pos;
auto text = to_wstring(API::transform_shortkey_text(m.text, hotkey, &hotkey_pos)); auto text = API::transform_shortkey_text(m.text, hotkey, &hotkey_pos);
if (m.image.empty() == false) if (m.image.empty() == false)
renderer->item_image(graph, nana::point(item_r.x + 5, item_r.y + static_cast<int>(item_h_px - image_px) / 2 - 1), image_px, m.image); renderer->item_image(graph, nana::point(item_r.x + 5, item_r.y + static_cast<int>(item_h_px - image_px) / 2 - 1), image_px, m.image);
renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), to_utf8(text), strpixels, attr); renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), text, strpixels, attr);
if (hotkey) if (hotkey)
{ {
m.hotkey = hotkey; m.hotkey = hotkey;
if (m.flags.enabled) if (m.flags.enabled)
{ {
unsigned off_w = (hotkey_pos ? graph.text_extent_size(text, static_cast<unsigned>(hotkey_pos)).width : 0); auto off_px = (hotkey_pos ? graph.text_extent_size(text.c_str(), hotkey_pos).width : 0);
nana::size hotkey_size = graph.text_extent_size(text.c_str() + hotkey_pos, 1); auto hotkey_px = graph.text_extent_size(text.c_str() + hotkey_pos, 1).width;
int x = item_r.x + 40 + off_w;
int y = item_r.y + text_top_off + hotkey_size.height;
graph_->line({ x, y }, { x + static_cast<int>(hotkey_size.width) - 1, y }, colors::black); unsigned ascent, descent, inleading;
graph.text_metrics(ascent, descent, inleading);
int x = item_r.x + 40 + off_px;
int y = item_r.y + text_top_off + ascent + 1;
graph_->line({ x, y }, { x + static_cast<int>(hotkey_px)-1, y }, colors::black);
} }
} }
@ -582,9 +586,12 @@ namespace nana
} }
else if(m.flags.enabled) else if(m.flags.enabled)
{ {
std::move(fn_close_tree_)(); fn_close_tree_();
item_proxy ip(index, m); if (m.functor)
m.functor.operator()(ip); {
item_proxy ip(index, m);
m.functor.operator()(ip);
}
return 1; return 1;
} }
} }