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
39namespace Pt {
40
41namespace 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
Aligns content along one axis.
Definition Adjustment.h:60
void left()
Moves the caret one character to the left.
void del()
Deletes the character at the caret.
void right()
Moves the caret one character to the right.
Adjustment adjustment() const
Returns the horizontal adjustment of the text.
void insert(Char ch)
Inserts ch at the caret and advances the caret.
void layout(const Painter &painter, TextLine &line)
Lays out displayText() into line using painter.
void setCursorPosition(std::size_t n)
Sets the caret index in the entered text to n.
void layout(const Painter &painter, const Pt::String &text, TextLine &line)
Lays out text into line using painter.
const Pt::String & text() const
Returns the entered text.
const Gfx::PointF & position() const
Returns the top-left position of the line.
void setText(const Pt::String &s)
Sets the entered text to s.
const Pt::String & displayText() const
Returns the text shown for the line.
const Gfx::SizeF & size() const
Returns the size of the line.
void setPosition(const Gfx::PointF &p)
Sets the top-left position of the line to p.
void backspace()
Deletes the character before the caret.
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.
void setAdjustment(Adjustment a)
Sets the horizontal adjustment of the text to a.
void clear()
Clears the entered text, caret, and scroll.
~LineEditor()
Destroys the line editor.
bool isEmpty() const
Returns true if the entered text is empty.
void setMasked(bool m)
Sets whether displayText() shows a mask character per character.
std::size_t cursorPosition() const
Returns the caret index in the entered text.
LineEditor()
Constructs an empty line editor.
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Represents one laid-out line in a TextBlock.
Definition TextBlock.h:58
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33
Unicode character type.
Definition String.h:67