Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
ds_edit.h
1/* Copyright (C) 2017 - 2024, Thornwave Labs Inc - All Rights Reserved.
2 * Unauthorized copying of this file, via any medium is strictly prohibited.
3 * Proprietary and confidential.
4 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
5*/
6
7#ifndef _DS_EDIT_H
8#define _DS_EDIT_H
9
10
11#include <ds_view.h>
12#include <ds_string.h>
13
14
21class DsEdit: public DsView
22{
23public:
28 {
29 public:
35 virtual bool operator()(const DsString &text) = 0;
36 };
37
38
43 {
44 public:
51 SignedIntegerValidator(int64_t min, int64_t max, uint8_t base = 10);
52
53 private:
54 uint8_t mBase;
55 int64_t mMin;
56 int64_t mMax;
57
58 bool operator()(const DsString &text) override final;
59 };
60
61
66 {
67 public:
74 UnsignedIntegerValidator(uint64_t min, uint64_t max, uint8_t base = 10);
75
76 private:
77 uint8_t mBase;
78 uint64_t mMin;
79 uint64_t mMax;
80
81 bool operator()(const DsString &text) override final;
82 };
83
84
89 {
90 public:
96 FloatValidator(float min, float max);
97
98
99 private:
100 float mMin;
101 float mMax;
102
103 bool operator()(const DsString &text) override final;
104 };
105
106
111 {
112 public:
118 virtual void onEditBoxFocused(DsEdit* object) {}
119
125 virtual void onEditBoxChanged(DsEdit* object) {}
126
132 virtual void onEditBoxNewLine(DsEdit* object) {}
133
140 virtual void onEditBoxValidation(DsEdit* object, bool is_valid) {}
141 };
142
143
152 DsEdit(DsView* parent, const DsPoint &pos, const DsSize &size, size_t text_capacity);
153
154
159 void setMaxTextLength(size_t length);
160
161
166 size_t getMaxTextLength(void) const;
167
168
173 size_t getTextLength(void) const;
174
175
180 void setHint(const char* text);
181
182
188
189
194 void setHintFont(const ds_bitmap_font_t* font);
195
196
202
203
208 void setTextFont(const ds_bitmap_font_t* font);
209
210
216 void setPasswordMode(bool password_mode);
217
218
224 void setListener(Listener* listener);
225
226
234 int64_t getValueAsSigned(void) const;
235
236
244 uint64_t getValueAsUnsigned(void) const;
245
246
254 float getValueAsFloat(void) const;
255
256
262 const char* getValueAsString(void) const;
263
264
269 void setValidator(Validator* validator);
270
271
275 void setInvalidValue(void);
276
277
285 bool isValidValue(void) const;
286
287
291 void validateValue(void);
292
293
297 void setValue(const char* format, ...);
298
299
303 void setValue(const char* format, va_list args);
304
305
309 void clear(void);
310
311private:
312 DsAlignment mAlignment;
313 Validator* mValidator;
314 bool mIsValueValid;
315
316 const char* mHint;
317 DsColor mHintColor;
318 const ds_bitmap_font_t* mHintFont;
319
320 DsColor mTextColor;
321 const ds_bitmap_font_t* mTextFont;
322 bool mPasswordMode;
323
324 Listener* mListener;
325
326 DsString mText;
327 size_t mMaxTextLength;
328
329 void onPaint(DsRenderer &renderer) override final;
330 void onKeyboard(int32_t key) override final;
331};
332
333
334#endif
335
DsAlignment is a class representing both horizontal and vertical alignment type.
Definition ds_types.h:130
DsColor is a class that represents a 4 channel color (Alpha, Red, Green, Blue).
Definition ds_color.h:53
FloatValidator is a class implementing validation for real numbers (floating point).
Definition ds_edit.h:89
FloatValidator(float min, float max)
Constructor.
Listener is an interface class that receives events from the edit view.
Definition ds_edit.h:111
virtual void onEditBoxValidation(DsEdit *object, bool is_valid)
Called when the edit view validation status changes.
Definition ds_edit.h:140
virtual void onEditBoxChanged(DsEdit *object)
Called when the edit view text input changes.
Definition ds_edit.h:125
virtual void onEditBoxFocused(DsEdit *object)
Called when the edit view receives focus.
Definition ds_edit.h:118
virtual void onEditBoxNewLine(DsEdit *object)
Called when the edit view received a new line character (user presed ENTER).
Definition ds_edit.h:132
SignedIntegerValidator is a class implementing validation for a signed integer input.
Definition ds_edit.h:43
SignedIntegerValidator(int64_t min, int64_t max, uint8_t base=10)
Constructor.
UnsignedIntegerValidator is a class implementing validation for an unsigned integer input.
Definition ds_edit.h:66
UnsignedIntegerValidator(uint64_t min, uint64_t max, uint8_t base=10)
Constructor.
Base class for the validators.
Definition ds_edit.h:28
virtual bool operator()(const DsString &text)=0
Validates the text input.
Definition ds_edit.h:22
int64_t getValueAsSigned(void) const
Returns the edit view text interpreted as a signed integer.
size_t getTextLength(void) const
Returns the actual text length of the edit box.
bool isValidValue(void) const
Is the DsEdit value valid?
uint64_t getValueAsUnsigned(void) const
Returns the edit view text interpreted as an unsigned integer.
void setTextFont(const ds_bitmap_font_t *font)
Sets the text font.
DsEdit(DsView *parent, const DsPoint &pos, const DsSize &size, size_t text_capacity)
Creates a DsEdit object.
void setInvalidValue(void)
Sets the DsEdit state as invalid. This will trigger a callback to DsEdit::Listener::onEditBoxValidati...
const char * getValueAsString(void) const
Returns the edit view string.
size_t getMaxTextLength(void) const
Returns the maximum text length allowed in the edit box.
void setPasswordMode(bool password_mode)
Sets the edit view password mode.
void setValidator(Validator *validator)
Sets the value validator object.
void setListener(Listener *listener)
Sets the DsEdit event listener.
void setHint(const char *text)
Sets the hint text.
void setValue(const char *format, va_list args)
Sets the DsEdit value using the vprintf() format.
void clear(void)
Clears the DsEdit value.
void setTextColor(DsColor color)
Sets the text color.
void setValue(const char *format,...)
Sets the DsEdit value using the printf() format.
void setHintColor(DsColor color)
Sets the hint text color.
void setHintFont(const ds_bitmap_font_t *font)
Sets the hint text font.
void validateValue(void)
Runs the value validation.
float getValueAsFloat(void) const
Returns the edit view text interpreted as a floating point number.
void setMaxTextLength(size_t length)
Sets the maximum text length allowed in the edit box.
DsPoint is a class that represents the X and Y 2D coordinates of a point as integer numbers.
Definition ds_geometry.h:24
DsRenderer is a class that implements all the drawing operations.
Definition ds_renderer.h:42
DsSize is class that represents the 2D size of a graphic object (width, height) as integer values.
Definition ds_geometry.h:780
DsString is a class representing a character string.
Definition ds_string.h:26
DsView is a base class that represents any view on the screen.
Definition ds_view.h:40
Definition ds_font.h:45