add textbox::content_origin

This commit is contained in:
Jinhao 2017-07-25 07:57:48 +08:00
parent d5c01b3dd1
commit 27e1d7aff5
4 changed files with 20 additions and 1 deletions

View File

@ -86,6 +86,7 @@ namespace nana{ namespace widgets
~text_editor(); ~text_editor();
size caret_size() const; size caret_size() const;
const point& content_origin() const;
void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&); void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&);
void erase_highlight(const ::std::string& name); void erase_highlight(const ::std::string& name);

View File

@ -140,6 +140,8 @@ namespace nana
colored_area_access_interface* colored_area_access(); colored_area_access_interface* colored_area_access();
point content_origin() const;
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter. /// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line. /// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
textbox& indention(bool, std::function<std::string()> generator = {}); textbox& indention(bool, std::function<std::string()> generator = {});

View File

@ -497,6 +497,7 @@ namespace nana{ namespace widgets
undoable<command> undo; //undo command undoable<command> undo; //undo command
renderers customized_renderers; renderers customized_renderers;
std::vector<upoint> text_position; //positions of text since last rendering. std::vector<upoint> text_position; //positions of text since last rendering.
int text_position_origin{ -1 }; //origin when last text_exposed
skeletons::textbase<wchar_t> textbase; skeletons::textbase<wchar_t> textbase;
@ -1083,6 +1084,11 @@ namespace nana{ namespace widgets
return { 1, line_height() }; return { 1, line_height() };
} }
const point& text_editor::content_origin() const
{
return impl_->cview->origin();
}
void text_editor::set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor) void text_editor::set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor)
{ {
if (fgcolor.invisible() && bgcolor.invisible()) if (fgcolor.invisible() && bgcolor.invisible())
@ -1982,8 +1988,9 @@ namespace nana{ namespace widgets
if (text_pos.empty()) if (text_pos.empty())
text_pos.emplace_back(upoint{}); text_pos.emplace_back(upoint{});
if (text_pos != impl_->text_position) if ((impl_->text_position_origin != impl_->cview->origin().y) || (text_pos != impl_->text_position))
{ {
impl_->text_position_origin = impl_->cview->origin().y;
impl_->text_position.swap(text_pos); impl_->text_position.swap(text_pos);
if (event_handler_) if (event_handler_)
event_handler_->text_exposed(impl_->text_position); event_handler_->text_exposed(impl_->text_position);

View File

@ -269,6 +269,15 @@ namespace drawerbase {
return nullptr; return nullptr;
} }
point textbox::content_origin() const
{
auto editor = get_drawer_trigger().editor();
if (editor)
return editor->content_origin();
return{};
}
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter. /// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line. /// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
textbox& textbox::indention(bool enb, std::function<std::string()> generator) textbox& textbox::indention(bool enb, std::function<std::string()> generator)