From 27e1d7aff5ee26da0109d868cac63367b5601562 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 25 Jul 2017 07:57:48 +0800 Subject: [PATCH] add textbox::content_origin --- include/nana/gui/widgets/skeletons/text_editor.hpp | 1 + include/nana/gui/widgets/textbox.hpp | 2 ++ source/gui/widgets/skeletons/text_editor.cpp | 9 ++++++++- source/gui/widgets/textbox.cpp | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 9e91712c..a2ab3ea7 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -86,6 +86,7 @@ namespace nana{ namespace widgets ~text_editor(); size caret_size() const; + const point& content_origin() const; void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&); void erase_highlight(const ::std::string& name); diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index ad4a1b2f..d0ac2f67 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -140,6 +140,8 @@ namespace nana 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. /// @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 generator = {}); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index e48498d0..2d2e17e2 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -497,6 +497,7 @@ namespace nana{ namespace widgets undoable undo; //undo command renderers customized_renderers; std::vector text_position; //positions of text since last rendering. + int text_position_origin{ -1 }; //origin when last text_exposed skeletons::textbase textbase; @@ -1083,6 +1084,11 @@ namespace nana{ namespace widgets 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) { if (fgcolor.invisible() && bgcolor.invisible()) @@ -1982,8 +1988,9 @@ namespace nana{ namespace widgets if (text_pos.empty()) 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); if (event_handler_) event_handler_->text_exposed(impl_->text_position); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 3366d84b..e29b0d88 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -269,6 +269,15 @@ namespace drawerbase { 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. /// @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 generator)