add support of text align to text_editor/textbox

This commit is contained in:
Jinhao 2017-01-25 19:18:54 +08:00
parent 583bdf6199
commit d34806353e
4 changed files with 553 additions and 494 deletions

View File

@ -1,7 +1,7 @@
/* /*
* A text editor implementation * A text editor implementation
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -56,6 +56,8 @@ namespace nana{ namespace widgets
class keyword_parser; class keyword_parser;
class helper_pencil; class helper_pencil;
struct text_section;
text_editor(const text_editor&) = delete; text_editor(const text_editor&) = delete;
text_editor& operator=(const text_editor&) = delete; text_editor& operator=(const text_editor&) = delete;
@ -101,6 +103,8 @@ namespace nana{ namespace widgets
bool load(const char*); bool load(const char*);
void text_align(::nana::align alignment);
/// Sets the text area. /// Sets the text area.
/// @return true if the area is changed with the new value. /// @return true if the area is changed with the new value.
bool text_area(const nana::rectangle&); bool text_area(const nana::rectangle&);
@ -206,8 +210,17 @@ namespace nana{ namespace widgets
skeletons::textbase<char_type>& textbase(); skeletons::textbase<char_type>& textbase();
const skeletons::textbase<char_type>& textbase() const; const skeletons::textbase<char_type>& textbase() const;
private: private:
std::vector<upoint> _m_render_text(const ::nana::color& text_color);
void _m_pre_calc_lines(std::size_t line_off, std::size_t lines); void _m_pre_calc_lines(std::size_t line_off, std::size_t lines);
::nana::point _m_caret_to_screen(::nana::upoint pos) const;
::nana::upoint _m_screen_to_caret(::nana::point pos) const;
bool _m_pos_from_secondary(std::size_t textline, const nana::upoint& secondary, unsigned & pos);
bool _m_pos_secondary(const nana::upoint& charpos, nana::upoint& secondary_pos) const;
bool _m_move_caret_ns(bool to_north);
void _m_update_line(std::size_t pos, std::size_t secondary_count_before);
bool _m_accepts(char_type) const; bool _m_accepts(char_type) const;
::nana::color _m_bgcolor() const; ::nana::color _m_bgcolor() const;
bool _m_scroll_text(bool vertical); bool _m_scroll_text(bool vertical);
@ -233,10 +246,13 @@ namespace nana{ namespace widgets
int _m_text_top_base() const; int _m_text_top_base() const;
/// Returns the logical position that text starts of a specified line in x-axis
int _m_text_x(const text_section&) const;
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const; void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const;
//_m_draw_string //_m_draw_string
//@brief: Draw a line of string //@brief: Draw a line of string
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const ::std::wstring&, bool if_mask) const; void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const text_section&, bool if_mask) const;
//_m_update_caret_line //_m_update_caret_line
//@brief: redraw whole line specified by caret pos. //@brief: redraw whole line specified by caret pos.
//@return: true if caret overs the border //@return: true if caret overs the border
@ -244,7 +260,7 @@ namespace nana{ namespace widgets
void _m_offset_y(int y); void _m_offset_y(int y);
unsigned _m_char_by_pixels(const unicode_bidi::entity&, unsigned pos); unsigned _m_char_by_pixels(const unicode_bidi::entity&, unsigned pos) const;
unsigned _m_pixels_by_char(const ::std::wstring&, ::std::size_t pos) const; unsigned _m_pixels_by_char(const ::std::wstring&, ::std::size_t pos) const;
void _m_handle_move_key(const arg_keyboard& arg); void _m_handle_move_key(const arg_keyboard& arg);
@ -265,6 +281,8 @@ namespace nana{ namespace widgets
{ {
::std::string tip_string; ::std::string tip_string;
::nana::align alignment{ ::nana::align::left };
bool line_wrapped{false}; bool line_wrapped{false};
bool multi_lines{true}; bool multi_lines{true};
bool editable{true}; bool editable{true};

View File

@ -1,7 +1,7 @@
/** /**
* A Textbox Implementation * A Textbox Implementation
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -227,6 +227,9 @@ namespace nana
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8); void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
void erase_keyword(const std::string& kw); void erase_keyword(const std::string& kw);
/// Sets the text alignment
textbox& text_align(::nana::align alignment);
/// Returns the text position of each line that currently displays on screen. /// Returns the text position of each line that currently displays on screen.
text_positions text_position() const; text_positions text_position() const;

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/* /*
* A Textbox Implementation * A Textbox Implementation
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -619,6 +619,19 @@ namespace drawerbase {
editor->erase_keyword(to_wstring(kw)); editor->erase_keyword(to_wstring(kw));
} }
textbox& textbox::text_align(::nana::align alignment)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if (editor)
{
editor->text_align(alignment);
API::update_window(this->handle());
}
return *this;
}
std::vector<upoint> textbox::text_position() const std::vector<upoint> textbox::text_position() const
{ {
internal_scope_guard lock; internal_scope_guard lock;