diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index c46aa1ca..01c9a9d1 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -17,6 +17,8 @@ #include "skeletons/textbase_export_interface.hpp" #include "skeletons/text_editor_part.hpp" +#include + namespace nana { class textbox; @@ -173,6 +175,13 @@ namespace nana /// Read the text from a specified line with a set offset. It returns true for success. bool getline(std::size_t line_index,std::size_t offset,std::string& text) const; + /// Read the text from a specified line; returns an empty optional on failure + std::optional getline(std::size_t pos) const; + + ///Read the text from a specified line with a set offset. Returns an empty optional for + /// failure. + std::optional getline(std::size_t line_index, std::size_t offset) const; + /// Gets the caret position /// Returns true if the caret is in the area of display, false otherwise. bool caret_pos(point& pos, bool text_coordinate) const; diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index db57ae82..6836c231 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -377,6 +377,27 @@ namespace drawerbase { return false; } + std::optional textbox::getline(std::size_t pos) const + { + auto result = std::string{}; + if ( getline(pos, result) ) + { + return { std::move(result) }; + } + return {}; + } + + std::optional textbox::getline(std::size_t line_index, std::size_t offset) const + { + auto result = std::string{}; + if ( getline(line_index, offset, result) ) + { + return { std::move(result) }; + } + return {}; + } + + /// Gets the caret position bool textbox::caret_pos(point& pos, bool text_coordinate) const {