You.i Engine
YiTextEditView.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_TEXT_EDIT_VIEW_H_
3 #define _YI_TEXT_EDIT_VIEW_H_
4 
8 #include "utility/YiColor.h"
9 #include "utility/YiTimer.h"
10 #include "view/YiSceneView.h"
11 
12 class CYIAssetTexture;
13 class CYIKeyEvent;
14 class CYIPushButtonView;
15 class CYITextEditReceiver;
16 class CYITextSceneNode;
17 class CYITimelineLoop;
18 
62 {
63 public:
64  friend class CYITextEditReceiver;
65  friend class CYITextEditViewPriv;
66 
67  enum class Justification : uint8_t
68  {
69  Left = 0,
70  Right,
71  Center,
72  Start,
73  End
74  };
75 
76  enum class ClearButtonMode
77  {
78  Never, /* Clear button will never show */
79  WhileEditing, /* Clear button will show when TextEditView currently has text and the user is editing */
80  UnlessEditing, /* Clear button will show when TextEditView currently has text and the user is not editing */
81  Always /* Clear button will show when TextEditView currently has text */
82  };
83 
85  virtual ~CYITextEditView();
86 
87  virtual bool Init() override;
88 
92  virtual void Clear();
93 
99  void SetValue(CYIString text);
100 
104  virtual CYIString GetValue() const;
105 
109  void SetDefaultText(const CYIString &defaultText, bool cropToMaxCharacterCount = true);
110 
115  const CYIString &GetDefaultText() const;
116 
122  void SetDefaultTextColor(const CYIColor &defaultTextColor);
123 
129  const CYIColor &GetDefaultTextColor() const;
130 
135  bool IsDisplayingDefaultText() const;
136 
142  void SetTextColor(const CYIColor &textColor);
143 
149  const CYIColor &GetTextColor() const;
150 
154  void SetFontSize(int32_t size);
155 
161  size_t GetFontSize() const;
162 
170  void SetCaretColor(const CYIColor &clrCaret);
171 
177  const CYIColor &GetCaretColor() const;
178 
182  size_t GetCaretPosition() const;
183 
187  void SetCaretPosition(size_t position);
188 
192  void DeactivateCaret();
193 
197  void ActivateCaret();
198 
203 
210 
214  void SetMaximumCharacterCount(size_t maximumCharacterCount);
215 
219  void SetEditingEnabled(bool enable);
220 
226  bool IsEditingEnabled() const;
227 
235  void Activate();
236 
244  void Deactivate();
245 
252  bool IsActivated() const;
253 
257  size_t GetMaximumCharacterCount() const;
258 
264  bool SetTextEntryBoxWidth(float boxWidth);
265 
271  float GetTextEntryBoxWidth() const;
272 
276  float GetInitialTextEntryBoxWidth() const;
277 
283  void SetXJustify(Justification xJustify);
284 
289  Justification GetXJustify() const;
290 
295 
301 
307 
314 
321 
326 
333 
338 
343  bool SetAccessoryImageUrl(const CYIUrl &url);
344 
349  const CYIUrl &GetAccessoryImageUrl() const;
350 
351  virtual const CYISceneView::AssetRequirement *GetAssetRequirements(uint32_t *pRequirementCount) override;
352 
357  virtual bool HandleEvent(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent) override;
358 
370  void EnablePasswordMode(bool passwordModeEnabled);
371 
377  bool IsPasswordModeEnabled() const;
378 
386  void SetMaskCharacter(char32_t maskCharacter);
387 
393  char32_t GetMaskCharacter() const;
394 
403  void SetCharacterShowDuration(uint64_t timeMs);
404 
410  uint64_t GetCharacterShowDuration() const;
411 
415  CYISignal<const CYIString & /*currentText*/, const CYIString & /*previousText*/> TextChanged;
416 
421 
426 
427  /*
428  \details Triggered when the return key is pressed.
429  */
431 
432 protected:
436  virtual void UpdateTextView();
437 
441  void UpdateTextView(const CYIString &currentText);
442 
446  bool OnKeyDownWhenActive(CYIKeyEvent *pEvent);
447 
451  bool OnKeyInputWhenActive(CYIKeyEvent *pEvent);
452 
456  virtual bool OnCharWhenActive(CYIKeyEvent *pEvent);
457 
461  void OnCaretBlink();
462 
468  void OnActivated();
469 
473  void OnDeactivated();
474 
478  void ShowKeyboard();
479 
485  void OnTextChanged(bool notifyKeyboard);
486 
491 
495  void ResetCaretBlinkTimer();
496 
501  void SetCaretPositionInString(float localSpaceX, float localSpaceY, int8_t caretOffset = 0);
502 
506  void OnClearButtonClicked();
507 
511  void UpdateClearButton();
512 
516  void UpdateTextSpan(bool updateTextOffset);
517 
524  void InitInputSettings();
525 
532 
536  float GetTextWidth(uint32_t position);
537 
542  void OnScrollTimerEvent();
543 
548  void StartScrolling();
549 
553  void StopScrolling();
554 
559 
564 
565  virtual bool OnTextEntered(const CYIString &pText, int32_t caret);
566  virtual bool OnTextDeleted(int32_t beforeCaret, int32_t afterCaret);
567  virtual void OnTextReplaced(const CYIString &text, size_t cursor);
568  virtual void OnCursorPositionChanged(size_t cursor);
569 
573  bool OnKeyboardHidden();
574 
579 
583  virtual void WorldSurfaceScaleUpdated() override;
584 
588  virtual void UpdateBegin() override;
589 
593  virtual void UpdateEnd() override;
594 
600  void HideLastCharacter();
601 
605  CYIString GetMaskedText(const CYIString &text, bool showLastChar) const;
606 
608  std::unique_ptr<CYITimelineLoop> m_pCaretBlinkTimelineLoop;
614  std::unique_ptr<CYITimer> m_pScrollTimer;
615  CYIString m_CurrentText;
616  CYIString m_PreviousText;
617  CYIString m_DefaultText;
634 
637 
638  float m_caretMaxX;
641 
642  std::shared_ptr<CYIAssetTexture> m_DefaultCaretTexture;
643  std::unique_ptr<CYITextEditReceiver> m_pReceiver;
644 
647  CYIString m_maskCharacter;
648 
649 private:
650  enum class SetCaretPositionSource : uint8_t
651  {
652  InternalCall,
653  KeyboardInputBridge
654  };
655 
656  bool HandleEventWhenActive(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent);
657  bool HandleEventWhenInactive(const std::shared_ptr<CYIEventDispatcher> &pDispatcher, CYIEvent *pEvent);
658 
659  bool TabKeyPressed(const CYIKeyEvent *pKeyEvent);
660 
661  void DoScrolling(bool isMouseEvent);
662  void NotifyKeyboardOnTextChange();
663  void NotifyKeyboardOnCursorPositionWillChange();
664  void NotifyKeyboardOnCursorPositionChanged();
665 
666  void SetBasicCaretPosition(size_t logicalPosition, bool alignedCharacterMustBeVisible, SetCaretPositionSource callSource);
667  void SetCaretPosition(size_t logicalPosition, bool alignWithPreviousCharacter, SetCaretPositionSource callSource);
668  void SetCaretPosition(CYITextEngine::PositionInString position, SetCaretPositionSource callSource);
669 
670  CYITextLayout::TextDirection GetEffectiveTextDirection();
671 
674 };
675 
678 #endif // _YI_TEXT_EDIT_VIEW_H_
void ActivateCaret()
void SetCharacterShowDuration(uint64_t timeMs)
void SetMaskCharacter(char32_t maskCharacter)
bool IsDisplayingDefaultText() const
void InitInputSettings()
void DoScrollingForTimerEvent()
CYITextEngine::PositionInString m_posInString
Definition: YiTextEditView.h:628
void SetReturnKeyType(CYIKeyboardInputBridge::ReturnKeyType keyType)
CYIKeyboardInputBridge::InputType GetInputType() const
CYISignal< CYITextEditView * > Activated
Definition: YiTextEditView.h:420
ClearButtonMode GetClearButtonMode() const
CYIColor m_DefaultTextColor
Definition: YiTextEditView.h:618
virtual void OnTextReplaced(const CYIString &text, size_t cursor)
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:69
CYIColor m_CaretColor
Definition: YiTextEditView.h:620
const CYIString & GetDefaultText() const
Justification
Definition: YiTextEditView.h:67
CYITextLayout::TextDirection m_defaultTextDirection
Definition: YiTextEditView.h:633
const CYIColor & GetDefaultTextColor() const
size_t m_maximumCharacterCount
Definition: YiTextEditView.h:630
void SetInputModifiers(CYIKeyboardInputBridge::InputModifiers inputModifiers)
Class for key events.
Definition: YiKeyEvent.h:16
void SetDefaultText(const CYIString &defaultText, bool cropToMaxCharacterCount=true)
bool m_activated
Definition: YiTextEditView.h:624
bool SetTextEntryBoxWidth(float boxWidth)
std::shared_ptr< CYIAssetTexture > m_DefaultCaretTexture
Definition: YiTextEditView.h:642
void SetMaximumCharacterCount(size_t maximumCharacterCount)
Base class for events.
Definition: YiEvent.h:28
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
CYIKeyboardInputBridge::ReturnKeyType GetReturnKeyType() const
void SetEditingEnabled(bool enable)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:32
void SetTextColor(const CYIColor &textColor)
void SetCaretPositionInString(float localSpaceX, float localSpaceY, int8_t caretOffset=0)
CYISignal< const CYIString &, const CYIString &> TextChanged
Definition: YiTextEditView.h:415
const CYIColor & GetTextColor() const
size_t m_lengthOfValueString
Definition: YiTextEditView.h:627
bool OnKeyboardHidden()
ReturnKeyType
The preferred return key type.
Definition: YiKeyboardInputBridge.h:87
A texture asset representing an image which will be loaded into the GPU.
Definition: YiAssetTexture.h:21
size_t GetMaximumCharacterCount() const
const CYIColor & GetCaretColor() const
CYIString m_maskCharacter
Definition: YiTextEditView.h:647
glm::vec3 m_scrollMouseLocalSpaceLocation
Definition: YiTextEditView.h:636
bool m_updateText
Definition: YiTextEditView.h:622
CYITextSceneNode * m_pTextNode
Definition: YiTextEditView.h:611
virtual bool Init() override
void DoScrollingForMouseEvent()
Justification m_xJustify
Definition: YiTextEditView.h:640
void OnDeactivated()
size_t GetFontSize() const
void StartScrolling()
void SetXJustify(Justification xJustify)
void ResetCaretBlinkTimer()
bool IsEditingEnabled() const
Definition: YiSceneView.h:76
TextDirection
Enumeration for direction types used in text layout.
Definition: YiTextLayout.h:28
bool m_alignedCharacterMustBeVisible
Definition: YiTextEditView.h:629
uint64_t GetCharacterShowDuration() const
void OnClearButtonClicked()
void SetFontSize(int32_t size)
ClearButtonMode m_clearButtonMode
Definition: YiTextEditView.h:621
CYISceneNode * m_pCaretNode
Definition: YiTextEditView.h:609
CYIString m_PreviousText
Definition: YiTextEditView.h:616
float GetInitialTextEntryBoxWidth() const
CYIPushButtonView * m_pClearBtn
Definition: YiTextEditView.h:612
void UpdateClearButton()
char32_t GetMaskCharacter() const
void SetClearButtonMode(ClearButtonMode mode)
CYISignal< CYITextEditView * > ReturnKeyPressed
Definition: YiTextEditView.h:430
CYIKeyboardInputBridge::InputModifiers m_inputModifiers
Definition: YiTextEditView.h:632
friend class CYITextEditViewPriv
Definition: YiTextEditView.h:65
CYITimer m_lastCharacterShowTimer
Definition: YiTextEditView.h:646
A low-precision timer driven by the update loop.
Definition: YiTimer.h:27
bool m_maskingEnabled
Definition: YiTextEditView.h:645
CYITimer m_CaretTimer
Definition: YiTextEditView.h:607
bool OnKeyInputWhenActive(CYIKeyEvent *pEvent)
float GetTextEntryBoxWidth() const
const CYIUrl & GetAccessoryImageUrl() const
virtual bool HandleEvent(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent) override
CYISceneNode * m_pEntryFieldNode
Definition: YiTextEditView.h:613
CYIKeyboardInputBridge::InputModifiers GetInputModifiers() const
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:105
void HideLastCharacter()
void DeactivateCaret()
A scene node type that renders text.
Definition: YiTextSceneNode.h:79
virtual ~CYITextEditView()
CYISceneNode * m_pSecondaryCaretNode
Definition: YiTextEditView.h:610
std::unique_ptr< CYITimelineLoop > m_pCaretBlinkTimelineLoop
Definition: YiTextEditView.h:608
bool m_editingEnabled
Definition: YiTextEditView.h:623
virtual bool OnTextEntered(const CYIString &pText, int32_t caret)
float GetTextWidth(uint32_t position)
virtual void WorldSurfaceScaleUpdated() override
bool SetAccessoryImageUrl(const CYIUrl &url)
virtual CYIString GetValue() const
A class used to encapsulate an URL.
Definition: YiUrl.h:24
CYITextLayout::TextDirection GetDefaultTextDirection() const
Displays text to the user and allows them to edit it.
Definition: YiTextEditView.h:61
Definition: YiTextEngine.h:117
bool m_caretActive
Definition: YiTextEditView.h:625
virtual void OnCursorPositionChanged(size_t cursor)
float m_initialCaretMaxX
Definition: YiTextEditView.h:639
void SetCaretPosition(size_t position)
virtual void UpdateBegin() override
virtual void UpdateTextView()
bool InitDefaultTextFromProperty()
bool m_placeholderTextMode
Definition: YiTextEditView.h:626
void SetDefaultTextDirection(CYITextLayout::TextDirection direction)
bool IsActivated() const
CYIString m_CurrentText
Definition: YiTextEditView.h:615
virtual bool OnTextDeleted(int32_t beforeCaret, int32_t afterCaret)
void UpdateCaretNodePositionAndTextOffset()
void OnSynchronizeKeyboard(CYIKeyboardInputBridge::Receiver::Description &receiverDescription)
InputModifiers
The preferred modifiers for the platform keyboard.
Definition: YiKeyboardInputBridge.h:104
void OnScrollTimerEvent()
void SetValue(CYIString text)
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:259
Provides details to the system software keyboard.
Definition: YiKeyboardInputBridge.h:140
friend class CYITextEditReceiver
Definition: YiTextEditView.h:64
size_t GetCaretPosition() const
Justification GetXJustify() const
Repeats a timeline.
Definition: YiTimelineLoop.h:20
glm::vec2 m_scrollMouseLocationDown
Definition: YiTextEditView.h:635
virtual void UpdateEnd() override
CYIKeyboardInputBridge::InputType m_inputType
Definition: YiTextEditView.h:631
A class used to represent a color value.
Definition: YiColor.h:35
std::unique_ptr< CYITextEditReceiver > m_pReceiver
Definition: YiTextEditView.h:643
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:614
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:169
CYIString m_DefaultText
Definition: YiTextEditView.h:617
CYIString GetMaskedText(const CYIString &text, bool showLastChar) const
void SetInputType(CYIKeyboardInputBridge::InputType inputType)
float m_caretMaxX
Definition: YiTextEditView.h:638
ClearButtonMode
Definition: YiTextEditView.h:76
CYISignal< CYITextEditView * > Deactivated
Definition: YiTextEditView.h:425
void SetDefaultTextColor(const CYIColor &defaultTextColor)
void UpdateTextSpan(bool updateTextOffset)
InputType
The preferred input type.
Definition: YiKeyboardInputBridge.h:41
void SetCaretColor(const CYIColor &clrCaret)
CYIColor m_TextColor
Definition: YiTextEditView.h:619
void EnablePasswordMode(bool passwordModeEnabled)
void StopScrolling()
bool IsPasswordModeEnabled() const