text_field_view.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 uicore
35 {
36  class Font;
37  class TextFieldBaseViewImpl;
38 
39  class TextFieldBaseView : public View
40  {
41  public:
44 
45  int preferred_size() const;
46  void set_preferred_size(int num_characters);
47 
48  std::string text() const;
49  void set_text(const std::string &value);
50 
51  std::string placeholder() const;
52  void set_placeholder(const std::string &value);
53 
56 
57  bool is_read_only() const;
58  void set_read_only(bool value = true);
59 
60  bool is_lowercase() const;
61  void set_lowercase(bool value = true);
62 
63  bool is_uppercase() const;
64  void set_uppercase(bool value = true);
65 
66  bool is_password_mode() const;
67  void set_password_mode(bool value = true);
68 
69  int max_length() const;
70  void set_max_length(int length);
71 
72  std::string selection() const;
73  size_t selection_start() const;
74  size_t selection_length() const;
75  void set_selection(size_t pos, size_t length);
76  void clear_selection();
77  void delete_selected_text();
78  void select_all();
79  void set_select_all_on_focus_gain(bool value);
80 
81  int cursor_pos() const;
82  void set_cursor_pos(int pos);
83  void set_cursor_drawing_enabled(bool value);
84 
85  int text_int() const;
86  void set_text(int number);
87 
88  float text_float() const;
89  void set_text(float number, int num_decimal_places = 6);
90 
91  void set_numeric_mode(bool enable = true, bool decimals = false);
92  void set_input_mask(const std::string &mask);
93  void set_decimal_character(const std::string &decimal_char);
94 
99 
100  protected:
101  void render_content(const CanvasPtr &canvas) override;
102  float calculate_preferred_width(const CanvasPtr &canvas) override;
103  float calculate_preferred_height(const CanvasPtr &canvas, float width) override;
104  float calculate_first_baseline_offset(const CanvasPtr &canvas, float width) override;
105  float calculate_last_baseline_offset(const CanvasPtr &canvas, float width) override;
106 
107  private:
108  std::unique_ptr<TextFieldBaseViewImpl> impl;
109  };
110 }
size_t selection_length() const
void set_select_all_on_focus_gain(bool value)
float calculate_preferred_height(const CanvasPtr &canvas, float width) override
Calculates the preferred height of this view.
void set_input_mask(const std::string &mask)
float calculate_first_baseline_offset(const CanvasPtr &canvas, float width) override
Calculates the offset to the first baseline.
float calculate_preferred_width(const CanvasPtr &canvas) override
Calculates the preferred width of this view.
CanvasPtr canvas() const
void set_text_alignment(TextAlignment value)
void render_content(const CanvasPtr &canvas) override
Renders the content of a view.
bool is_password_mode() const
void set_cursor_pos(int pos)
void set_selection(size_t pos, size_t length)
std::string selection() const
Signal< void(KeyEvent *)> & sig_before_edit_changed()
void set_lowercase(bool value=true)
TextAlignment
Definition: label_view.h:37
Signal< void(KeyEvent *)> & sig_after_edit_changed()
void set_decimal_character(const std::string &decimal_char)
void set_numeric_mode(bool enable=true, bool decimals=false)
bool is_uppercase() const
size_t selection_start() const
Definition: text_field_view.h:39
float calculate_last_baseline_offset(const CanvasPtr &canvas, float width) override
Calculates the offset to the last baseline.
float text_float() const
bool is_lowercase() const
Definition: signal.h:101
void set_read_only(bool value=true)
bool is_read_only() const
std::string text() const
void set_uppercase(bool value=true)
View for an area of the user interface.
Definition: view.h:68
void set_preferred_size(int num_characters)
Signal< void()> & sig_selection_changed()
void set_max_length(int length)
TextAlignment text_alignment() const
void set_cursor_drawing_enabled(bool value)
std::shared_ptr< Canvas > CanvasPtr
Definition: canvas.h:126
void set_text(const std::string &value)
void set_placeholder(const std::string &value)
std::string placeholder() const
void set_password_mode(bool value=true)
Definition: Application/application.h:35
Signal< void(KeyEvent *)> & sig_enter_pressed()