13 #ifndef EMP_WEB_TEXT_AREA_H 14 #define EMP_WEB_TEXT_AREA_H 42 std::function<void(const std::string &)>
callback;
49 if (callback_id) emp::JSDelete(callback_id);
52 std::string
TypeName()
const override {
return "TextAreaInfo"; }
61 virtual void GetHTML(std::stringstream & HTML)
override {
64 if (disabled) { HTML <<
" disabled=true"; }
65 HTML <<
" id=\"" <<
id <<
"\"";
66 HTML <<
" onkeyup=\"emp.Callback(" << callback_id <<
", $(this).val())\"";
67 HTML <<
" rows=\"" << rows <<
"\"" 68 <<
" cols=\"" << cols <<
"\"";
69 if (max_length >= 0) { HTML <<
" maxlength=\"" << max_length <<
"\""; }
70 HTML <<
">" << cur_text <<
"</textarea>";
78 void UpdateCallback(
const std::function<
void(
const std::string &)> & in_cb) {
89 var
id = Pointer_stringify($0);
90 var text = Pointer_stringify($1);
91 $(
'#' +
id).val(text);
92 },
id.c_str(), in_string.c_str());
96 virtual std::string
GetType()
override {
return "web::TextAreaInfo"; }
122 [ta_info](std::string in_str){ ta_info->
DoCallback(in_str); }
127 TextArea(std::function<
void(
const std::string &)> in_cb,
const std::string & in_id=
"")
virtual ~TextAreaInfo()
Definition: TextArea.h:48
TextAreaInfo & operator=(const TextAreaInfo &)=delete
TextArea & SetText(const std::string &in_text)
Set the text contained in the text area.
Definition: TextArea.h:156
TextArea(const Widget &in)
Definition: TextArea.h:135
int cols
How many columns of text in the area?
Definition: TextArea.h:33
Definition: TextArea.h:30
void UpdateAutofocus(bool in_af)
Definition: TextArea.h:73
TextArea(const std::string &in_id="")
Build a text area with a specified HTML identifier.
Definition: TextArea.h:108
bool disabled
Should this TextArea be disabled?
Definition: TextArea.h:40
bool HasAutofocus() const
Does this widget have auto focus set?
Definition: TextArea.h:163
int max_length
Maximum number of total characters allowed.
Definition: TextArea.h:35
int rows
How many rows of text in the area?
Definition: TextArea.h:34
virtual void GetHTML(std::stringstream &HTML) override
Definition: TextArea.h:61
void DoCallback(std::string in_text)
Definition: TextArea.h:55
TextArea(const TextArea &in)
Connect to an existing TextArea.
Definition: TextArea.h:134
TextArea(std::function< void(const std::string &)> in_cb, const std::string &in_id="")
Build a text area with a specified function to call with every change.
Definition: TextArea.h:127
TextAreaInfo * Info()
Definition: TextArea.h:101
const std::string & GetText() const
Get the current text in this TextArea.
Definition: TextArea.h:141
TextArea & SetAutofocus(bool in_af)
Make this text area have focus by default.
Definition: TextArea.h:144
const TextAreaInfo * Info() const
Definition: TextArea.h:102
std::string TypeName() const override
Debugging helpers...
Definition: TextArea.h:52
Definition: TextArea.h:25
void UpdateText(const std::string &in_string)
Definition: TextArea.h:87
void UpdateDisabled(bool in_dis)
Definition: TextArea.h:82
If we are in emscripten, make sure to include the header.
Definition: array.h:37
virtual bool IsTextAreaInfo() const override
Definition: TextArea.h:53
TextArea & SetDisabled(bool in_dis)
Gray out this text area.
Definition: TextArea.h:153
#define emp_assert(...)
Definition: assert.h:199
virtual ~TextArea()
Definition: TextArea.h:136
virtual std::string GetType() override
Definition: TextArea.h:96
TextArea(TextAreaInfo *in_info)
Definition: TextArea.h:104
TextAreaInfo(const std::string &in_id="")
Definition: TextArea.h:45
std::string cur_text
Text that should currently be in the box.
Definition: TextArea.h:37
uint32_t callback_id
Callback ID the built-in function for this text area.
Definition: TextArea.h:43
void UpdateCallback(const std::function< void(const std::string &)> &in_cb)
Definition: TextArea.h:78
bool autofocus
Should this TextArea be set as Autofocus?
Definition: TextArea.h:39
std::function< void(const std::string &)> callback
Function to call with each keypress.
Definition: TextArea.h:42
bool IsDisabled() const
Is this widget currently disabled?
Definition: TextArea.h:166
TextArea & SetCallback(const std::function< void(const std::string &)> &in_cb)
Change the callback function for this TextArea.
Definition: TextArea.h:147