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

added colors to textinput

parent bc564132
No related branches found
No related tags found
1 merge request!14added colors to textinput
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "Widget.h" #include "Widget.h"
#include "Point.h" #include "Point.h"
#include "Color.h"
#include <string> #include <string>
namespace TDT4102 { namespace TDT4102 {
...@@ -13,11 +14,21 @@ namespace TDT4102 { ...@@ -13,11 +14,21 @@ namespace TDT4102 {
private: private:
std::string contents; std::string contents;
std::string previousContents; std::string previousContents;
nk_color textColor = nk_rgba(175, 175, 175, 255);
nk_color boxColor = nk_rgba(50 , 50, 50, 255);
nk_color boxColorHover = nk_rgba(50 , 50, 50, 255);
nk_color boxColorActive = nk_rgba(50 , 50, 50, 255);
nk_color borderColor = nk_rgba(50, 50, 50, 255);
protected: protected:
void update(nk_context* context) override; void update(nk_context* context) override;
public: public:
explicit TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = ""); explicit TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = "");
std::string getText() const; std::string getText() const;
void setText(std::string text); void setText(std::string text);
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 setBoxColorHover(Color newColor) {boxColorHover = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
void setBoxColorActive(Color newColor) {boxColorActive = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
void setBorderColor(TDT4102::Color newColor) {borderColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
}; };
} }
\ No newline at end of file
#include "widgets/TextInput.h" #include "widgets/TextInput.h"
void TDT4102::TextInput::update(nk_context *context) { void TDT4102::TextInput::update(nk_context *context) {
struct nk_style* s = &context->style;
nk_style_push_color(context, &s->edit.text_normal, textColor);
nk_style_push_color(context, &s->edit.text_hover, textColor);
nk_style_push_color(context, &s->edit.text_active, textColor);
nk_style_push_style_item(context, &s->edit.normal, nk_style_item_color(boxColor));
nk_style_push_style_item(context, &s->edit.hover, nk_style_item_color(boxColorHover));
nk_style_push_style_item(context, &s->edit.active, nk_style_item_color(boxColorActive));
nk_edit_string_zero_terminated(context, NK_EDIT_SELECTABLE | NK_EDIT_ALWAYS_INSERT_MODE | NK_EDIT_BOX | NK_EDIT_SIMPLE, const_cast<char*>(contents.data()), internal::TEXT_INPUT_CHARACTER_LIMIT, nk_filter_ascii); nk_edit_string_zero_terminated(context, NK_EDIT_SELECTABLE | NK_EDIT_ALWAYS_INSERT_MODE | NK_EDIT_BOX | NK_EDIT_SIMPLE, const_cast<char*>(contents.data()), internal::TEXT_INPUT_CHARACTER_LIMIT, nk_filter_ascii);
// Detect whether any editing of the string has occurred // Detect whether any editing of the string has occurred
...@@ -9,6 +16,13 @@ void TDT4102::TextInput::update(nk_context *context) { ...@@ -9,6 +16,13 @@ void TDT4102::TextInput::update(nk_context *context) {
fire(); fire();
} }
previousContents = contents; previousContents = contents;
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);
nk_style_pop_style_item(context);
} }
TDT4102::TextInput::TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText) TDT4102::TextInput::TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText)
......
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