std::string_view

This commit is contained in:
Jinhao
2018-06-07 03:41:08 +08:00
parent 549b3d4353
commit 3427181405
12 changed files with 251 additions and 44 deletions

View File

@@ -393,8 +393,13 @@ namespace API
{
if (shortkey)
{
#ifdef _nana_std_has_string_view
auto off_x = (shortkey_position ? graph.text_extent_size(std::string_view{ text.c_str(), shortkey_position }).width : 0);
auto key_px = static_cast<int>(graph.text_extent_size(std::wstring_view{ &shortkey, 1 }).width);
#else
auto off_x = (shortkey_position ? graph.text_extent_size(text.c_str(), shortkey_position).width : 0);
auto key_px = static_cast<int>(graph.text_extent_size(&shortkey, 1).width);
#endif
unsigned ascent, descent, inleading;
graph.text_metrics(ascent, descent, inleading);

View File

@@ -78,7 +78,11 @@ namespace nana{ namespace drawerbase
}
//draw crook
#ifdef _nana_std_has_string_view
auto txt_px = graph.text_extent_size(std::wstring_view( L"jN", 2 )).height + 2;
#else
auto txt_px = graph.text_extent_size(L"jN", 2).height + 2;
#endif
impl_->crook.draw(graph, wdg->bgcolor(), wdg->fgcolor(), rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), API::element_state(*wdg));
}

View File

@@ -83,7 +83,11 @@ namespace nana
auto pre_font = graph.typeface(); //used for restoring the font
#ifdef _nana_std_has_string_view
const unsigned def_line_pixels = graph.text_extent_size(std::wstring_view{ L" ", 1 }).height;
#else
const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height;
#endif
font_ = pre_font;
fblock_ = nullptr;
@@ -170,7 +174,11 @@ namespace nana
auto ft = graph.typeface(); //used for restoring the font
#ifdef _nana_std_has_string_view
const unsigned def_line_pixels = graph.text_extent_size(std::wstring_view(L" ", 1)).height;
#else
const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height;
#endif
font_ = ft;
fblock_ = nullptr;

View File

@@ -3147,7 +3147,11 @@ namespace nana{ namespace widgets
maskstr.append(n, mask_char_);
return graph_.text_extent_size(maskstr);
}
#ifdef _nana_std_has_string_view
return graph_.text_extent_size(std::basic_string_view<char_type>(str, n));
#else
return graph_.text_extent_size(str, static_cast<unsigned>(n));
#endif
}
bool text_editor::_m_adjust_view()
@@ -3500,7 +3504,12 @@ namespace nana{ namespace widgets
for (auto & ent : reordered)
{
std::size_t len = ent.end - ent.begin;
#ifdef _nana_std_has_string_view
unsigned str_w = graph_.text_extent_size(std::wstring_view{ ent.begin, len }).width;
#else
unsigned str_w = graph_.text_extent_size(ent.begin, len).width;
#endif
if ((text_draw_pos.x + static_cast<int>(str_w) > text_area_.area.x) && (text_draw_pos.x < text_right))
{
@@ -3519,7 +3528,11 @@ namespace nana{ namespace widgets
for (auto & ent : reordered)
{
const auto len = ent.end - ent.begin;
#ifdef _nana_std_has_string_view
auto ent_px = graph_.text_extent_size(std::wstring_view(ent.begin, len)).width;
#else
auto ent_px = graph_.text_extent_size(ent.begin, len).width;
#endif
extra_space = false;
@@ -3589,7 +3602,11 @@ namespace nana{ namespace widgets
auto pos = text_coord.x + text_len;
if (b.x != pos || text_coord.y != b.y)
{
#ifdef _nana_std_has_string_view
auto whitespace_w = graph_.text_extent_size(std::wstring_view{ L" ", 1 }).width;
#else
auto whitespace_w = graph_.text_extent_size(L" ", 1).width;
#endif
graph_.rectangle(::nana::rectangle{ text_draw_pos, { whitespace_w, line_h_pixels } }, true);
}
}

View File

@@ -1163,7 +1163,11 @@ namespace nana
virtual unsigned item_height(graph_reference graph) const override
{
#ifdef _nana_std_has_string_view
return graph.text_extent_size(std::wstring_view{ L"jH{", 3 }).height + 8;
#else
return graph.text_extent_size(L"jH{", 3).height + 8;
#endif
}
virtual unsigned item_width(graph_reference graph, const item_attribute_t& attr) const override