 |
Gorgon Game Engine
|
Go to the documentation of this file.
7 #include "../Property.h"
8 #include "../UI/Validators.h"
9 #include "../UI/ComponentStackWidget.h"
10 #include "../UI/Helpers.h"
11 #include "../Input/KeyRepeater.h"
14 namespace Gorgon {
namespace Widgets {
26 glyphbyte &operator +=(
const glyphbyte &other) {
33 glyphbyte
operator +(
const glyphbyte &other)
const {
34 return {glyph + other.glyph,
byte + other.byte};
38 static constexpr
int allselected = std::numeric_limits<int>::max();
50 std::string GetText()
const {
54 std::string GetSelectedText()
const {
56 return display.substr(selstart.byte + sellen.byte, -sellen.byte);
57 else if(sellen.byte > 0)
58 return display.substr(selstart.byte, sellen.byte);
69 sellen = {allselected, allselected};
81 int SelectionStart()
const {
82 return selstart.glyph;
87 int SelectionLength()
const {
92 int CaretLocation()
const {
93 return selstart.glyph + sellen.glyph;
99 bool Activate()
override {
103 bool Done()
override;
107 virtual bool KeyEvent(
Input::Key key,
float state)
override;
109 virtual void SetEnabled(
bool value)
override {
110 ComponentStackWidget::SetEnabled(value);
124 void SetAutoSelectAll(
const bool &value) {
125 autoselectall = value;
126 if(!IsFocused() && value) {
133 bool GetAutoSelectAll()
const {
134 return autoselectall;
139 void SetBlockEnterKey(
const bool &value) {
145 bool GetBlockEnterKey()
const {
151 void SetReadonly(
const bool &value) {
152 if(value == readonly)
157 if(readonly && IsEnabled()) {
167 bool GetReadonly()
const {
174 &Inputbox_base::GetAutoSelectAll,
175 &Inputbox_base::SetAutoSelectAll> AutoSelectAll;
180 &Inputbox_base::GetBlockEnterKey,
181 &Inputbox_base::SetBlockEnterKey> BlockEnterKey;
186 &Inputbox_base::GetReadonly,
187 &Inputbox_base::SetReadonly>
Readonly;
193 void updateselection();
196 virtual void updatevalue() = 0;
199 virtual void updatevaluedisplay(
bool updatedisplay =
true) = 0;
201 virtual void changed() = 0;
204 if(selstart.glyph > 0) {
209 while(selstart.byte && (display[selstart.byte] & 0b11000000) == 0b10000000)
214 void moveselright() {
215 if(selstart.glyph < glyphcount) {
221 void eraseselected() {
222 if(sellen.byte < 0) {
225 int pos = selstart.byte + sellen.byte;
227 display.erase(pos, -sellen.byte);
229 glyphcount += sellen.glyph;
233 else if(sellen.byte > 0) {
236 int pos = selstart.byte;
238 display.erase(pos, sellen.byte);
240 glyphcount -= sellen.glyph;
243 updatevaluedisplay(
false);
248 void focuslost()
override;
250 void focused()
override;
261 glyphbyte selstart = {0, 0};
262 glyphbyte sellen = {0, 0};
265 int scrolloffset = 0;
267 bool ismousedown =
false;
268 bool autoselectall =
false;
269 bool blockenter =
false;
270 bool readonly =
false;
327 public internal::Inputbox_base,
328 public P_<UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>, T_, &UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::get_, &UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::set_> {
334 using PropType = P_<UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>, T_, &
UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::get_, &
UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::set_>;
336 friend class P_<UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>, T_, &
UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::get_, &
UI::internal::prophelper<Inputbox<T_, V_, P_>, T_>::set_>;
337 template<class T1_, class V1_, template<class C_, class PT_, PT_(C_::*Getter_)() const, void(C_::*Setter_)(const PT_&)> class P1_, Widgets::Registry::TemplateType DEFTMP1_>
342 explicit
Inputbox(const UI::Template &temp, T_ value = T_()) :
343 internal::Inputbox_base(temp),
PropType(&helper), value(value)
345 display = validator.ToString(value);
390 operator T_()
const {
428 value = validator.From(display);
440 display = validator.ToString(value);
int UTF8Bytes(char c)
Returns the number of bytes used by the next UTF8 codepoint.
Definition: String.h:569
Textholder is designed to hold text data.
Definition: Template.h:1422
@ ContentsTag
Definition: Template.h:872
This class provides event mechanism.
Definition: Event.h:134
@ SelectionTag
Definition: Template.h:874
This class stores visual information about a widget template.
Definition: Template.h:392
Supports logic operators.
Definition: Property.h:230
T_ X
X coordinate.
Definition: Point.h:368
@ TopLeft
Top left.
Definition: Template.h:41
@ CaretTag
Definition: Template.h:875
@ Text
Works only for TextholderTemplate, data will affect the text that is displayed.
Definition: Template.h:651
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
uint32_t Char
Definition: Types.h:46
This is generic property that can be set and retrieved good for enums mostly, its ok to use with POD ...
Definition: Property.h:30
@ ViewPortTag
Definition: Template.h:873
@ BottomLeft
Bottom left.
Definition: Template.h:56
std::string GetClipboardText(Resource::GID::Type type=Resource::GID::Text)
Returns the clipboard text.
Definition: Clipboard.cpp:249
int UnicodeGlyphCount(const std::string &s)
Definition: String.h:595
int UnicodeUTF8Bytes(Char c)
Definition: String.h:583
T_ operator+(TextualProperty< C_, T_, Setter_, Getter_ > &t, const T_ &v)
Definition: Property.h:801
This class represents a 2D point.
Definition: Point.h:32
bool InsertUnicode(std::string &s, std::size_t pos, Char c)
Appends a unicode code point to the string.
Definition: String.h:650
@ Active
This is for widgets that can be activated, like a count down timer.
Definition: Template.h:245
Gorgon::Property< UI::internal::prophelper< Inputbox< T_, UI::ConversionValidator< T_ >, Gorgon::Property >, T_ >, T_, &UI::internal::prophelper< Inputbox< T_, UI::ConversionValidator< T_ >, Gorgon::Property >, T_ >::get_, &UI::internal::prophelper< Inputbox< T_, UI::ConversionValidator< T_ >, Gorgon::Property >, T_ >::set_ >::Type T_ Type
Definition: Property.h:32
T_ Y
Y coordinate.
Definition: Point.h:371
T_ Width
Width of this size object.
Definition: Size.h:258
T_ Get() const
Definition: Property.h:59
const Graphics::TextRenderer & GetRenderer() const
Returns the renderer for this textholder.
Definition: Template.h:1445
@ Textholder
Definition: Template.h:163
void SetClipboardText(const std::string &text, Resource::GID::Type type=Resource::GID::Text, bool unicode=true, bool append=false)
Sets the clipboard text to given string.
Definition: Clipboard.cpp:350
Tag
Tags mark a component to be modified in a way meaningful to specific widgets.
Definition: Template.h:850
bool AppendUnicode(std::string &s, Char c)
Appends a unicode code point to the string.
Definition: String.h:609
@ Readonly
Component is visible when the widget is readonly.
Definition: Template.h:187