text_field_view.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29 #pragma once
30
31 #include "../View/view.h"
32 #include "label_view.h"
33
34 namespace clan
35 {
36 class Font;
37 class TextFieldViewImpl;
38
39 class TextFieldView : public View
40 {
41 public:
42 TextFieldView();
43 ~TextFieldView();
44
45 std::string text() const;
46 void set_text(const std::string &value);
47
48 std::string placeholder() const;
49 void set_placeholder(const std::string &value);
50
51 TextAlignment text_alignment() const;
52 void set_text_alignment(TextAlignment value);
53
54 bool is_read_only() const;
55 void set_read_only(bool value = true);
56
57 bool is_lowercase() const;
58 void set_lowercase(bool value = true);
59
60 bool is_uppercase() const;
61 void set_uppercase(bool value = true);
62
63 bool is_password_mode() const;
64 void set_password_mode(bool value = true);
65
66 int max_length() const;
67 void set_max_length(int length);
68
69 std::string selection() const;
70 size_t selection_start() const;
71 size_t selection_length() const;
72 void set_selection(size_t pos, size_t length);
73 void clear_selection();
74 void delete_selected_text();
75 void select_all();
76 void set_select_all_on_focus_gain(bool value);
77
78 int cursor_pos() const;
79 void set_cursor_pos(int pos);
80 void set_cursor_drawing_enabled(bool value);
81
82 int text_int() const;
83 void set_text(int number);
84
85 float text_float() const;
86 void set_text(float number, int num_decimal_places = 6);
87
88 void set_numeric_mode(bool enable = true, bool decimals = false);
89 void set_input_mask(const std::string &mask);
90 void set_decimal_character(const std::string &decimal_char);
91
92 Signal<void(KeyEvent &)> &sig_before_edit_changed();
93 Signal<void(KeyEvent &)> &sig_after_edit_changed();
94 Signal<void()> &sig_selection_changed();
95 Signal<void()> &sig_enter_pressed();
96
97 void render_content(Canvas &canvas) override;
98 float get_preferred_width(Canvas &canvas) override;
99 float get_preferred_height(Canvas &canvas, float width) override;
100 float get_first_baseline_offset(Canvas &canvas, float width) override;
101 float get_last_baseline_offset(Canvas &canvas, float width) override;
102
103 private:
104 std::unique_ptr<TextFieldViewImpl> impl;
105 };
106 }
clan::TextFieldView::set_password_mode
void set_password_mode(bool value=true)
clan
Definition: clanapp.h:35
clan::View
View for an area of the user interface.
Definition: view.h:61
clan::Canvas
2D Graphics Canvas
Definition: canvas.h:72
clan::TextFieldView::get_first_baseline_offset
float get_first_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the first baseline.
clan::TextFieldView::selection_start
size_t selection_start() const
clan::TextFieldView::set_text
void set_text(const std::string &value)
clan::TextFieldView::sig_after_edit_changed
Signal< void(KeyEvent &)> & sig_after_edit_changed()
clan::TextFieldView::set_uppercase
void set_uppercase(bool value=true)
clan::TextFieldView::get_last_baseline_offset
float get_last_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the last baseline.
clan::TextFieldView::is_uppercase
bool is_uppercase() const
clan::TextFieldView::placeholder
std::string placeholder() const
clan::TextFieldView::set_cursor_pos
void set_cursor_pos(int pos)
clan::TextFieldView::set_lowercase
void set_lowercase(bool value=true)
clan::TextFieldView::set_decimal_character
void set_decimal_character(const std::string &decimal_char)
clan::TextFieldView::sig_before_edit_changed
Signal< void(KeyEvent &)> & sig_before_edit_changed()
clan::TextFieldView::sig_enter_pressed
Signal< void()> & sig_enter_pressed()
clan::TextFieldView::is_password_mode
bool is_password_mode() const
clan::TextFieldView::set_read_only
void set_read_only(bool value=true)
clan::TextFieldView::get_preferred_height
float get_preferred_height(Canvas &canvas, float width) override
Calculates the preferred height of this view.
clan::StyleTokenType::string
@ keyword
clan::TextFieldView
Definition: text_field_view.h:39
clan::TextFieldView::select_all
void select_all()
clan::TextFieldView::get_preferred_width
float get_preferred_width(Canvas &canvas) override
Calculates the preferred width of this view.
clan::StyleTokenType::number
Hash
clan::TextFieldView::set_numeric_mode
void set_numeric_mode(bool enable=true, bool decimals=false)
clan::TextFieldView::set_max_length
void set_max_length(int length)
clan::TextFieldView::is_lowercase
bool is_lowercase() const
clan::TextFieldView::set_text_alignment
void set_text_alignment(TextAlignment value)
clan::TextFieldView::selection
std::string selection() const
clan::TextFieldView::render_content
void render_content(Canvas &canvas) override
Renders the content of a view.
clan::TextFieldView::clear_selection
void clear_selection()
clan::Signal
Definition: signal.h:104
clan::StyleValueType::length
value is a keyword
clan::TextFieldView::set_select_all_on_focus_gain
void set_select_all_on_focus_gain(bool value)
clan::TextFieldView::delete_selected_text
void delete_selected_text()
clan::TextFieldView::is_read_only
bool is_read_only() const
clan::TextFieldView::set_cursor_drawing_enabled
void set_cursor_drawing_enabled(bool value)
clan::TextFieldView::text
std::string text() const
clan::TextFieldView::set_placeholder
void set_placeholder(const std::string &value)
clan::TextAlignment
TextAlignment
Definition: label_view.h:37
clan::TextFieldView::~TextFieldView
~TextFieldView()
clan::TextFieldView::text_int
int text_int() const
clan::TextFieldView::text_float
float text_float() const
clan::TextFieldView::set_input_mask
void set_input_mask(const std::string &mask)
clan::TextFieldView::text_alignment
TextAlignment text_alignment() const
clan::TextFieldView::TextFieldView
TextFieldView()
clan::TextFieldView::sig_selection_changed
Signal< void()> & sig_selection_changed()
clan::TextFieldView::max_length
int max_length() const
clan::TextFieldView::cursor_pos
int cursor_pos() const
clan::TextFieldView::selection_length
size_t selection_length() const
clan::TextFieldView::set_selection
void set_selection(size_t pos, size_t length)