Skip to content
Snippets Groups Projects
Commit ffd4aee7 authored by Joakim Hunskaar's avatar Joakim Hunskaar
Browse files

added getText to TextBox

parent 1e6b4bbb
No related branches found
No related tags found
1 merge request!10More button widgets
...@@ -12,7 +12,7 @@ namespace TDT4102 { ...@@ -12,7 +12,7 @@ namespace TDT4102 {
class TextBox : public TDT4102::Widget { class TextBox : public TDT4102::Widget {
private: private:
std::string text; std::string contents;
nk_color textColor = nk_rgba(175, 175, 175, 255); nk_color textColor = nk_rgba(175, 175, 175, 255);
nk_color boxColor = nk_rgba(50 , 50, 50, 255); nk_color boxColor = nk_rgba(50 , 50, 50, 255);
nk_color borderColor = nk_rgba(50, 50, 50, 255); nk_color borderColor = nk_rgba(50, 50, 50, 255);
...@@ -20,6 +20,7 @@ namespace TDT4102 { ...@@ -20,6 +20,7 @@ namespace TDT4102 {
void update(nk_context* context) override; void update(nk_context* context) override;
public: public:
explicit TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = ""); explicit TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = "");
std::string getText() const;
void setText(std::string updatedText); void setText(std::string updatedText);
void setTextColor(TDT4102::Color newColor) {textColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} void setTextColor(TDT4102::Color newColor) {textColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
void setBoxColor(TDT4102::Color newColor) {boxColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} void setBoxColor(TDT4102::Color newColor) {boxColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
......
...@@ -5,7 +5,7 @@ void TDT4102::TextBox::update(nk_context *context) { ...@@ -5,7 +5,7 @@ void TDT4102::TextBox::update(nk_context *context) {
nk_style_push_color(context, &s->edit.text_normal, textColor); nk_style_push_color(context, &s->edit.text_normal, textColor);
nk_style_push_color(context, &s->edit.border_color, borderColor); nk_style_push_color(context, &s->edit.border_color, borderColor);
nk_style_push_style_item(context, &s->edit.normal, nk_style_item_color(boxColor)); nk_style_push_style_item(context, &s->edit.normal, nk_style_item_color(boxColor));
nk_edit_string_zero_terminated(context, NK_EDIT_READ_ONLY, const_cast<char*>(text.data()), internal::TEXT_BOX_CHARACTER_LIMIT, nk_filter_ascii); nk_edit_string_zero_terminated(context, NK_EDIT_READ_ONLY, const_cast<char*>(contents.data()), internal::TEXT_BOX_CHARACTER_LIMIT, nk_filter_ascii);
nk_style_pop_color(context); nk_style_pop_color(context);
nk_style_pop_color(context); nk_style_pop_color(context);
nk_style_pop_style_item(context); nk_style_pop_style_item(context);
...@@ -13,13 +13,17 @@ void TDT4102::TextBox::update(nk_context *context) { ...@@ -13,13 +13,17 @@ void TDT4102::TextBox::update(nk_context *context) {
TDT4102::TextBox::TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText) TDT4102::TextBox::TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText)
: TDT4102::Widget(location, width, height) { : TDT4102::Widget(location, width, height) {
text = initialText; contents = initialText;
text.resize(internal::TEXT_BOX_CHARACTER_LIMIT); contents.resize(internal::TEXT_BOX_CHARACTER_LIMIT);
} }
std::string TDT4102::TextBox::getText() const {
return std::string(contents.data());;
}
void TDT4102::TextBox::setText(std::string updatedText) { void TDT4102::TextBox::setText(std::string updatedText) {
text = updatedText; contents = updatedText;
text.resize(internal::TEXT_BOX_CHARACTER_LIMIT); contents.resize(internal::TEXT_BOX_CHARACTER_LIMIT);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment