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 
57 {
58  public:
62 
66 
69  const Gfx::PointF& position() const;
70 
73  void setPosition(const Gfx::PointF& p);
74 
77  const Gfx::SizeF& size() const;
78 
81  void setSize(const Gfx::SizeF& s);
82 
86 
90 
93  bool isMasked() const;
94 
97  void setMasked(bool m);
98 
101  const Pt::String& text() const;
102 
105  void setText(const Pt::String& s);
106 
112  const Pt::String& displayText() const;
113 
116  std::size_t cursorPosition() const;
117 
120  void setCursorPosition(std::size_t n);
121 
124  bool isEmpty() const;
125 
128  void clear();
129 
132  void insert(Char ch);
133 
136  void left();
137 
140  void right();
141 
144  void del();
145 
148  void backspace();
149 
152  void layout(const Painter& painter, TextLine& line);
153 
156  void layout(const Painter& painter, const Pt::String& text, TextLine& line);
157 
158  private:
159  Gfx::PointF _position;
160  Gfx::SizeF _size;
161  Adjustment _adjustment;
162  bool _isMasked;
163  Pt::String _text;
164  Pt::String _displayText;
165  std::size_t _cursorPosition;
166  double _scrollOffset;
167 };
168 
169 } // namespace
170 
171 } // namespace
172 
173 #endif
const Pt::String & text() const
Returns the entered text.
Core module.
Definition: Allocator.h:33
void setCursorPosition(std::size_t n)
Sets the caret index in the entered text to n.
Single-line text, caret, and scroll helper.
Definition: LineEditor.h:57
void layout(const Painter &painter, TextLine &line)
Lays out displayText() into line using painter.
const Gfx::PointF & position() const
Returns the top-left position of the line.
void setPosition(const Gfx::PointF &p)
Sets the top-left position of the line to p.
bool isEmpty() const
Returns true if the entered text is empty.
void insert(Char ch)
Inserts ch at the caret and advances the caret.
void setMasked(bool m)
Sets whether displayText() shows a mask character per character.
void del()
Deletes the character at the caret.
Draws on a Forms paint surface or paint context.
Definition: Painter.h:53
void backspace()
Deletes the character before the caret.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Adjustment adjustment() const
Returns the horizontal adjustment of the text.
const Gfx::SizeF & size() const
Returns the size of the line.
Unicode character type.
Definition: String.h:67
void setText(const Pt::String &s)
Sets the entered text to s.
void clear()
Clears the entered text, caret, and scroll.
void left()
Moves the caret one character to the left.
std::size_t cursorPosition() const
Returns the caret index in the entered text.
LineEditor()
Constructs an empty line editor.
Aligns content along one axis.
Definition: Adjustment.h:60
void layout(const Painter &painter, const Pt::String &text, TextLine &line)
Lays out text into line using painter.
Unicode capable basic_string.
Definition: Api-String.h:44
bool isMasked() const
Returns true if displayText() shows a mask character per character.
void setSize(const Gfx::SizeF &s)
Sets the size of the line to s.
~LineEditor()
Destroys the line editor.
void setAdjustment(Adjustment a)
Sets the horizontal adjustment of the text to a.
void right()
Moves the caret one character to the right.
const Pt::String & displayText() const
Returns the text shown for the line.
Represents one laid-out line in a TextBlock.
Definition: TextBlock.h:58