diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/graph_node.cpp | 20 | ||||
-rw-r--r-- | scene/gui/graph_node.h | 6 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 27 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 21 |
5 files changed, 50 insertions, 26 deletions
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 8730be0c06..bef0808fd0 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -270,7 +270,7 @@ void GraphNode::_notification(int p_what) { } } - if (resizeable) { + if (resizable) { draw_texture(resizer, get_size() - resizer->get_size()); } } @@ -594,7 +594,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Ref<Texture> resizer = get_icon("resizer"); - if (resizeable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { + if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { resizing = true; resizing_from = mpos; @@ -645,15 +645,15 @@ bool GraphNode::is_comment() const { return comment; } -void GraphNode::set_resizeable(bool p_enable) { +void GraphNode::set_resizable(bool p_enable) { - resizeable = p_enable; + resizable = p_enable; update(); } -bool GraphNode::is_resizeable() const { +bool GraphNode::is_resizable() const { - return resizeable; + return resizable; } void GraphNode::_bind_methods() { @@ -678,8 +678,8 @@ void GraphNode::_bind_methods() { ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment); ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment); - ClassDB::bind_method(D_METHOD("set_resizeable", "resizeable"), &GraphNode::set_resizeable); - ClassDB::bind_method(D_METHOD("is_resizeable"), &GraphNode::is_resizeable); + ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable); + ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable); ClassDB::bind_method(D_METHOD("set_selected", "selected"), &GraphNode::set_selected); ClassDB::bind_method(D_METHOD("is_selected"), &GraphNode::is_selected); @@ -702,7 +702,7 @@ void GraphNode::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizeable"), "set_resizeable", "is_resizeable"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable"); ADD_SIGNAL(MethodInfo("offset_changed")); ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to"))); @@ -722,7 +722,7 @@ GraphNode::GraphNode() { connpos_dirty = true; set_mouse_filter(MOUSE_FILTER_STOP); comment = false; - resizeable = false; + resizable = false; resizing = false; selected = false; } diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 416d711aab..a606e47acd 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -68,7 +68,7 @@ private: bool show_close; Vector2 offset; bool comment; - bool resizeable; + bool resizable; bool resizing; Vector2 resizing_from; @@ -151,8 +151,8 @@ public: void set_comment(bool p_enable); bool is_comment() const; - void set_resizeable(bool p_enable); - bool is_resizeable() const; + void set_resizable(bool p_enable); + bool is_resizable() const; virtual Size2 get_minimum_size() const; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index a3f116c883..e51955ed66 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -80,6 +80,10 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { return NULL; } +Rect2 RichTextLabel::_get_text_rect() { + Ref<StyleBox> style = get_stylebox("normal"); + return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); +} void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) { RID ci; @@ -583,7 +587,7 @@ void RichTextLabel::_update_scroll() { int total_height = 0; if (main->lines.size()) - total_height = main->lines[main->lines.size() - 1].height_accum_cache; + total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; bool exceeds = total_height > get_size().height && scroll_active; @@ -641,7 +645,11 @@ void RichTextLabel::_notification(int p_what) { _update_scroll(); RID ci = get_canvas_item(); + Size2 size = get_size(); + Rect2 text_rect = _get_text_rect(); + + draw_style_box(get_stylebox("normal"), Rect2(Point2(), size)); if (has_focus()) { VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); @@ -657,10 +665,10 @@ void RichTextLabel::_notification(int p_what) { int total_chars = 0; while (from_line < main->lines.size()) { - if (main->lines[from_line].height_accum_cache >= ofs) + if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) break; - from_line++; total_chars += main->lines[from_line].char_count; + from_line++; } if (from_line >= main->lines.size()) @@ -672,7 +680,7 @@ void RichTextLabel::_notification(int p_what) { while (y < size.height && from_line < main->lines.size()) { - _process_line(main, Point2(), y, size.width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, Point2i(), NULL, NULL, NULL, total_chars); + _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, Point2i(), NULL, NULL, NULL, total_chars); total_chars += main->lines[from_line].char_count; from_line++; } @@ -686,7 +694,7 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item *r_click_item = NULL; Size2 size = get_size(); - + Rect2 text_rect = _get_text_rect(); int ofs = vscroll->get_value(); //todo, change to binary search @@ -706,9 +714,9 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item Ref<Font> base_font = get_font("normal_font"); Color base_color = get_color("default_color"); - while (y < size.height && from_line < p_frame->lines.size()) { + while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) { - _process_line(p_frame, Point2(), y, size.width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, p_click, r_click_item, r_click_char, r_outside); + _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, p_click, r_click_item, r_click_char, r_outside); if (r_click_item && *r_click_item) return; from_line++; @@ -1015,13 +1023,14 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { //validate invalid lines!s Size2 size = get_size(); + Rect2 text_rect = _get_text_rect(); Ref<Font> base_font = get_font("normal_font"); for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) { int y = 0; - _process_line(p_frame, Point2(), y, size.width - scroll_w, i, PROCESS_CACHE, base_font, Color()); + _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, i, PROCESS_CACHE, base_font, Color()); p_frame->lines[i].height_cache = y; p_frame->lines[i].height_accum_cache = y; @@ -1031,7 +1040,7 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { int total_height = 0; if (p_frame->lines.size()) - total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache; + total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; main->first_invalid_line = p_frame->lines.size(); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 74bf180b5d..4db2c3a8e9 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -276,6 +276,8 @@ private: void _gui_input(Ref<InputEvent> p_event); Item *_get_next_item(Item *p_item, bool p_free = false); + Rect2 _get_text_rect(); + bool use_bbcode; String bbcode; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index ade665b418..1738e303aa 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2136,15 +2136,25 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { break; } } - if (auto_indent) { - // indent once again if previous line will end with ':' - // (i.e. colon precedes current cursor position) - if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') { + + bool brace_indent = false; + + // no need to indent if we are going upwards. + if (auto_indent && !(k->get_command() && k->get_shift())) { + // indent once again if previous line will end with ':' or '{' + // (i.e. colon/brace precedes current cursor position) + if (cursor.column > 0 && (text[cursor.line][cursor.column - 1] == ':' || text[cursor.line][cursor.column - 1] == '{')) { if (indent_using_spaces) { ins += space_indent; } else { ins += "\t"; } + + // no need to move the brace below if we are not taking the text with us. + if (text[cursor.line][cursor.column] == '}' && !k->get_command()) { + brace_indent = true; + ins += "\n" + ins.substr(1, ins.length() - 2); + } } } @@ -2168,6 +2178,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (first_line) { cursor_set_line(0); + } else if (brace_indent) { + cursor_set_line(cursor.line - 1); + cursor_set_column(text[cursor.line].length()); } } break; |