You.i Engine
YiTextEditView.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_TEXT_EDIT_VIEW_H_
3 #define _YI_TEXT_EDIT_VIEW_H_
4 
7 #include "utility/YiColor.h"
8 #include "utility/YiTimer.h"
9 #include "view/YiSceneView.h"
10 
11 class CYIAssetTexture;
12 class CYIKeyEvent;
13 class CYIPushButtonView;
14 class CYITextSceneNode;
15 class CYITimelineLoop;
16 
53 {
54 public:
55  enum class Justification : uint8_t
56  {
57  Left = 0,
58  Right,
59  Center,
60  Start,
61  End
62  };
63 
64  enum class ClearButtonMode
65  {
66  Never, /* Clear button will never show */
67  WhileEditing, /* Clear button will show when TextEditView currently has text and the user is editing */
68  UnlessEditing, /* Clear button will show when TextEditView currently has text and the user is not editing */
69  Always /* Clear button will show when TextEditView currently has text */
70  };
71 
73  virtual ~CYITextEditView();
74 
75  virtual bool Init() override;
76 
80  virtual void Clear();
81 
87  virtual void SetValue(CYIString text, bool notifyKeyboard = true);
88 
92  virtual CYIString GetValue() const;
93 
97  void SetDefaultText(const CYIString &defaultText, bool cropToMaxCharacterCount = true);
98 
103  const CYIString &GetDefaultText() const;
104 
110  void SetDefaultTextColor(const CYIColor &defaultTextColor);
111 
117  const CYIColor &GetDefaultTextColor() const;
118 
123  bool IsDisplayingDefaultText() const;
124 
130  void SetTextColor(const CYIColor &textColor);
131 
137  const CYIColor &GetTextColor() const;
138 
142  void SetFontSize(int32_t size);
143 
149  size_t GetFontSize() const;
150 
158  void SetCaretColor(const CYIColor &clrCaret);
159 
165  const CYIColor &GetCaretColor() const;
166 
170  size_t GetCaretPosition() const;
171 
175  void DeactivateCaret();
176 
180  void ActivateCaret();
181 
186 
193 
197  void SetMaximumCharacterCount(size_t maximumCharacterCount);
198 
202  void SetEditingEnabled(bool enable);
203 
209  bool IsEditingEnabled() const;
210 
218  void Activate();
219 
227  void Deactivate();
228 
235  bool IsActivated() const;
236 
240  size_t GetMaximumCharacterCount() const;
241 
247  bool SetTextEntryBoxWidth(float boxWidth);
248 
254  float GetTextEntryBoxWidth() const;
255 
259  float GetInitialTextEntryBoxWidth() const;
260 
266  void SetXJustify(Justification xJustify);
267 
272  Justification GetXJustify() const;
273 
274  virtual bool OnTextEntered(const CYIString &pText, int32_t caret) override;
275 
276  virtual bool OnTextDeleted(int32_t beforeCaret, int32_t afterCaret) override;
277  virtual void OnTextReplaced(const CYIString &text, size_t cursor) override;
278  virtual void OnCursorPositionChanged(size_t cursor) override;
279 
283  virtual bool OnKeyboardHidden() override;
284 
288  virtual void OnSynchronizeKeyboard(Receiver::Description &receiverDescription) override;
289 
290  virtual void SetReturnKeyType(CYIKeyboardInputBridge::ReturnKeyType keyType) override;
291 
296  virtual void SetInputType(CYIKeyboardInputBridge::InputType inputType);
297 
298  virtual CYIKeyboardInputBridge::InputType GetInputType() const override;
299 
300  virtual bool OnSetComposingText(const CYIString &pText, int32_t caret) override;
301 
302  virtual bool OnFinishComposingText() override;
303 
304  virtual bool OnSetComposingRegion(int32_t start, int32_t end) override;
305  virtual bool OnTextPasted(const CYIString &pText) override;
306 
307  virtual const CYISceneView::AssetRequirement *GetAssetRequirements(uint32_t *pRequirementCount) override;
308 
313  virtual bool HandleEvent(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent) override;
314 
318  CYISignal<const CYIString & /*currentText*/, const CYIString & /*previousText*/> TextChanged;
319 
324 
329 
330 protected:
334  virtual void UpdateTextView();
335 
339  void UpdateTextView(const CYIString &currentText);
340 
344  bool OnKeyDownWhenActive(CYIKeyEvent *pEvent);
345 
349  bool OnKeyInputWhenActive(CYIKeyEvent *pEvent);
350 
354  virtual bool OnCharWhenActive(CYIKeyEvent *pEvent);
355 
359  void OnCaretBlink();
360 
366  void OnActivated();
367 
371  void OnDeactivated();
372 
376  void ShowKeyboard();
377 
383  void OnTextChanged(bool notifyKeyboard);
384 
389 
393  void ResetCaretBlinkTimer();
394 
399  void SetCaretPositionInString(float localSpaceX, float localSpaceY, int8_t caretOffset = 0);
400 
406  void RemoveComposingText(bool emitChangedSignal = true);
407 
411  bool HasComposingText();
412 
416  void OnClearButtonClicked();
417 
421  void UpdateClearButton();
422 
426  void UpdateTextSpan(bool updateTextOffset);
427 
433  bool InitInputType();
434 
441 
445  float GetTextWidth(uint32_t position);
446 
451  void OnScrollTimerEvent();
452 
457  void StartScrolling();
458 
462  void StopScrolling();
463 
468 
473 
477  virtual void WorldSurfaceScaleUpdated() override;
478 
482  virtual void UpdateBegin() override;
483 
487  virtual void UpdateEnd() override;
488 
490  std::unique_ptr<CYITimelineLoop> m_pCaretBlinkTimelineLoop;
495  std::unique_ptr<CYITimer> m_pScrollTimer;
496  CYIString m_CurrentText;
497  CYIString m_PreviousText;
498  CYIString m_DefaultText;
515 
518 
519  float m_caretMaxX;
522 
523  std::shared_ptr<CYIAssetTexture> m_DefaultCaretTexture;
524 
525 private:
526  enum class SetCaretPositionSource : uint8_t
527  {
528  InternalCall,
529  KeyboardInputBridge
530  };
531 
532  bool HandleEventWhenActive(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent);
533  bool HandleEventWhenInactive(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent);
534 
535  bool TabKeyPressed(const CYIKeyEvent *pKeyEvent);
536 
537  void DoScrolling(bool isMouseEvent);
538  void NotifyKeyboardOnTextChange();
539  void NotifyKeyboardOnCursorPositionWillChange();
540  void NotifyKeyboardOnCursorPositionChanged();
541 
542  void SetBasicCaretPosition(size_t logicalPosition, bool alignedCharacterMustBeVisible, SetCaretPositionSource callSource);
543  void SetCaretPosition(size_t logicalPosition, bool alignWithPreviousCharacter, SetCaretPositionSource callSource);
544  void SetCaretPosition(CYITextEngine::PositionInString position, SetCaretPositionSource callSource);
545 
548 };
549 
552 #endif // _YI_TEXT_EDIT_VIEW_H_
void ActivateCaret()
bool IsDisplayingDefaultText() const
void DoScrollingForTimerEvent()
CYITextEngine::PositionInString m_posInString
Definition: YiTextEditView.h:509
CYISignal< CYITextEditView * > Activated
Definition: YiTextEditView.h:323
ClearButtonMode GetClearButtonMode() const
CYIColor m_DefaultTextColor
Definition: YiTextEditView.h:499
virtual void OnSynchronizeKeyboard(Receiver::Description &receiverDescription) override
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:122
CYIColor m_CaretColor
Definition: YiTextEditView.h:501
const CYIString & GetDefaultText() const
Justification
Definition: YiTextEditView.h:55
const CYIColor & GetDefaultTextColor() const
size_t m_maximumCharacterCount
Definition: YiTextEditView.h:511
Class for key events.
Definition: YiKeyEvent.h:15
void SetDefaultText(const CYIString &defaultText, bool cropToMaxCharacterCount=true)
bool m_activated
Definition: YiTextEditView.h:505
Provides an interface to interact with the system software keyboard.
Definition: YiKeyboardInputBridge.h:100
bool SetTextEntryBoxWidth(float boxWidth)
std::shared_ptr< CYIAssetTexture > m_DefaultCaretTexture
Definition: YiTextEditView.h:523
void SetMaximumCharacterCount(size_t maximumCharacterCount)
virtual bool OnTextPasted(const CYIString &pText) override
virtual void OnTextReplaced(const CYIString &text, size_t cursor) override
Base class for events.
Definition: YiEvent.h:27
The base class for all view types. Views are containers of renderable elements that often define inte...
Definition: YiSceneView.h:47
virtual void Clear()
bool OnKeyDownWhenActive(CYIKeyEvent *pEvent)
virtual const CYISceneView::AssetRequirement * GetAssetRequirements(uint32_t *pRequirementCount) override
size_t m_composingStartPos
Definition: YiTextEditView.h:512
void SetEditingEnabled(bool enable)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
void SetTextColor(const CYIColor &textColor)
void SetCaretPositionInString(float localSpaceX, float localSpaceY, int8_t caretOffset=0)
virtual bool OnSetComposingText(const CYIString &pText, int32_t caret) override
CYISignal< const CYIString &, const CYIString &> TextChanged
Definition: YiTextEditView.h:318
const CYIColor & GetTextColor() const
bool InitInputType()
size_t m_lengthOfValueString
Definition: YiTextEditView.h:508
ReturnKeyType
The preferred return key type.
Definition: YiKeyboardInputBridge.h:84
A texture asset representing an image which will be loaded into the GPU.
Definition: YiAssetTexture.h:22
size_t GetMaximumCharacterCount() const
const CYIColor & GetCaretColor() const
Iterator end(Iterator::Mode mode=Iterator::Mode::ImmediateChildren) const
glm::vec3 m_scrollMouseLocalSpaceLocation
Definition: YiTextEditView.h:517
bool m_updateText
Definition: YiTextEditView.h:503
CYITextSceneNode * m_pTextNode
Definition: YiTextEditView.h:492
virtual bool Init() override
void DoScrollingForMouseEvent()
Justification m_xJustify
Definition: YiTextEditView.h:521
void OnDeactivated()
size_t GetFontSize() const
void StartScrolling()
void SetXJustify(Justification xJustify)
void ResetCaretBlinkTimer()
bool IsEditingEnabled() const
Definition: YiSceneView.h:76
bool m_alignedCharacterMustBeVisible
Definition: YiTextEditView.h:510
void OnClearButtonClicked()
void SetFontSize(int32_t size)
ClearButtonMode m_clearButtonMode
Definition: YiTextEditView.h:502
CYISceneNode * m_pCaretNode
Definition: YiTextEditView.h:491
bool HasComposingText()
virtual bool OnTextEntered(const CYIString &pText, int32_t caret) override
CYIString m_PreviousText
Definition: YiTextEditView.h:497
float GetInitialTextEntryBoxWidth() const
CYIPushButtonView * m_pClearBtn
Definition: YiTextEditView.h:493
void UpdateClearButton()
void SetClearButtonMode(ClearButtonMode mode)
virtual void SetValue(CYIString text, bool notifyKeyboard=true)
A low-precision timer driven by the update loop.
Definition: YiTimer.h:27
CYITimer m_CaretTimer
Definition: YiTextEditView.h:489
bool OnKeyInputWhenActive(CYIKeyEvent *pEvent)
virtual void SetReturnKeyType(CYIKeyboardInputBridge::ReturnKeyType keyType) override
float GetTextEntryBoxWidth() const
size_t m_composingEndPos
Definition: YiTextEditView.h:513
virtual bool HandleEvent(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent) override
CYISceneNode * m_pEntryFieldNode
Definition: YiTextEditView.h:494
void OnTextChanged(bool notifyKeyboard)
A scene node is the base type for all nodes which are used by the scene manager; it is an integral pa...
Definition: YiSceneNode.h:99
void DeactivateCaret()
A scene node type that renders text.
Definition: YiTextSceneNode.h:78
virtual ~CYITextEditView()
virtual bool OnSetComposingRegion(int32_t start, int32_t end) override
std::unique_ptr< CYITimelineLoop > m_pCaretBlinkTimelineLoop
Definition: YiTextEditView.h:490
virtual void SetInputType(CYIKeyboardInputBridge::InputType inputType)
bool m_editingEnabled
Definition: YiTextEditView.h:504
float GetTextWidth(uint32_t position)
virtual void WorldSurfaceScaleUpdated() override
virtual CYIString GetValue() const
virtual bool OnKeyboardHidden() override
Displays text to the user and allows them to edit it.
Definition: YiTextEditView.h:52
Definition: YiTextEngine.h:102
bool m_caretActive
Definition: YiTextEditView.h:506
float m_initialCaretMaxX
Definition: YiTextEditView.h:520
virtual void UpdateBegin() override
virtual bool OnTextDeleted(int32_t beforeCaret, int32_t afterCaret) override
virtual void UpdateTextView()
bool InitDefaultTextFromProperty()
bool m_placeholderTextMode
Definition: YiTextEditView.h:507
bool IsActivated() const
CYIString m_CurrentText
Definition: YiTextEditView.h:496
void RemoveComposingText(bool emitChangedSignal=true)
void UpdateCaretNodePositionAndTextOffset()
virtual void OnCursorPositionChanged(size_t cursor) override
virtual bool OnFinishComposingText() override
void OnScrollTimerEvent()
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:257
size_t GetCaretPosition() const
Justification GetXJustify() const
Repeats a timeline.
Definition: YiTimelineLoop.h:20
glm::vec2 m_scrollMouseLocationDown
Definition: YiTextEditView.h:516
virtual void UpdateEnd() override
CYIKeyboardInputBridge::InputType m_inputType
Definition: YiTextEditView.h:514
A class used to represent a color value.
Definition: YiColor.h:31
Provides an implementation of a button which accepts user interaction in the form of a press and rele...
Definition: YiPushButtonView.h:34
virtual bool OnCharWhenActive(CYIKeyEvent *pEvent)
std::unique_ptr< CYITimer > m_pScrollTimer
Definition: YiTextEditView.h:495
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:168
CYIString m_DefaultText
Definition: YiTextEditView.h:498
float m_caretMaxX
Definition: YiTextEditView.h:519
ClearButtonMode
Definition: YiTextEditView.h:64
CYISignal< CYITextEditView * > Deactivated
Definition: YiTextEditView.h:328
virtual CYIKeyboardInputBridge::InputType GetInputType() const override
void SetDefaultTextColor(const CYIColor &defaultTextColor)
void UpdateTextSpan(bool updateTextOffset)
InputType
The preferred input type.
Definition: YiKeyboardInputBridge.h:40
void SetCaretColor(const CYIColor &clrCaret)
CYIColor m_TextColor
Definition: YiTextEditView.h:500
void StopScrolling()