SimpleInput class reference


Basic interactive widget - displays a input control that reacts to mouse clicks and keyboard inputs. It supports keyboard shortcuts like: Ctrl+A, Ctrl+X, Ctrl+C, Ctrl+V, Left and right Arrows, Backspace.

SimpleInput input(window, {{0,0}, {100, 30}}, theme);

Functions

Functions documentation

SimpleInput(
Window* window,
const Widget2DProps& props = Widget2DProps({ 0,0 }, { 0,0 }, Anchor::Left | Anchor::Bottom | ResizePolicy::AutoFill),
const SimpleInputTheme& rectProps = SimpleInputTheme(),
std::wstring defaultText = L""
);

Default constructor.


SimpleInput(
Window* window,
const Widget2DProps& props = Widget2DProps({ 0,0 }, { 0,0 }, Anchor::Left | Anchor::Bottom | ResizePolicy::AutoFill),
const Theme& theme = Theme(),
std::wstring defaultText = L""
);

Delegating constructor with theme application.


SimpleInput(const SimpleInput& copy);

Copy constructor.


virtual ~SimpleInput();

Destructor.


SimpleInput& operator=(SimpleInput rhs);

Assignment operator.


friend void swap(SimpleInput& first, SimpleInput& second) noexcept;

Swap function.


SimpleInput* Clone() const override;

Clones the object (usefull while making copy of object that is casted to its base).


const std::wstring& GetTextRef() const;

Returns reference to the input text (quick access).


std::wstring GetTextWhenEnter();

Returns the current input text (useful when using the pooling technique). When Enter key was not pressed returns empty std::wstirng -> L"".


void SetCallback(Callback function);

Sets a callback that is executed every time an event is processed (inside SimpleInput object).


void ResetCallback();

Resets the callback to nullptr.


void SetFilter(std::function<bool(KbCharAppearEvent*)> function);

Sets the filter that passes specific characters to the SimpleInput widget. There are 5 predefinied filters: IntNumericFilter, FloatNumericFilter, AlphabeticFilter, AlphaNumericFilter, CustomFilter.


void ResetFilter();

Resets the filter to nullptr.


WidgetMouseState GetState();

Returns the current status of the widget (useful when using the pooling technique).


void SetColor(WidgetMouseState forState, Color color);

Sets the background color for a given widget state.


void SetColor(Color normal, Color hover, Color press);

Sets the background color for all widget states.


void SetBorderColor(WidgetMouseState forState, Color color);

Sets the border color for a given widget state.


void SetBorderColor(Color normal, Color hover, Color press);

Sets the border color for all widget states.


void SetBoderSize(Dimension<int> newBorderSize);

Sets the widget border size.


void SetFontSize(int newSize);

Sets the font size for the text inside Input field.


void SetText(std::wstring newText);

Sets the text inside Input field.


void SetFont(Font* newFont);

Sets the new font for the input text. (Requires redrawn to show changes)


void SetFontColor(Color newColor);

Sets the font color for all widget states.


void SetFlags(int newFlags) override;

Sets the widget flags.


void SetTextMargin(Point<int> newMargins);

Sets the text margins to the left bottom position of the widget.


void SetDefaultTextColor(Color newColor);

Sets new font color for the default text.


void SetDefaultText(std::wstring newDefaultText);

Dets new default text.


void UnregisterEvent(EventType eventType) override;

Allows to unregister the widget from a specific event in the parent window.


Color GetColor(WidgetMouseState forState) const;

Returns the background color for a given widget state.


Color GetBorderColor(WidgetMouseState forState) const;

Returns the border color for a given widget state.


const Dimension<int>& GetBoderSize() const;

Returns the border size of the widget.


int GetFontSize() const;

Returns font size used by widget to render text.


std::wstring GetText() const;

Returns the input text.


Color GetFontColor() const;

Returns font color used by widget to render text.


Font* GetUsedFont() const;

Returns pointer to the font object used by widget to render text.


const Point<int>& GetTextMargin() const;

Returns the text margins to the left bottom position of the widget.


Color GetDefaultTextColor() const;

Returns the default text color.


std::wstring GetDefaultText() const;

Returns the default text.


void CalcAnchorOffsets();

Converts the location of the widget depending on the flags set (Anchor).


void UpdateSelection();

Helper function. Updates the rectangular area which marks the text while selecting it via mouse.


Variables documentation

bool m_Enter;

Stores information whether the enter key has been pressed.


int m_iTicks;

Internal widget counter.


int m_iPromptIdx;

Describes current prompt position.


float m_fPromptPos;

Describes current prompt position in 2D space (X offset)


bool m_bActive;

Describes whether the SimpleInput widget is active or not.


bool m_bDrag;

Stores information whether the user drags the mouse over the button.


int m_iDragStart, m_iDragEnd;

Stores start and end position of the cursor (in characters) while user is dragging mouse.


Point<int> m_AnchorOffsets;

Stores precalculated (depending on Anchor flags) offsets.


Stores widet state. (depends on mouse actions and m_bActive variable)


Background* m_Background;

Represents the background of the SimpleInput widget.


Rectangle2D* m_BottomBar;

Graphical indicator of SimpleInput widget. (bottom bar)


Rectangle2D* m_Prompt;

Represents the prompt/cursor in the input field.


Rectangle2D* m_Selection;

Represents the text selection.


Text* m_Text;

Represents the text in the input field.


Text* m_DefaultText;

Represents the default text in the input field.


SimpleInputTheme m_InpTheme;

Stores widget theme.


Callback m_Callback;

Stores callback function.


std::function<bool(KbCharAppearEvent*)> m_FilterFunc;

Stores filter function.