std::string_view

This commit is contained in:
Jinhao
2018-06-09 01:21:10 +08:00
parent ffee0e5a3b
commit fc7743cbe2
8 changed files with 263 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
/*
* A Button Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -262,7 +262,11 @@ namespace nana{ namespace drawerbase
if (attr_.omitted)
tr.render(pos, txtptr, txtlen, omitted_pixels, true);
else
#ifdef _nana_std_has_string_view
graph.bidi_string(pos, { txtptr, txtlen });
#else
graph.bidi_string(pos, txtptr, txtlen);
#endif
API::dev::draw_shortkey_underline(graph, mbstr, shortkey, shortkey_pos, pos, text_color);
}
@@ -277,9 +281,15 @@ namespace nana{ namespace drawerbase
}
else
{
#ifdef _nana_std_has_string_view
graph.bidi_string(point{ pos.x + 1, pos.y + 1 }, { txtptr, txtlen });
graph.palette(true, color{ colors::gray });
graph.bidi_string(pos, { txtptr, txtlen });
#else
graph.bidi_string(point{ pos.x + 1, pos.y + 1 }, txtptr, txtlen);
graph.palette(true, color{ colors::gray });
graph.bidi_string(pos, txtptr, txtlen);
#endif
}
}
}

View File

@@ -1,7 +1,7 @@
/*
* A Label Control Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-208 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -564,6 +564,16 @@ namespace nana
_m_change_font(graph, fblock_ptr);
#ifdef _nana_std_has_string_view
std::wstring_view text_sv{ data_ptr->text() };
if (text_range.second != text_sv.size())
{
text_sv = text_sv.substr(text_range.first, text_range.second);
sz = graph.text_extent_size(text_sv);
}
graph.string({ rs.pos.x, y }, text_sv, _m_fgcolor(fblock_ptr));
#else
if (text_range.second == data_ptr->text().length())
{
graph.string({ rs.pos.x, y }, data_ptr->text(), _m_fgcolor(fblock_ptr));
@@ -575,6 +585,7 @@ namespace nana
graph.string({ rs.pos.x, y }, str, _m_fgcolor(fblock_ptr));
}
#endif
_m_insert_if_traceable(rs.pos.x, y, sz, fblock_ptr);

View File

@@ -3309,8 +3309,12 @@ namespace nana{ namespace widgets
void text_editor::_m_draw_parse_string(const keyword_parser& parser, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t* str, std::size_t len) const
{
#ifdef _nana_std_has_string_view
graph_.string(pos, { str, len }, fgcolor);
#else
graph_.palette(true, fgcolor);
graph_.string(pos, str, len);
#endif
if (parser.entities().empty())
return;
@@ -3359,7 +3363,20 @@ namespace nana{ namespace widgets
ent_pos.x = pos.x + ent_off;
#ifdef _nana_std_has_string_view
std::wstring_view ent_sv;
if (rtl)
{
//draw the whole text if it is a RTL text, because Arbic language is transformable.
ent_sv = { str, len };
}
else
{
ent_sv = { ent_begin, static_cast<std::wstring_view::size_type>(ent_end - ent_begin) };
ent_off = 0;
}
canvas.string({}, ent_sv);
#else
if (rtl)
{
//draw the whole text if it is a RTL text, because Arbic language is transformable.
@@ -3370,6 +3387,7 @@ namespace nana{ namespace widgets
canvas.string({}, ent_begin, ent_end - ent_begin);
ent_off = 0;
}
#endif
graph_.bitblt(rectangle{ ent_pos, size{ ent_pixels, canvas.height() } }, canvas, point{ ent_off, 0 });
}
}
@@ -3395,12 +3413,19 @@ namespace nana{ namespace widgets
void write_selection(const point& text_pos, unsigned text_px, const wchar_t* text, std::size_t len, bool has_focused)
{
#ifdef _nana_std_has_string_view
graph_.rectangle(::nana::rectangle{ text_pos,{ text_px, line_px_ } }, true,
selection_color(false, has_focused));
graph_.string(text_pos, { text, len }, selection_color(true, has_focused));
#else
graph_.palette(true, selection_color(true, has_focused));
graph_.rectangle(::nana::rectangle{ text_pos, { text_px, line_px_ } }, true,
selection_color(false, has_focused));
graph_.string(text_pos, text, len);
#endif
}
void rtl_string(point strpos, const wchar_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected, bool has_focused)
@@ -3414,9 +3439,12 @@ namespace nana{ namespace widgets
int sel_xpos = static_cast<int>(str_px - (glyph_front + glyph_selected));
#ifdef _nana_std_has_string_view
graph.string({ -sel_xpos, 0 }, { str, len }, selection_color(true, has_focused));
#else
graph.palette(true, selection_color(true, has_focused));
graph.string({ -sel_xpos, 0 }, str, len);
#endif
graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_px_), graph);
};
private:
@@ -3646,11 +3674,11 @@ namespace nana{ namespace widgets
unsigned text_editor::_m_char_by_pixels(const unicode_bidi::entity& ent, unsigned pos) const
{
auto len = static_cast<std::size_t>(ent.end - ent.begin);
std::unique_ptr<unsigned[]> pxbuf(new unsigned[len]);
#ifdef _nana_std_has_string_view
if (graph_.glyph_pixels({ent.begin, len}, pxbuf.get()))
auto pxbuf = graph_.glyph_pixels({ ent.begin, len });
if (pxbuf)
#else
std::unique_ptr<unsigned[]> pxbuf(new unsigned[len]);
if (graph_.glyph_pixels(ent.begin, len, pxbuf.get()))
#endif
{
@@ -3710,10 +3738,10 @@ namespace nana{ namespace widgets
{
//Characters of some bidi languages may transform in a word.
//RTL
std::unique_ptr<unsigned[]> pxbuf(new unsigned[len]);
#ifdef _nana_std_has_string_view
graph_.glyph_pixels({ent.begin, len}, pxbuf.get());
auto pxbuf = graph_.glyph_pixels({ent.begin, len});
#else
std::unique_ptr<unsigned[]> pxbuf(new unsigned[len]);
graph_.glyph_pixels(ent.begin, len, pxbuf.get());
#endif
return std::accumulate(pxbuf.get() + (target - ent.begin), pxbuf.get() + len, text_w);

View File

@@ -1,6 +1,6 @@
/*
* A Tabbar Implementation
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -1489,7 +1489,12 @@ namespace nana
}
graph.rectangle(r, true);
#ifdef _nana_std_has_string_view
graph.bidi_string({ m.pos_ends.first + 5, 0 }, m.text);
#else
graph.bidi_string({ m.pos_ends.first + 5, 0 }, m.text.data(), m.text.size());
#endif
++pos;
}