Gosu
TextInput.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/Platform.hpp>
8 #include <memory>
9 #include <string>
10 
11 namespace Gosu
12 {
21  class TextInput
22  {
23  struct Impl;
24  // Non-movable (const) to avoid dangling references to TextInput instances.
25  const std::unique_ptr<Impl> pimpl;
26 
27  public:
28  TextInput();
29  virtual ~TextInput();
30 
31  std::string text() const;
32 
35  void set_text(const std::string& text);
36 
40  unsigned caret_pos() const;
43  void set_caret_pos(unsigned pos);
44 
48  unsigned selection_start() const;
50  void set_selection_start(unsigned pos);
51 
52 #ifndef GOSU_IS_IPHONE
53  // Platform-specific communication with Gosu::Input.
54  bool feed_sdl_event(void* event);
55 #endif
56 
60  virtual std::string filter(std::string text) const
61  {
62  return text;
63  }
64 
68  void insert_text(std::string text);
69 
71  void delete_forward();
72 
74  void delete_backward();
75  };
76 }
Definition: Audio.hpp:12
bool feed_sdl_event(void *event)
void set_text(const std::string &text)
Replaces the current text by the given string and positions the cursor at the end of the text...
unsigned caret_pos() const
Index of the character that comes after the caret.
std::string text() const
void delete_forward()
Deletes the current selection, if any, or the next character.
virtual ~TextInput()
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void set_selection_start(unsigned pos)
Sets the start of the selection as returned by selection_start.
TextInput instances are invisible objects that build a text string from input, using the current oper...
Definition: TextInput.hpp:21
void insert_text(std::string text)
Replaces the current selection (if any) and inserts the given string at the current caret position...
void set_caret_pos(unsigned pos)
Sets the caret position as returned by caret_pos.
virtual std::string filter(std::string text) const
Overridable filter that is applied to all new text that is entered.
Definition: TextInput.hpp:60
unsigned selection_start() const
If there is a selection, the selection_start() member yields its beginning, using the same indexing s...
void delete_backward()
Deletes the current selection, if any, or the previous character.