Btk
textbox.hpp
1 #if !defined(_BTK_TEXTBOX_HPP_)
2 #define _BTK_TEXTBOX_HPP_
3 #include <string>
4 #include <string_view>
5 #include "utils/timer.hpp"
6 #include "widget.hpp"
7 #include "pixels.hpp"
8 #include "themes.hpp"
9 #include "rect.hpp"
10 #include "font.hpp"
11 namespace Btk{
12  class KeyEvent;
13  class BTKAPI TextBox:public Widget{
14  public:
16  TextBox(const TextBox &) = delete;
17  ~TextBox();
18 
19  bool handle(Event &);
20  void draw(Renderer &);
26  std::u16string_view text() const{
27  return tb_text;
28  }
29  std::string u8text() const{
30  std::string s;
31  u8text(s);
32  return s;
33  }
39  void u8text(std::string &str) const;
45  void set_text(std::u16string_view txt);
46  void set_text(std::string_view txt);
47  private:
48  void timeout();
49  //Process keyboard event
50  bool do_keyboard(KeyEvent &event);
51  //Add string in where the cur_text point
52  void add_string(std::string_view);
53  Font tb_font;//Text Font
54  Theme theme;
55 
56  std::u16string tb_text;//Text
57  PixBuf tb_buf;//Rendered text
58  Texture texture;
59 
60  bool has_focus = false;//Flag of has focus
61  bool is_dragging = false;//< Flag of drag
62  bool show_line = true;//<Flag of show the edit line
63 
64  std::u16string::iterator cur_txt;//Current text
65  //It will be point from tb_text.begin() - 1
66  //to tb_text.end() - 1
67  std::u16string::iterator sel_begin;//select text begin
68  std::u16string::iterator sel_end;//select text end
69 
70  Timer timer;//For drawing the line
71  int ft_h;//Rendered Text's h
72  int tb_boarder = 4;//The text boarder
73  friend struct TextBoxInserter;
74  };
75 };
76 
77 
78 #endif // _BTK_TEXTBOX_HPP_
Definition: pixels.hpp:191
Definition: widget.hpp:219
This header include many useful containers.
Definition: async.hpp:7
Definition: themes.hpp:9
Definition: textbox.cpp:19
Font Class.
Definition: font.hpp:26
Definition: timer.hpp:21
Definition: pixels.hpp:32
A event about keyboard.
Definition: event.hpp:171
std::u16string_view text() const
Get TextBox&#39;s text.
Definition: textbox.hpp:26
Definition: textbox.hpp:13
A base event of all events.
Definition: event.hpp:17
A Container of Widget.
Definition: widget.hpp:108