summaryrefslogtreecommitdiff
path: root/scene/gui/text_edit.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/text_edit.h')
-rw-r--r--scene/gui/text_edit.h154
1 files changed, 75 insertions, 79 deletions
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 437e22ca40..e38d484b0d 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -30,19 +30,18 @@
#define TEXT_EDIT_H
#include "scene/gui/control.h"
-#include "scene/gui/scroll_bar.h"
#include "scene/gui/popup_menu.h"
+#include "scene/gui/scroll_bar.h"
#include "scene/main/timer.h"
+class TextEdit : public Control {
-class TextEdit : public Control {
-
- GDCLASS( TextEdit, Control );
+ GDCLASS(TextEdit, Control);
struct Cursor {
int last_fit_x;
- int line,column; ///< cursor
- int x_ofs,line_ofs;
+ int line, column; ///< cursor
+ int x_ofs, line_ofs;
} cursor;
struct Selection {
@@ -55,14 +54,13 @@ class TextEdit : public Control {
};
Mode selecting_mode;
- int selecting_line,selecting_column;
+ int selecting_line, selecting_column;
bool selecting_text;
-
bool active;
- int from_line,from_column;
- int to_line,to_column;
+ int from_line, from_column;
+ int to_line, to_column;
bool shiftclick_left;
@@ -113,7 +111,13 @@ class TextEdit : public Control {
String end_key;
bool line_only;
bool eq;
- ColorRegion(const String& p_begin_key="",const String& p_end_key="",const Color &p_color=Color(),bool p_line_only=false) { begin_key=p_begin_key; end_key=p_end_key; color=p_color; line_only=p_line_only || p_end_key==""; eq=begin_key==end_key; }
+ ColorRegion(const String &p_begin_key = "", const String &p_end_key = "", const Color &p_color = Color(), bool p_line_only = false) {
+ begin_key = p_begin_key;
+ end_key = p_end_key;
+ color = p_color;
+ line_only = p_line_only || p_end_key == "";
+ eq = begin_key == end_key;
+ }
};
class Text {
@@ -124,43 +128,42 @@ class TextEdit : public Control {
bool end;
};
- struct Line {
- int width_cache : 24;
- bool marked : 1;
- bool breakpoint : 1;
- Map<int,ColorRegionInfo> region_info;
- String data;
- };
+ struct Line {
+ int width_cache : 24;
+ bool marked : 1;
+ bool breakpoint : 1;
+ Map<int, ColorRegionInfo> region_info;
+ String data;
+ };
+
private:
- const Vector<ColorRegion> *color_regions;
- mutable Vector<Line> text;
- Ref<Font> font;
- int tab_size;
+ const Vector<ColorRegion> *color_regions;
+ mutable Vector<Line> text;
+ Ref<Font> font;
+ int tab_size;
- void _update_line_cache(int p_line) const;
+ void _update_line_cache(int p_line) const;
public:
-
-
void set_tab_size(int p_tab_size);
- void set_font(const Ref<Font>& p_font);
- void set_color_regions(const Vector<ColorRegion>*p_regions) { color_regions=p_regions; }
+ void set_font(const Ref<Font> &p_font);
+ void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; }
int get_line_width(int p_line) const;
int get_max_width() const;
- const Map<int,ColorRegionInfo>& get_color_region_info(int p_line);
- void set(int p_line,const String& p_string);
- void set_marked(int p_line,bool p_marked) { text[p_line].marked=p_marked; }
+ const Map<int, ColorRegionInfo> &get_color_region_info(int p_line);
+ void set(int p_line, const String &p_string);
+ void set_marked(int p_line, bool p_marked) { text[p_line].marked = p_marked; }
bool is_marked(int p_line) const { return text[p_line].marked; }
- void set_breakpoint(int p_line,bool p_breakpoint) { text[p_line].breakpoint=p_breakpoint; }
+ void set_breakpoint(int p_line, bool p_breakpoint) { text[p_line].breakpoint = p_breakpoint; }
bool is_breakpoint(int p_line) const { return text[p_line].breakpoint; }
- void insert(int p_at,const String& p_text);
+ void insert(int p_at, const String &p_text);
void remove(int p_at);
int size() const { return text.size(); }
void clear();
void clear_caches();
- _FORCE_INLINE_ const String& operator[](int p_line) const { return text[p_line].data; }
- Text() { tab_size=4; }
- };
+ _FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
+ Text() { tab_size = 4; }
+ };
struct TextOperation {
@@ -171,7 +174,7 @@ class TextEdit : public Control {
};
Type type;
- int from_line,from_column;
+ int from_line, from_column;
int to_line, to_column;
String text;
uint32_t prev_version;
@@ -183,14 +186,13 @@ class TextEdit : public Control {
TextOperation current_op;
List<TextOperation> undo_stack;
- List<TextOperation>::Element *undo_stack_pos;
+ List<TextOperation>::Element *undo_stack_pos;
void _clear_redo();
- void _do_text_op(const TextOperation& p_op, bool p_reverse);
-
+ void _do_text_op(const TextOperation &p_op, bool p_reverse);
//syntax coloring
- HashMap<String,Color> keywords;
+ HashMap<String, Color> keywords;
Vector<ColorRegion> color_regions;
@@ -260,7 +262,6 @@ class TextEdit : public Control {
VScrollBar *v_scroll;
bool updating_scrolls;
-
Object *tooltip_obj;
StringName tooltip_func;
Variant tooltip_ud;
@@ -281,8 +282,8 @@ class TextEdit : public Control {
int get_char_count();
- int get_char_pos_for(int p_px,String p_pos) const;
- int get_column_x_offset(int p_column,String p_pos);
+ int get_char_pos_for(int p_px, String p_pos) const;
+ int get_column_x_offset(int p_column, String p_pos);
void adjust_viewport_to_cursor();
void _scroll_moved(double);
@@ -311,13 +312,13 @@ class TextEdit : public Control {
/* super internal api, undo/redo builds on it */
- void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column);
- String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const;
- void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
+ void _base_insert_text(int p_line, int p_column, const String &p_text, int &r_end_line, int &r_end_column);
+ String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
+ void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
- PoolVector<int> _search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const;
+ PoolVector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
PopupMenu *menu;
@@ -328,13 +329,12 @@ class TextEdit : public Control {
void _update_completion_candidates();
protected:
+ virtual String get_tooltip(const Point2 &p_pos) const;
- virtual String get_tooltip(const Point2& p_pos) const;
-
- void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL);
- void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
- void _insert_text_at_cursor(const String& p_text);
- void _gui_input(const InputEvent& p_input);
+ void _insert_text(int p_line, int p_column, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL);
+ void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
+ void _insert_text_at_cursor(const String &p_text);
+ void _gui_input(const InputEvent &p_input);
void _notification(int p_what);
void _consume_pair_symbol(CharType ch);
@@ -342,10 +342,7 @@ protected:
static void _bind_methods();
-
-
public:
-
enum MenuItems {
MENU_CUT,
MENU_COPY,
@@ -359,14 +356,14 @@ public:
enum SearchFlags {
- SEARCH_MATCH_CASE=1,
- SEARCH_WHOLE_WORDS=2,
- SEARCH_BACKWARDS=4
+ SEARCH_MATCH_CASE = 1,
+ SEARCH_WHOLE_WORDS = 2,
+ SEARCH_BACKWARDS = 4
};
- virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const;
+ virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
- void _get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const;
+ void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
//void delete_char();
//void delete_line();
@@ -375,16 +372,16 @@ public:
void end_complex_operation();
void set_text(String p_text);
- void insert_text_at_cursor(const String& p_text);
- void insert_at(const String& p_text, int at);
+ void insert_text_at_cursor(const String &p_text);
+ void insert_at(const String &p_text, int at);
int get_line_count() const;
- void set_line_as_marked(int p_line,bool p_marked);
- void set_line_as_breakpoint(int p_line,bool p_breakpoint);
+ void set_line_as_marked(int p_line, bool p_marked);
+ void set_line_as_breakpoint(int p_line, bool p_breakpoint);
bool is_line_set_as_breakpoint(int p_line) const;
void get_breakpoints(List<int> *p_breakpoints) const;
String get_text();
String get_line(int line) const;
- void set_line(int line, String new_text);
+ void set_line(int line, String new_text);
void backspace_at_cursor();
void indent_selection_left();
@@ -398,7 +395,7 @@ public:
auto_brace_completion_enabled = p_enabled;
}
inline void set_brace_matching(bool p_enabled) {
- brace_matching_enabled=p_enabled;
+ brace_matching_enabled = p_enabled;
update();
}
inline void set_callhint_settings(bool below, Vector2 offset) {
@@ -409,8 +406,8 @@ public:
void center_viewport_to_cursor();
- void cursor_set_column(int p_col, bool p_adjust_viewport=true);
- void cursor_set_line(int p_row, bool p_adjust_viewport=true);
+ void cursor_set_column(int p_col, bool p_adjust_viewport = true);
+ void cursor_set_line(int p_row, bool p_adjust_viewport = true);
int cursor_get_column() const;
int cursor_get_line() const;
@@ -438,10 +435,10 @@ public:
void copy();
void paste();
void select_all();
- void select(int p_from_line,int p_from_column,int p_to_line,int p_to_column);
+ void select(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
void deselect();
- void set_search_text(const String& p_search_text);
+ void set_search_text(const String &p_search_text);
void set_search_flags(uint32_t p_flags);
void set_current_search_result(int line, int col);
@@ -455,9 +452,9 @@ public:
String get_selection_text() const;
String get_word_under_cursor() const;
- String get_word_at_pos(const Vector2& p_pos) const;
+ String get_word_at_pos(const Vector2 &p_pos) const;
- bool search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const;
+ bool search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const;
void undo();
void redo();
@@ -470,8 +467,8 @@ public:
void set_insert_mode(bool p_enabled);
bool is_insert_mode() const;
- void add_keyword_color(const String& p_keyword,const Color& p_color);
- void add_color_region(const String& p_begin_key=String(),const String& p_end_key=String(),const Color &p_color=Color(),bool p_line_only=false);
+ void add_keyword_color(const String &p_keyword, const Color &p_color);
+ void add_color_region(const String &p_begin_key = String(), const String &p_end_key = String(), const Color &p_color = Color(), bool p_line_only = false);
void clear_colors();
int get_v_scroll() const;
@@ -500,11 +497,11 @@ public:
void set_breakpoint_gutter_width(int p_gutter_width);
int get_breakpoint_gutter_width() const;
- void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
+ void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
- void set_completion(bool p_enabled,const Vector<String>& p_prefixes);
+ void set_completion(bool p_enabled, const Vector<String> &p_prefixes);
void code_complete(const Vector<String> &p_strings);
- void set_code_hint(const String& p_hint);
+ void set_code_hint(const String &p_hint);
void query_code_comple();
void set_select_identifiers_on_hover(bool p_enable);
@@ -521,5 +518,4 @@ public:
~TextEdit();
};
-
#endif // TEXT_EDIT_H