R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ITextInput.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** ITextInput - Abstract text input interface for UI system
6*/
7
8#pragma once
9
10#include <functional>
11#include <string>
12
13namespace UI {
17 enum class Align;
18
32 class ITextInput {
33 public:
37 virtual ~ITextInput() = default;
38
43 virtual void Update() = 0;
44
49 virtual void Render() = 0;
50
55 virtual void SetOnTextChanged(std::function<void(const std::string &)> callback) = 0;
56
62 virtual void SetPosition(float x, float y) = 0;
63
69 virtual void GetPosition(float &x, float &y) const = 0;
70
76 virtual void SetSize(float width, float height) = 0;
77
83 virtual void GetSize(float &width, float &height) const = 0;
84
89 virtual void SetBackgroundColor(unsigned int color) = 0;
90
95 virtual void SetBorderColor(unsigned int color) = 0;
96
101 virtual void SetActiveBorderColor(unsigned int color) = 0;
102
107 virtual void SetTextColor(unsigned int color) = 0;
108
113 virtual void SetPlaceholderColor(unsigned int color) = 0;
114
119 virtual void SetTextSize(int size) = 0;
120
125 virtual void SetPlaceholder(const std::string &placeholder) = 0;
126
131 virtual void SetMaxLength(size_t maxLength) = 0;
132
139 virtual void SetValidationRegex(const std::string &regexPattern) = 0;
140
145 [[nodiscard]] virtual const std::string &GetText() const = 0;
146
151 virtual void SetText(const std::string &text) = 0;
152
156 virtual void Clear() = 0;
157
162 [[nodiscard]] virtual bool IsFocused() const = 0;
163
168 virtual void SetFocused(bool focused) = 0;
169
174 virtual void SetFont(int fontHandle) = 0;
175
180 virtual void SetAlign(Align align) = 0;
181
186 [[nodiscard]] virtual Align GetAlign() const = 0;
187
192 virtual void ApplyAlignment() = 0;
193
198 virtual void SetEnabled(bool enabled) = 0;
199
204 [[nodiscard]] virtual bool IsEnabled() const = 0;
205
210 virtual void SetPasswordMode(bool passwordMode) = 0;
211
216 [[nodiscard]] virtual bool IsPasswordMode() const = 0;
217 };
218} // namespace UI
Abstract interface for UI text input fields.
virtual void SetFocused(bool focused)=0
Set focus state programmatically.
virtual void SetEnabled(bool enabled)=0
Enable or disable the text input.
virtual const std::string & GetText() const =0
Get the current text content.
virtual void Update()=0
Update the text input internal state (focus, cursor, input).
virtual ~ITextInput()=default
Virtual destructor.
virtual void SetAlign(Align align)=0
Set alignment mode relative to the window.
virtual void SetValidationRegex(const std::string &regexPattern)=0
Set a regex pattern to restrict allowed characters.
virtual bool IsEnabled() const =0
Check if the text input is enabled.
virtual bool IsPasswordMode() const =0
Check if password mode is enabled.
virtual bool IsFocused() const =0
Check if the text input is currently focused/active.
virtual void SetSize(float width, float height)=0
Set the text input size.
virtual void SetTextColor(unsigned int color)=0
Set the text color.
virtual void SetTextSize(int size)=0
Set the text size in pixels.
virtual void SetActiveBorderColor(unsigned int color)=0
Set the border color when the input is focused/active.
virtual void SetOnTextChanged(std::function< void(const std::string &)> callback)=0
Set callback invoked when text changes.
virtual void SetPosition(float x, float y)=0
Set the top-left position of the text input.
virtual void SetBackgroundColor(unsigned int color)=0
Set the background color of the text input box.
virtual void GetSize(float &width, float &height) const =0
Get the current size of the text input.
virtual void SetMaxLength(size_t maxLength)=0
Set the maximum number of characters allowed.
virtual void SetPlaceholder(const std::string &placeholder)=0
Set the placeholder text displayed when the input is empty.
virtual void Render()=0
Render the text input box.
virtual void GetPosition(float &x, float &y) const =0
Get the current top-left position of the text input.
virtual Align GetAlign() const =0
Get the current alignment mode.
virtual void SetText(const std::string &text)=0
Set the text content programmatically.
virtual void SetPasswordMode(bool passwordMode)=0
Enable or disable password mode (masks characters with asterisks).
virtual void ApplyAlignment()=0
Apply the current alignment mode to the position.
virtual void SetBorderColor(unsigned int color)=0
Set the border color when the input is not focused.
virtual void SetPlaceholderColor(unsigned int color)=0
Set the placeholder text color (when input is empty).
virtual void Clear()=0
Clear the text content.
virtual void SetFont(int fontHandle)=0
Set the font handle for rendering text.
Definition IButton.hpp:13
Align
Alignment modes relative to the current window.
Definition IButton.hpp:33