LineEditor.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_LineEditor_H
30 #define Pt_Forms_LineEditor_H
31 
32 #include <Pt/Forms/Adjustment.h>
33 #include <Pt/Forms/TextBlock.h>
34 #include <Pt/Gfx/Font.h>
35 #include <Pt/Gfx/Size.h>
36 #include <Pt/Gfx/Point.h>
37 #include <Pt/String.h>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class LineEditor
44 {
45  public:
46  LineEditor();
47 
48  ~LineEditor();
49 
50  const Gfx::PointF& position() const;
51 
52  void setPosition(const Gfx::PointF& p);
53 
54  const Gfx::SizeF& size() const;
55 
56  void setSize(const Gfx::SizeF& s);
57 
58  Adjustment adjustment() const;
59 
60  void setAdjustment(Adjustment a);
61 
62  bool isMasked() const;
63 
64  void setMasked(bool m);
65 
66  const Pt::String& text() const;
67 
68  void setText(const Pt::String& s);
69 
70  const Pt::String& displayText() const;
71 
72  std::size_t cursorPosition() const;
73 
74  void setCursorPosition(std::size_t n);
75 
76  bool isEmpty() const;
77 
78  void clear();
79 
80  void insert(Char ch);
81 
82  void left();
83 
84  void right();
85 
86  void del();
87 
88  void backspace();
89 
90  void layout(Gfx::Painter& painter, TextLine& line);
91 
92  void layout(Gfx::Painter& painter, const Pt::String& text, TextLine& line);
93 
94  private:
95  Gfx::PointF _position;
96  Gfx::SizeF _size;
97  Adjustment _adjustment;
98  bool _isMasked;
99  Pt::String _text;
100  Pt::String _displayText;
101  std::size_t _cursorPosition;
102  double _scrollOffset;
103 };
104 
105 } // namespace
106 
107 } // namespace
108 
109 #endif
Unicode capable basic_string.
Definition: String.h:42