Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
text_entry.h
1 #pragma once
2 
3 #include "widget.h"
4 #include "../../generic/managed.h"
5 
6 namespace smlt {
7 namespace ui {
8 
9 class TextEntry:
10  public Widget,
11  public RefCounted<TextEntry> {
12 
13 public:
14  using Widget::init; // Pull in init to satisfy Managed<TextEntry>
15  using Widget::clean_up;
16 
17  TextEntry(
18  UIManager* owner,
19  UIConfig* config,
20  Stage* stage,
21  std::shared_ptr<WidgetStyle> shared_style=std::shared_ptr<WidgetStyle>()
22  );
23 
24  /* Inserts a character at the caret position */
25  void insert_character(uint16_t c);
26 
27  /* Deletes the character before the caret, returns
28  * false if the caret was at position 0 */
29  bool backspace_character();
30 
31  /* Moves the caret 1 character left, returns false if
32  * the caret was already at position 0 */
33  bool caret_left();
34 
35  /* Moves the caret 1 character right, returns false if
36  * the caret was already at the last character position */
37  bool caret_right();
38 
39 private:
40  /* This is the character position of the caret. 0 means it's before the
41  * first character */
42  uint16_t caret_position_ = 0;
43 
44  /* If true, then set_text won't update the caret position */
45  bool freeze_caret_ = false;
46 
47  /* The caret is rendered using the foreground layer. Usually 1px wide and the
48  * same height as the font. The position will depend on the caret_position_
49  * and the text */
50  virtual WidgetBounds calculate_foreground_size(const UIDim& content_dimensions) const override;
51 
52  virtual bool pre_set_text(const unicode&) override;
53 };
54 
55 }
56 }
smlt::ui::UIManager
Definition: ui_manager.h:55
smlt::Stage
Definition: stage.h:80
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::ui::Widget
Definition: widget.h:85
smlt::ui::UIConfig
Definition: ui_config.h:244
unicode
Definition: unicode.h:36
smlt::ui::TextEntry
Definition: text_entry.h:11
smlt::ui::Widget::WidgetBounds
Definition: widget.h:293
smlt::ui::UIDim
Definition: ui_config.h:192