cangine
Loading...
Searching...
No Matches
inputfield_object.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5#include "../game_object.hpp"
6#include "../../components/ui/inputfield_component.hpp"
7
8namespace cangine {
16 class InputField : public GameObject {
17 private:
19
20 public:
22 InputField();
27 void setContent(std::string contentIn) {
29 ifc->updateView();
30 }
40 void setCursorPos(int posIn) {
42 ifc->updateView();
43 }
48 void setWidth(float widthIn) { ifc->width = (int)widthIn; }
53 void setHeight(float heightIn) { ifc->height = (int)heightIn; ifc->setFontHeight((heightIn * 4) / 5); }
93 void setOnReturn(std::function<void(std::string)> functionIn) { ifc->onReturn = functionIn; }
94
104 const std::string& getContent() const { return ifc->content; }
109 const std::string& getPlaceholder() const { return ifc->placeholder; }
114 int getCursorPos() const { return ifc->cursorpos; }
119 float getWidth() const { return (float)ifc->width; }
124 float getHeight() const { return (float)ifc->height; }
129 float getBorderWidth() const { return ifc->borderWidth; }
134 const Color& getPlaceholderColor() const { return ifc->placeholderColor; }
139 const Color& getBorderColor() const { return ifc->borderColor; }
144 const Color& getBorderColorFocus() const { return ifc->borderColorFocus; }
149 const Color& getCursorColor() const { return ifc->cursorColor; }
154 const Color& getBackgroundColor() const { return ifc->backgroundColor; }
159 const Color& getColor() const { return ifc->color; }
160 };
161}
Base class for everything that lives in the scene.
Definition game_object.hpp:20
T * getComponent()
Returns the first attached component of a type.
Definition game_object.hpp:93
Editable single-line text input field.
Definition inputfield_component.hpp:19
Color cursorColor
Caret color.
Definition inputfield_component.hpp:50
void updateView()
Recomputes the visible text window from the caret position.
Definition inputfield_component.cpp:155
int height
Field height in pixels.
Definition inputfield_component.hpp:36
float borderWidth
Border thickness in pixels.
Definition inputfield_component.hpp:45
Color borderColor
Border color when not focused.
Definition inputfield_component.hpp:48
std::string content
Current text content.
Definition inputfield_component.hpp:38
int width
Field width in pixels.
Definition inputfield_component.hpp:35
std::function< void(std::string)> onReturn
Called with the content when Enter is pressed.
Definition inputfield_component.hpp:42
Color placeholderColor
Color of the placeholder text.
Definition inputfield_component.hpp:47
std::string placeholder
Text shown when the field is empty.
Definition inputfield_component.hpp:46
int cursorpos
Caret position as an index into content.
Definition inputfield_component.hpp:39
Color borderColorFocus
Border color when focused.
Definition inputfield_component.hpp:49
Editable text-field game object.
Definition inputfield_object.hpp:16
const Color & getBorderColorFocus() const
Returns the focused border color.
Definition inputfield_object.hpp:144
void setPlaceholder(std::string placeholderIn)
Sets the placeholder text shown when empty.
Definition inputfield_object.hpp:35
InputFieldComponent * getIFC()
Returns the underlying input field component.
Definition inputfield_object.hpp:99
void setBorderColor(Color colorIn)
Sets the border color when unfocused.
Definition inputfield_object.hpp:68
int getCursorPos() const
Returns the caret position.
Definition inputfield_object.hpp:114
void setHeight(float heightIn)
Sets the field height (and scales the font to match).
Definition inputfield_object.hpp:53
const std::string & getPlaceholder() const
Returns the placeholder text.
Definition inputfield_object.hpp:109
void setWidth(float widthIn)
Sets the field width.
Definition inputfield_object.hpp:48
const Color & getCursorColor() const
Returns the caret color.
Definition inputfield_object.hpp:149
void setOnReturn(std::function< void(std::string)> functionIn)
Sets the callback invoked when Enter is pressed.
Definition inputfield_object.hpp:93
const Color & getBackgroundColor() const
Returns the background color.
Definition inputfield_object.hpp:154
const Color & getBorderColor() const
Returns the unfocused border color.
Definition inputfield_object.hpp:139
float getBorderWidth() const
Returns the border thickness.
Definition inputfield_object.hpp:129
void setContent(std::string contentIn)
Sets the field's text content and refreshes the view.
Definition inputfield_object.hpp:27
const std::string & getContent() const
Returns the current content.
Definition inputfield_object.hpp:104
const Color & getColor() const
Returns the text color.
Definition inputfield_object.hpp:159
void setBorderColorFocus(Color colorIn)
Sets the border color when focused.
Definition inputfield_object.hpp:73
float getHeight() const
Returns the field height.
Definition inputfield_object.hpp:124
void setPlaceHolderColor(Color colorIn)
Sets the placeholder text color.
Definition inputfield_object.hpp:63
void setCursorPos(int posIn)
Sets the caret position and refreshes the view.
Definition inputfield_object.hpp:40
float getWidth() const
Returns the field width.
Definition inputfield_object.hpp:119
void setBackgroundColor(Color colorIn)
Sets the field background color.
Definition inputfield_object.hpp:83
void setColor(Color colorIn)
Sets the text color.
Definition inputfield_object.hpp:88
void setBorderWidth(float widthIn)
Sets the border thickness.
Definition inputfield_object.hpp:58
const Color & getPlaceholderColor() const
Returns the placeholder text color.
Definition inputfield_object.hpp:134
InputField()
Constructs an input field with a default style.
Definition inputfield_object.cpp:6
InputFieldComponent * ifc
Component implementing the input field.
Definition inputfield_object.hpp:18
void setCursorColor(Color colorIn)
Sets the caret color.
Definition inputfield_object.hpp:78
Color color
Text color.
Definition textrenderer_component.hpp:27
void setFontHeight(int heightIn)
Sets the font's pixel height (reloads the font).
Definition textrenderer_component.cpp:95
Color backgroundColor
Background fill color.
Definition textrenderer_component.hpp:28
Definition audiomanager.cpp:4
RGBA color stored as normalized floating-point components.
Definition color.hpp:12