summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp32
-rw-r--r--scene/gui/box_container.cpp46
-rw-r--r--scene/gui/button.cpp68
-rw-r--r--scene/gui/center_container.cpp18
-rw-r--r--scene/gui/check_box.cpp17
-rw-r--r--scene/gui/check_button.cpp14
-rw-r--r--scene/gui/color_picker.cpp97
-rw-r--r--scene/gui/container.cpp21
-rw-r--r--scene/gui/control.cpp224
-rw-r--r--scene/gui/control.h3
-rw-r--r--scene/gui/dialogs.cpp21
-rw-r--r--scene/gui/file_dialog.cpp93
-rw-r--r--scene/gui/gradient_edit.cpp39
-rw-r--r--scene/gui/graph_edit.cpp117
-rw-r--r--scene/gui/graph_node.cpp138
-rw-r--r--scene/gui/grid_container.cpp38
-rw-r--r--scene/gui/item_list.cpp88
-rw-r--r--scene/gui/label.cpp61
-rw-r--r--scene/gui/line_edit.cpp183
-rw-r--r--scene/gui/link_button.cpp5
-rw-r--r--scene/gui/margin_container.cpp21
-rw-r--r--scene/gui/menu_button.cpp9
-rw-r--r--scene/gui/nine_patch_rect.cpp9
-rw-r--r--scene/gui/option_button.cpp33
-rw-r--r--scene/gui/panel_container.cpp30
-rw-r--r--scene/gui/popup.cpp12
-rw-r--r--scene/gui/popup_menu.cpp148
-rw-r--r--scene/gui/range.cpp24
-rw-r--r--scene/gui/reference_rect.cpp6
-rw-r--r--scene/gui/rich_text_label.cpp330
-rw-r--r--scene/gui/scroll_bar.cpp57
-rw-r--r--scene/gui/scroll_container.cpp76
-rw-r--r--scene/gui/shortcut.cpp5
-rw-r--r--scene/gui/slider.cpp34
-rw-r--r--scene/gui/spin_box.cpp9
-rw-r--r--scene/gui/split_container.cpp63
-rw-r--r--scene/gui/subviewport_container.cpp49
-rw-r--r--scene/gui/tab_container.cpp161
-rw-r--r--scene/gui/tabs.cpp94
-rw-r--r--scene/gui/text_edit.cpp729
-rw-r--r--scene/gui/texture_button.cpp42
-rw-r--r--scene/gui/texture_progress.cpp66
-rw-r--r--scene/gui/tree.cpp426
-rw-r--r--scene/gui/video_player.cpp65
44 files changed, 2484 insertions, 1337 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 79e1102f6b..d8229b5f43 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -35,24 +35,27 @@
#include "scene/scene_string_names.h"
void BaseButton::_unpress_group() {
- if (!button_group.is_valid())
+ if (!button_group.is_valid()) {
return;
+ }
if (toggle_mode) {
status.pressed = true;
}
for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
- if (E->get() == this)
+ if (E->get() == this) {
continue;
+ }
E->get()->set_pressed(false);
}
}
void BaseButton::_gui_input(Ref<InputEvent> p_event) {
- if (status.disabled) // no interaction with disabled button
+ if (status.disabled) { // no interaction with disabled button
return;
+ }
Ref<InputEventMouseButton> mouse_button = p_event;
bool ui_accept = p_event->is_action("ui_accept") && !p_event->is_echo();
@@ -183,8 +186,9 @@ void BaseButton::toggled(bool p_pressed) {
}
void BaseButton::set_disabled(bool p_disabled) {
- if (status.disabled == p_disabled)
+ if (status.disabled == p_disabled) {
return;
+ }
status.disabled = p_disabled;
if (p_disabled) {
@@ -203,10 +207,12 @@ bool BaseButton::is_disabled() const {
}
void BaseButton::set_pressed(bool p_pressed) {
- if (!toggle_mode)
+ if (!toggle_mode) {
return;
- if (status.pressed == p_pressed)
+ }
+ if (status.pressed == p_pressed) {
return;
+ }
_change_notify("pressed");
status.pressed = p_pressed;
@@ -236,8 +242,9 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
};
if (!status.press_attempt && status.hovering) {
- if (status.pressed)
+ if (status.pressed) {
return DRAW_HOVER_PRESSED;
+ }
return DRAW_HOVER;
} else {
@@ -246,16 +253,18 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
bool pressing;
if (status.press_attempt) {
pressing = (status.pressing_inside || keep_pressed_outside);
- if (status.pressed)
+ if (status.pressed) {
pressing = !pressing;
+ }
} else {
pressing = status.pressed;
}
- if (pressing)
+ if (pressing) {
return DRAW_PRESSED;
- else
+ } else {
return DRAW_NORMAL;
+ }
}
return DRAW_NORMAL;
@@ -451,8 +460,9 @@ Array ButtonGroup::_get_buttons() {
BaseButton *ButtonGroup::get_pressed_button() {
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- if (E->get()->is_pressed())
+ if (E->get()->is_pressed()) {
return E->get();
+ }
}
return nullptr;
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 5252f3f2f2..75d04dba61 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -54,10 +54,12 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
_MinSizeCache msc;
@@ -82,8 +84,9 @@ void BoxContainer::_resort() {
children_count++;
}
- if (children_count == 0)
+ if (children_count == 0) {
return;
+ }
int stretch_max = (vertical ? new_size.height : new_size.width) - (children_count - 1) * sep;
int stretch_diff = stretch_max - stretch_min;
@@ -104,10 +107,12 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
ERR_FAIL_COND(!min_size_cache.has(c));
_MinSizeCache &msc = min_size_cache[c];
@@ -131,8 +136,9 @@ void BoxContainer::_resort() {
}
}
- if (refit_successful) //uf refit went well, break
+ if (refit_successful) { //uf refit went well, break
break;
+ }
}
/** Final pass, draw and stretch elements **/
@@ -156,17 +162,20 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
_MinSizeCache &msc = min_size_cache[c];
- if (first)
+ if (first) {
first = false;
- else
+ } else {
ofs += sep;
+ }
int from = ofs;
int to = ofs + msc.final_size;
@@ -205,10 +214,12 @@ Size2 BoxContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (!c->is_visible()) {
continue;
@@ -263,14 +274,16 @@ void BoxContainer::add_spacer(bool p_begin) {
Control *c = memnew(Control);
c->set_mouse_filter(MOUSE_FILTER_PASS); //allow spacer to pass mouse events
- if (vertical)
+ if (vertical) {
c->set_v_size_flags(SIZE_EXPAND_FILL);
- else
+ } else {
c->set_h_size_flags(SIZE_EXPAND_FILL);
+ }
add_child(c);
- if (p_begin)
+ if (p_begin) {
move_child(c, 0);
+ }
}
BoxContainer::BoxContainer(bool p_vertical) {
@@ -298,8 +311,9 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control
mc->add_theme_constant_override("margin_left", 0);
mc->add_child(p_control);
add_child(mc);
- if (p_expand)
+ if (p_expand) {
mc->set_v_size_flags(SIZE_EXPAND_FILL);
+ }
return mc;
}
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index e761b2bf40..e400801b66 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -35,21 +35,24 @@
Size2 Button::get_minimum_size() const {
Size2 minsize = get_theme_font("font")->get_string_size(xl_text);
- if (clip_text)
+ if (clip_text) {
minsize.width = 0;
+ }
if (!expand_icon) {
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
if (!_icon.is_null()) {
minsize.height = MAX(minsize.height, _icon->get_height());
minsize.width += _icon->get_width();
- if (xl_text != "")
+ if (xl_text != "") {
minsize.width += get_theme_constant("hseparation");
+ }
}
}
@@ -78,23 +81,28 @@ void Button::_notification(int p_what) {
switch (get_draw_mode()) {
case DRAW_NORMAL: {
style = get_theme_stylebox("normal");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_normal"))
+ if (has_theme_color("icon_color_normal")) {
color_icon = get_theme_color("icon_color_normal");
+ }
} break;
case DRAW_HOVER_PRESSED: {
if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) {
style = get_theme_stylebox("hover_pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_hover_pressed"))
+ }
+ if (has_theme_color("font_color_hover_pressed")) {
color = get_theme_color("font_color_hover_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_hover_pressed"))
+ }
+ if (has_theme_color("icon_color_hover_pressed")) {
color_icon = get_theme_color("icon_color_hover_pressed");
+ }
break;
}
@@ -102,32 +110,39 @@ void Button::_notification(int p_what) {
}
case DRAW_PRESSED: {
style = get_theme_stylebox("pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_pressed"))
+ }
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_pressed"))
+ }
+ if (has_theme_color("icon_color_pressed")) {
color_icon = get_theme_color("icon_color_pressed");
+ }
} break;
case DRAW_HOVER: {
style = get_theme_stylebox("hover");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_hover");
- if (has_theme_color("icon_color_hover"))
+ if (has_theme_color("icon_color_hover")) {
color_icon = get_theme_color("icon_color_hover");
+ }
} break;
case DRAW_DISABLED: {
style = get_theme_stylebox("disabled");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_disabled");
- if (has_theme_color("icon_color_disabled"))
+ if (has_theme_color("icon_color_disabled")) {
color_icon = get_theme_color("icon_color_disabled");
+ }
} break;
}
@@ -139,10 +154,11 @@ void Button::_notification(int p_what) {
Ref<Font> font = get_theme_font("font");
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
Rect2 icon_region = Rect2();
if (!_icon.is_null()) {
@@ -159,8 +175,9 @@ void Button::_notification(int p_what) {
if (expand_icon) {
Size2 _size = get_size() - style->get_offset() * 2;
_size.width -= get_theme_constant("hseparation") + icon_ofs_region;
- if (!clip_text)
+ if (!clip_text) {
_size.width -= get_theme_font("font")->get_string_size(xl_text).width;
+ }
float icon_width = _icon->get_width() * _size.height / _icon->get_height();
float icon_height = _size.height;
@@ -196,8 +213,9 @@ void Button::_notification(int p_what) {
text_ofs.y += style->get_offset().y;
} break;
case ALIGN_CENTER: {
- if (text_ofs.x < 0)
+ if (text_ofs.x < 0) {
text_ofs.x = 0;
+ }
text_ofs += icon_ofs;
text_ofs += style->get_offset();
} break;
@@ -222,8 +240,9 @@ void Button::_notification(int p_what) {
}
void Button::set_text(const String &p_text) {
- if (text == p_text)
+ if (text == p_text) {
return;
+ }
text = p_text;
xl_text = tr(p_text);
update();
@@ -236,8 +255,9 @@ String Button::get_text() const {
}
void Button::set_icon(const Ref<Texture2D> &p_icon) {
- if (icon == p_icon)
+ if (icon == p_icon) {
return;
+ }
icon = p_icon;
update();
_change_notify("icon");
diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp
index ff2b5ea17e..f8f9bec3d7 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -31,17 +31,21 @@
#include "center_container.h"
Size2 CenterContainer::get_minimum_size() const {
- if (use_top_left)
+ if (use_top_left) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
@@ -70,10 +74,12 @@ void CenterContainer::_notification(int p_what) {
Size2 size = get_size();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index 8681b9bda7..df6f38f65d 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -39,14 +39,18 @@ Size2 CheckBox::get_icon_size() const {
Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked");
Size2 tex_size = Size2(0, 0);
- if (!checked.is_null())
+ if (!checked.is_null()) {
tex_size = Size2(checked->get_width(), checked->get_height());
- if (!unchecked.is_null())
+ }
+ if (!unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, unchecked->get_width()), MAX(tex_size.height, unchecked->get_height()));
- if (!radio_checked.is_null())
+ }
+ if (!radio_checked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_checked->get_width()), MAX(tex_size.height, radio_checked->get_height()));
- if (!radio_unchecked.is_null())
+ }
+ if (!radio_unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_unchecked->get_width()), MAX(tex_size.height, radio_unchecked->get_height()));
+ }
return tex_size;
}
@@ -77,10 +81,11 @@ void CheckBox::_notification(int p_what) {
ofs.x = sb->get_margin(MARGIN_LEFT);
ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index 041a28a0be..1ddc730dd1 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -37,10 +37,12 @@ Size2 CheckButton::get_icon_size() const {
Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
Size2 tex_size = Size2(0, 0);
- if (!on.is_null())
+ if (!on.is_null()) {
tex_size = Size2(on->get_width(), on->get_height());
- if (!off.is_null())
+ }
+ if (!off.is_null()) {
tex_size = Size2(MAX(tex_size.width, off->get_width()), MAX(tex_size.height, off->get_height()));
+ }
return tex_size;
}
@@ -49,8 +51,9 @@ Size2 CheckButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
- if (get_text().length() > 0)
+ if (get_text().length() > 0) {
minsize.width += get_theme_constant("hseparation");
+ }
Ref<StyleBox> sb = get_theme_stylebox("normal");
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM));
@@ -73,10 +76,11 @@ void CheckButton::_notification(int p_what) {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT));
ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index f150028c47..88710289c7 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -65,17 +65,20 @@ void ColorPicker::_notification(int p_what) {
#endif
} break;
case NOTIFICATION_PARENTED: {
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
set_margin((Margin)i, get_theme_constant("margin"));
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
Popup *p = Object::cast_to<Popup>(get_parent());
- if (p)
+ if (p) {
p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2));
+ }
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
- if (screen != nullptr && screen->is_visible())
+ if (screen != nullptr && screen->is_visible()) {
screen->hide();
+ }
} break;
}
}
@@ -89,11 +92,13 @@ void ColorPicker::_update_controls() {
const char *hsv[3] = { "H", "S", "V" };
if (hsv_mode_enabled) {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(hsv[i]);
+ }
} else {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(rgb[i]);
+ }
}
if (hsv_mode_enabled) {
@@ -127,8 +132,9 @@ void ColorPicker::_set_pick_color(const Color &p_color, bool p_update_sliders) {
last_hsv = color;
}
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color(p_update_sliders);
}
@@ -141,8 +147,9 @@ void ColorPicker::set_edit_alpha(bool p_show) {
edit_alpha = p_show;
_update_controls();
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color();
sample->update();
@@ -153,8 +160,9 @@ bool ColorPicker::is_editing_alpha() const {
}
void ColorPicker::_value_changed(double) {
- if (updating)
+ if (updating) {
return;
+ }
if (hsv_mode_enabled) {
color.set_hsv(scroll[0]->get_value() / 360.0,
@@ -172,16 +180,19 @@ void ColorPicker::_value_changed(double) {
}
void ColorPicker::_html_entered(const String &p_html) {
- if (updating || text_is_constructor || !c_text->is_visible())
+ if (updating || text_is_constructor || !c_text->is_visible()) {
return;
+ }
float last_alpha = color.a;
color = Color::html(p_html);
- if (!is_editing_alpha())
+ if (!is_editing_alpha()) {
color.a = last_alpha;
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
set_pick_color(color);
emit_signal("color_changed", color);
@@ -209,8 +220,9 @@ void ColorPicker::_update_color(bool p_update_sliders) {
if (raw_mode_enabled) {
scroll[i]->set_step(0.01);
scroll[i]->set_max(100);
- if (i == 3)
+ if (i == 3) {
scroll[i]->set_max(1);
+ }
scroll[i]->set_value(color.components[i]);
} else {
scroll[i]->set_step(1);
@@ -309,14 +321,17 @@ PackedColorArray ColorPicker::get_presets() const {
}
void ColorPicker::set_hsv_mode(bool p_enabled) {
- if (hsv_mode_enabled == p_enabled || raw_mode_enabled)
+ if (hsv_mode_enabled == p_enabled || raw_mode_enabled) {
return;
+ }
hsv_mode_enabled = p_enabled;
- if (btn_hsv->is_pressed() != p_enabled)
+ if (btn_hsv->is_pressed() != p_enabled) {
btn_hsv->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
@@ -327,14 +342,17 @@ bool ColorPicker::is_hsv_mode() const {
}
void ColorPicker::set_raw_mode(bool p_enabled) {
- if (raw_mode_enabled == p_enabled || hsv_mode_enabled)
+ if (raw_mode_enabled == p_enabled || hsv_mode_enabled) {
return;
+ }
raw_mode_enabled = p_enabled;
- if (btn_raw->is_pressed() != p_enabled)
+ if (btn_raw->is_pressed() != p_enabled) {
btn_raw->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
@@ -356,10 +374,11 @@ void ColorPicker::_update_text_value() {
bool visible = true;
if (text_is_constructor) {
String t = "Color(" + String::num(color.r) + ", " + String::num(color.g) + ", " + String::num(color.b);
- if (edit_alpha && color.a < 1)
+ if (edit_alpha && color.a < 1) {
t += ", " + String::num(color.a) + ")";
- else
+ } else {
t += ")";
+ }
c_text->set_text(t);
}
@@ -389,8 +408,9 @@ void ColorPicker::_sample_draw() {
}
void ColorPicker::_hsv_draw(int p_which, Control *c) {
- if (!c)
+ if (!c) {
return;
+ }
if (p_which == 0) {
Vector<Point2> points;
points.push_back(Vector2());
@@ -446,8 +466,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
} else if (deferred_mode_enabled && !bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
changing_color = false;
@@ -459,8 +480,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float x = CLAMP((float)mev->get_position().x, 0, uv_edit->get_size().width);
float y = CLAMP((float)mev->get_position().y, 0, uv_edit->get_size().height);
s = x / uv_edit->get_size().width;
@@ -469,8 +491,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
@@ -489,25 +512,28 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
- else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT)
+ } else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
+ }
}
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
h = y / w_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
@@ -543,8 +569,9 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
if (preset->get_size().x != 0) {
index /= preset->get_size().x;
}
- if (index < 0 || index >= presets.size())
+ if (index < 0 || index >= presets.size()) {
return;
+ }
preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
}
}
@@ -559,8 +586,9 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
Viewport *r = get_tree()->get_root();
- if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
+ if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y))) {
return;
+ }
Ref<Image> img = r->get_texture()->get_data();
if (img.is_valid() && !img->empty()) {
@@ -615,15 +643,17 @@ void ColorPicker::_focus_enter() {
void ColorPicker::_focus_exit() {
for (int i = 0; i < 4; i++) {
- if (!values[i]->get_line_edit()->get_menu()->is_visible())
+ if (!values[i]->get_line_edit()->get_menu()->is_visible()) {
values[i]->get_line_edit()->select(0, 0);
+ }
}
c_text->select(0, 0);
}
void ColorPicker::_html_focus_exit() {
- if (c_text->get_menu()->is_visible())
+ if (c_text->get_menu()->is_visible()) {
return;
+ }
_html_entered(c_text->get_text());
_focus_exit();
}
@@ -889,8 +919,9 @@ void ColorPickerButton::_notification(int p_what) {
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
- if (popup)
+ if (popup) {
popup->hide();
+ }
} break;
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 5bde293648..18a84ce348 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -43,8 +43,9 @@ void Container::add_child_notify(Node *p_child) {
Control::add_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->connect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->connect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -57,8 +58,9 @@ void Container::add_child_notify(Node *p_child) {
void Container::move_child_notify(Node *p_child) {
Control::move_child_notify(p_child);
- if (!Object::cast_to<Control>(p_child))
+ if (!Object::cast_to<Control>(p_child)) {
return;
+ }
minimum_size_changed();
queue_sort();
@@ -68,8 +70,9 @@ void Container::remove_child_notify(Node *p_child) {
Control::remove_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->disconnect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->disconnect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -80,8 +83,9 @@ void Container::remove_child_notify(Node *p_child) {
}
void Container::_sort_children() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
notification(NOTIFICATION_SORT_CHILDREN);
emit_signal(SceneStringNames::get_singleton()->sort_children);
@@ -117,8 +121,9 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
}
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
p_child->set_anchor(Margin(i), ANCHOR_BEGIN);
+ }
p_child->set_position(r.position);
p_child->set_size(r.size);
@@ -127,11 +132,13 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
void Container::queue_sort() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (pending_sort)
+ if (pending_sort) {
return;
+ }
MessageQueue::get_singleton()->push_call(this, "_sort_children");
pending_sort = true;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 02be8f23fb..96aaec6ae9 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -160,8 +160,9 @@ Size2 Control::_edit_get_minimum_size() const {
#endif
void Control::set_custom_minimum_size(const Size2 &p_custom) {
- if (p_custom == data.custom_minimum_size)
+ if (p_custom == data.custom_minimum_size) {
return;
+ }
data.custom_minimum_size = p_custom;
minimum_size_changed();
}
@@ -176,14 +177,16 @@ void Control::_update_minimum_size_cache() {
minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
bool size_changed = false;
- if (data.minimum_size_cache != minsize)
+ if (data.minimum_size_cache != minsize) {
size_changed = true;
+ }
data.minimum_size_cache = minsize;
data.minimum_size_valid = true;
- if (size_changed)
+ if (size_changed) {
minimum_size_changed();
+ }
}
Size2 Control::get_combined_minimum_size() const {
@@ -245,8 +248,9 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else
+ } else {
return false;
+ }
} else {
if (name.begins_with("custom_icons/")) {
@@ -267,15 +271,17 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_theme_constant_override(dname, p_value);
- } else
+ } else {
return false;
+ }
}
return true;
}
void Control::_update_minimum_size() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Size2 minsize = get_combined_minimum_size();
if (minsize.x > data.size_cache.x ||
@@ -321,8 +327,9 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
String name = sname.get_slicec('/', 1);
r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
- } else
+ } else {
return false;
+ }
return true;
}
@@ -343,8 +350,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_icon_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.icon_override.has(E->get()))
+ if (data.icon_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", hint));
}
@@ -354,8 +362,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_shader_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.shader_override.has(E->get()))
+ if (data.shader_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint));
}
@@ -365,8 +374,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_stylebox_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.style_override.has(E->get()))
+ if (data.style_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint));
}
@@ -376,8 +386,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_font_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_override.has(E->get()))
+ if (data.font_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint));
}
@@ -387,8 +398,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_color_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.color_override.has(E->get()))
+ if (data.color_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint));
}
@@ -398,8 +410,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_constant_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.constant_override.has(E->get()))
+ if (data.constant_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint));
}
@@ -474,8 +487,9 @@ void Control::_notification(int p_notification) {
while (parent) {
parent = parent->get_parent();
- if (!parent)
+ if (!parent) {
break;
+ }
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
if (ci && ci->is_set_as_toplevel()) {
@@ -534,8 +548,9 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the childrens to draw (like TabContainer)
// update if necessary
- if (data.parent)
+ if (data.parent) {
data.parent->update();
+ }
update();
if (data.RI) {
@@ -574,8 +589,9 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
- if (get_viewport() != nullptr)
+ if (get_viewport() != nullptr) {
get_viewport()->_gui_hid_control(this);
+ }
//remove key focus
@@ -613,10 +629,11 @@ bool Control::has_point(const Point2 &p_point) const {
}
void Control::set_drag_forwarding(Control *p_target) {
- if (p_target)
+ if (p_target) {
data.drag_owner = p_target->get_instance_id();
- else
+ } else {
data.drag_owner = ObjectID();
+ }
}
Variant Control::get_drag_data(const Point2 &p_point) {
@@ -633,8 +650,9 @@ Variant Control::get_drag_data(const Point2 &p_point) {
const Variant *p = &v;
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
@@ -654,8 +672,9 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
@@ -676,8 +695,9 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return;
+ }
}
}
@@ -699,8 +719,9 @@ Size2 Control::get_minimum_size() const {
if (si) {
Callable::CallError ce;
Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return s;
+ }
}
return Size2();
}
@@ -793,8 +814,9 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind
Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
- if (tex)
+ if (tex) {
return *tex;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -821,8 +843,9 @@ Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_
Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- if (sdr)
+ if (sdr) {
return *sdr;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -849,8 +872,9 @@ Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_w
Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
- if (style)
+ if (style) {
return *style;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -877,8 +901,9 @@ Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_own
Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Font> *font = data.font_override.getptr(p_name);
- if (font)
+ if (font) {
return *font;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -905,8 +930,9 @@ Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_windo
Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Color *color = data.color_override.getptr(p_name);
- if (color)
+ if (color) {
return *color;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -932,8 +958,9 @@ Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window,
int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const int *constant = data.constant_override.getptr(p_name);
- if (constant)
+ if (constant) {
return *constant;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -988,8 +1015,9 @@ bool Control::has_theme_constant_override(const StringName &p_name) const {
bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_icon_override(p_name))
+ if (has_theme_icon_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1012,8 +1040,9 @@ bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, co
bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_shader_override(p_name))
+ if (has_theme_shader_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1036,8 +1065,9 @@ bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window,
bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_stylebox_override(p_name))
+ if (has_theme_stylebox_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1060,8 +1090,9 @@ bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window
bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_font_override(p_name))
+ if (has_theme_font_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1084,8 +1115,9 @@ bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, co
bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_color_override(p_name))
+ if (has_theme_color_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1108,8 +1140,9 @@ bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, c
bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_constant_override(p_name))
+ if (has_theme_constant_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1131,8 +1164,9 @@ bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window
}
Rect2 Control::get_parent_anchorable_rect() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return Rect2();
+ }
Rect2 parent_rect;
if (data.parent_canvas_item) {
@@ -1623,10 +1657,12 @@ void Control::_set_size(const Size2 &p_size) {
void Control::set_size(const Size2 &p_size, bool p_keep_margins) {
Size2 new_size = p_size;
Size2 min = get_combined_minimum_size();
- if (new_size.x < min.x)
+ if (new_size.x < min.x) {
new_size.x = min.x;
- if (new_size.y < min.y)
+ }
+ if (new_size.y < min.y) {
new_size.y = min.y;
+ }
if (p_keep_margins) {
_compute_anchors(Rect2(data.pos_cache, new_size), data.margin, data.anchor);
@@ -1761,15 +1797,17 @@ void Control::add_theme_constant_override(const StringName &p_name, int p_consta
void Control::set_focus_mode(FocusMode p_focus_mode) {
ERR_FAIL_INDEX((int)p_focus_mode, 3);
- if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
+ if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) {
release_focus();
+ }
data.focus_mode = p_focus_mode;
}
static Control *_next_control(Control *p_from) {
- if (p_from->is_set_as_toplevel())
+ if (p_from->is_set_as_toplevel()) {
return nullptr; // can't go above
+ }
Control *parent = Object::cast_to<Control>(p_from->get_parent());
@@ -1781,8 +1819,9 @@ static Control *_next_control(Control *p_from) {
ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
for (int i = (next + 1); i < parent->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(parent->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
return c;
}
@@ -1806,8 +1845,9 @@ Control *Control::find_next_valid_focus() const {
} else {
return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find next child
@@ -1835,22 +1875,26 @@ Control *Control::find_next_valid_focus() const {
if (!next_child) {
next_child = const_cast<Control *>(this);
while (next_child) {
- if (next_child->data.RI)
+ if (next_child->data.RI) {
break;
+ }
next_child = next_child->get_parent_control();
}
}
}
}
- if (next_child == this) // no next control->
+ if (next_child == this) { // no next control->
return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr;
+ }
if (next_child) {
- if (next_child->get_focus_mode() == FOCUS_ALL)
+ if (next_child->get_focus_mode() == FOCUS_ALL) {
return next_child;
+ }
from = next_child;
- } else
+ } else {
break;
+ }
}
return nullptr;
@@ -1860,15 +1904,17 @@ static Control *_prev_control(Control *p_from) {
Control *child = nullptr;
for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
Control *c = Object::cast_to<Control>(p_from->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
child = c;
break;
}
- if (!child)
+ if (!child) {
return p_from;
+ }
//no prev in parent, try the same in parent
return _prev_control(child);
@@ -1889,8 +1935,9 @@ Control *Control::find_prev_valid_focus() const {
} else {
return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find prev child
@@ -1921,11 +1968,13 @@ Control *Control::find_prev_valid_focus() const {
}
}
- if (prev_child == this) // no prev control->
+ if (prev_child == this) { // no prev control->
return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr;
+ }
- if (prev_child->get_focus_mode() == FOCUS_ALL)
+ if (prev_child->get_focus_mode() == FOCUS_ALL) {
return prev_child;
+ }
from = prev_child;
}
@@ -1955,8 +2004,9 @@ void Control::grab_focus() {
void Control::release_focus() {
ERR_FAIL_COND(!is_inside_tree());
- if (!has_focus())
+ if (!has_focus()) {
return;
+ }
get_viewport()->_gui_remove_focus();
update();
@@ -1969,13 +2019,15 @@ bool Control::is_toplevel_control() const {
void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) {
Control *c = Object::cast_to<Control>(p_at);
- if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
+ if (c && c != p_owner && c->data.theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr;
- if (w && w != p_owner_window && w->theme.is_valid()) // has a theme, this can't be propagated
+ if (w && w != p_owner_window && w->theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
for (int i = 0; i < p_at->get_child_count(); i++) {
CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i));
@@ -2013,8 +2065,9 @@ void Control::_theme_changed() {
}
void Control::set_theme(const Ref<Theme> &p_theme) {
- if (data.theme == p_theme)
+ if (data.theme == p_theme) {
return;
+ }
if (data.theme.is_valid()) {
data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed));
@@ -2046,8 +2099,9 @@ void Control::set_theme(const Ref<Theme> &p_theme) {
}
void Control::accept_event() {
- if (is_inside_tree())
+ if (is_inside_tree()) {
get_viewport()->_gui_accept_event();
+ }
}
Ref<Theme> Control::get_theme() const {
@@ -2125,8 +2179,9 @@ NodePath Control::get_focus_previous() const {
Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
ERR_FAIL_INDEX_V((int)p_margin, 4, nullptr);
- if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
+ if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) {
return nullptr;
+ }
if (!data.focus_neighbour[p_margin].is_empty()) {
Control *c = nullptr;
Node *n = get_node(data.focus_neighbour[p_margin]);
@@ -2137,12 +2192,15 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
return nullptr;
}
bool valid = true;
- if (!c->is_visible())
+ if (!c->is_visible()) {
valid = false;
- if (c->get_focus_mode() == FOCUS_NONE)
+ }
+ if (c->get_focus_mode() == FOCUS_NONE) {
valid = false;
- if (valid)
+ }
+ if (valid) {
return c;
+ }
c = c->_get_focus_neighbour(p_margin, p_count + 1);
return c;
@@ -2173,8 +2231,9 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
for (int i = 0; i < 4; i++) {
float d = vdir.dot(points[i]);
- if (d > maxd)
+ if (d > maxd) {
maxd = d;
+ }
}
Node *base = this;
@@ -2182,14 +2241,16 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
while (base) {
Control *c = Object::cast_to<Control>(base);
if (c) {
- if (c->data.RI)
+ if (c->data.RI) {
break;
+ }
}
base = base->get_parent();
}
- if (!base)
+ if (!base) {
return nullptr;
+ }
_window_find_focus_neighbour(vdir, base, points, maxd, dist, &result);
@@ -2197,8 +2258,9 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
}
void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest) {
- if (Object::cast_to<Viewport>(p_at))
+ if (Object::cast_to<Viewport>(p_at)) {
return; //bye
+ }
Control *c = Object::cast_to<Control>(p_at);
@@ -2216,8 +2278,9 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
for (int i = 0; i < 4; i++) {
float d = p_dir.dot(points[i]);
- if (d < min)
+ if (d < min) {
min = d;
+ }
}
if (min > (p_min - CMP_EPSILON)) {
@@ -2244,15 +2307,17 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
for (int i = 0; i < p_at->get_child_count(); i++) {
Node *child = p_at->get_child(i);
Control *childc = Object::cast_to<Control>(child);
- if (childc && childc->data.RI)
+ if (childc && childc->data.RI) {
continue; //subwindow, ignore
+ }
_window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
}
}
void Control::set_h_size_flags(int p_flags) {
- if (data.h_size_flags == p_flags)
+ if (data.h_size_flags == p_flags) {
return;
+ }
data.h_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
@@ -2262,15 +2327,17 @@ int Control::get_h_size_flags() const {
}
void Control::set_v_size_flags(int p_flags) {
- if (data.v_size_flags == p_flags)
+ if (data.v_size_flags == p_flags) {
return;
+ }
data.v_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
void Control::set_stretch_ratio(float p_ratio) {
- if (data.expand == p_ratio)
+ if (data.expand == p_ratio) {
return;
+ }
data.expand = p_ratio;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
@@ -2287,16 +2354,18 @@ void Control::grab_click_focus() {
}
void Control::minimum_size_changed() {
- if (!is_inside_tree() || data.block_minimum_size_adjust)
+ if (!is_inside_tree() || data.block_minimum_size_adjust) {
return;
+ }
Control *invalidate = this;
//invalidate cache upwards
while (invalidate && invalidate->data.minimum_size_valid) {
invalidate->data.minimum_size_valid = false;
- if (invalidate->is_set_as_toplevel())
+ if (invalidate->is_set_as_toplevel()) {
break; // do not go further up
+ }
if (!invalidate->data.parent && get_parent()) {
Window *parent_window = Object::cast_to<Window>(get_parent());
if (parent_window && parent_window->is_wrapping_controls()) {
@@ -2306,11 +2375,13 @@ void Control::minimum_size_changed() {
invalidate = invalidate->data.parent;
}
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
- if (data.updating_last_minimum_size)
+ if (data.updating_last_minimum_size) {
return;
+ }
data.updating_last_minimum_size = true;
@@ -2394,10 +2465,12 @@ Vector2 Control::get_pivot_offset() const {
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
// Avoid having 0 scale values, can lead to errors in physics and rendering.
- if (data.scale.x == 0)
+ if (data.scale.x == 0) {
data.scale.x = CMP_EPSILON;
- if (data.scale.y == 0)
+ }
+ if (data.scale.y == 0) {
data.scale.y = CMP_EPSILON;
+ }
update();
_notify_transform();
}
@@ -2415,8 +2488,9 @@ Control *Control::get_root_parent_control() const {
if (c) {
root = c;
- if (c->data.RI || c->is_toplevel_control())
+ if (c->data.RI || c->is_toplevel_control()) {
break;
+ }
}
ci = ci->get_parent_item();
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 5a4c64492b..10d6ad168f 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -132,8 +132,9 @@ public:
private:
struct CComparator {
bool operator()(const Control *p_a, const Control *p_b) const {
- if (p_a->get_canvas_layer() == p_b->get_canvas_layer())
+ if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) {
return p_b->is_greater_than(p_a);
+ }
return p_a->get_canvas_layer() < p_b->get_canvas_layer();
}
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 37d6784e35..c6897fc684 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -100,8 +100,9 @@ void AcceptDialog::_text_entered(const String &p_text) {
}
void AcceptDialog::_ok_pressed() {
- if (hide_on_ok)
+ if (hide_on_ok) {
set_visible(false);
+ }
ok_pressed();
emit_signal("confirmed");
}
@@ -155,8 +156,9 @@ bool AcceptDialog::has_autowrap() {
void AcceptDialog::register_text_enter(Node *p_line_edit) {
ERR_FAIL_NULL(p_line_edit);
LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
- if (line_edit)
+ if (line_edit) {
line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered));
+ }
}
void AcceptDialog::_update_child_rects() {
@@ -173,11 +175,13 @@ void AcceptDialog::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c == bg || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) {
continue;
+ }
c->set_position(cpos);
c->set_size(csize);
@@ -199,11 +203,13 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c->is_set_as_toplevel()) {
continue;
+ }
Size2 cminsize = c->get_combined_minimum_size();
minsize.x = MAX(cminsize.x, minsize.x);
@@ -247,8 +253,9 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin
Button *AcceptDialog::add_cancel(const String &p_cancel) {
String c = p_cancel;
- if (p_cancel == "")
+ if (p_cancel == "") {
c = RTR("Cancel");
+ }
Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed));
return b;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 158662e0fc..be6b542ae1 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -102,8 +102,9 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
}
}
- if (handled)
+ if (handled) {
set_input_as_handled();
+ }
}
}
}
@@ -157,10 +158,11 @@ void FileDialog::_post_popup() {
update_file_list();
invalidated = false;
}
- if (mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_SAVE_FILE) {
file->grab_focus();
- else
+ } else {
tree->grab_focus();
+ }
set_process_unhandled_input(true);
@@ -229,13 +231,15 @@ void FileDialog::_action_pressed() {
break;
}
}
- if (valid)
+ if (valid) {
break;
+ }
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String flt = filters[idx].get_slice(";", 0);
int filterSliceCount = flt.get_slice_count(",");
@@ -280,19 +284,22 @@ void FileDialog::_cancel_pressed() {
}
bool FileDialog::_is_open_should_be_disabled() {
- if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) {
return false;
+ }
TreeItem *ti = tree->get_next_selected(tree->get_root());
while (ti) {
TreeItem *prev_ti = ti;
ti = tree->get_next_selected(tree->get_root());
- if (ti == prev_ti)
+ if (ti == prev_ti) {
break;
+ }
}
// We have something that we can't select?
- if (!ti)
+ if (!ti) {
return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
+ }
Dictionary d = ti->get_metadata(0);
@@ -337,8 +344,9 @@ void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selec
void FileDialog::_tree_selected() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (!d["dir"]) {
@@ -352,15 +360,17 @@ void FileDialog::_tree_selected() {
void FileDialog::_tree_item_activated() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (d["dir"]) {
dir_access->change_dir(d["name"]);
- if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY)
+ if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
file->set_text("");
+ }
call_deferred("_update_file_list");
call_deferred("_update_dir");
} else {
@@ -371,8 +381,9 @@ void FileDialog::_tree_item_activated() {
void FileDialog::update_file_name() {
int idx = filter->get_selected() - 1;
if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
- if (idx == -1)
+ if (idx == -1) {
idx += 1;
+ }
String filter_str = filters[idx];
String file_str = file->get_text();
String base_name = file_str.get_basename();
@@ -399,16 +410,18 @@ void FileDialog::update_file_list() {
String item;
while ((item = dir_access->get_next()) != "") {
- if (item == "." || item == "..")
+ if (item == "." || item == "..") {
continue;
+ }
is_hidden = dir_access->current_is_hidden();
if (show_hidden_files || !is_hidden) {
- if (!dir_access->current_is_dir())
+ if (!dir_access->current_is_dir()) {
files.push_back(item);
- else
+ } else {
dirs.push_back(item);
+ }
}
}
@@ -445,8 +458,9 @@ void FileDialog::update_file_list() {
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String f = filters[idx].get_slice(";", 0);
@@ -488,15 +502,17 @@ void FileDialog::update_file_list() {
d["dir"] = false;
ti->set_metadata(0, d);
- if (file->get_text() == files.front()->get() || match_str == files.front()->get())
+ if (file->get_text() == files.front()->get() || match_str == files.front()->get()) {
ti->select(0);
+ }
}
files.pop_front();
}
- if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr)
+ if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr) {
tree->get_root()->get_children()->select(0);
+ }
}
void FileDialog::_filter_selected(int) {
@@ -514,23 +530,26 @@ void FileDialog::update_filters() {
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
- if (i > 0)
+ if (i > 0) {
all_filters += ", ";
+ }
all_filters += flt;
}
- if (max_filters < filters.size())
+ if (max_filters < filters.size()) {
all_filters += ", ...";
+ }
filter->add_item(RTR("All Recognized") + " (" + all_filters + ")");
}
for (int i = 0; i < filters.size(); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
- if (desc.length())
+ if (desc.length()) {
filter->add_item(String(tr(desc)) + " (" + flt + ")");
- else
+ } else {
filter->add_item("(" + flt + ")");
+ }
}
filter->add_item(RTR("All Files (*)"));
@@ -583,14 +602,16 @@ void FileDialog::set_current_file(const String &p_file) {
int lp = p_file.find_last(".");
if (lp != -1) {
file->select(0, lp);
- if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file))
+ if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
file->grab_focus();
+ }
}
}
void FileDialog::set_current_path(const String &p_path) {
- if (!p_path.size())
+ if (!p_path.size()) {
return;
+ }
int pos = MAX(p_path.find_last("/"), p_path.find_last("\\"));
if (pos == -1) {
set_current_file(p_path);
@@ -617,32 +638,37 @@ void FileDialog::set_file_mode(FileMode p_mode) {
switch (mode) {
case FILE_MODE_OPEN_FILE:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_FILES:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open File(s)"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_DIR:
get_ok()->set_text(RTR("Select Current Folder"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a Directory"));
+ }
makedir->show();
break;
case FILE_MODE_OPEN_ANY:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File or Directory"));
+ }
makedir->show();
break;
case FILE_MODE_SAVE_FILE:
get_ok()->set_text(RTR("Save"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Save a File"));
+ }
makedir->show();
break;
}
@@ -660,8 +686,9 @@ FileDialog::FileMode FileDialog::get_file_mode() const {
void FileDialog::set_access(Access p_access) {
ERR_FAIL_INDEX(p_access, 3);
- if (access == p_access)
+ if (access == p_access) {
return;
+ }
memdelete(dir_access);
switch (p_access) {
case ACCESS_FILESYSTEM: {
@@ -926,12 +953,14 @@ FileDialog::FileDialog() {
set_hide_on_ok(false);
invalidated = true;
- if (register_func)
+ if (register_func) {
register_func(this);
+ }
}
FileDialog::~FileDialog() {
- if (unregister_func)
+ if (unregister_func) {
unregister_func(this);
+ }
memdelete(dir_access);
}
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 1617405dd3..ecd4ad17ea 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -73,8 +73,9 @@ int GradientEdit::_get_point_from_pos(int x) {
}
void GradientEdit::_show_color_picker() {
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
picker->set_pick_color(points[grabbed].color);
Size2 minsize = popup->get_contents_minimum_size();
bool show_above = false;
@@ -178,8 +179,9 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
int pos = -1;
for (int i = 0; i < points.size(); i++) {
- if (points[i].offset < newPoint.offset)
+ if (points[i].offset < newPoint.offset) {
pos = i;
+ }
}
if (pos == -1) {
@@ -248,17 +250,19 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (temp_ofs < smallest_ofs) {
smallest_ofs = temp_ofs;
nearest_point = i;
- if (found)
+ if (found) {
break;
+ }
found = true;
}
}
}
if (found) {
- if (points[nearest_point].offset < newofs)
+ if (points[nearest_point].offset < newofs) {
newofs = points[nearest_point].offset + 0.00001;
- else
+ } else {
newofs = points[nearest_point].offset - 0.00001;
+ }
newofs = CLAMP(newofs, 0, 1);
}
}
@@ -300,8 +304,9 @@ void GradientEdit::_notification(int p_what) {
int w = get_size().x;
int h = get_size().y;
- if (w == 0 || h == 0)
+ if (w == 0 || h == 0) {
return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size
+ }
int total_w = get_size().width - get_size().height - SPACING;
@@ -311,19 +316,21 @@ void GradientEdit::_notification(int p_what) {
//Draw color ramp
Gradient::Point prev;
prev.offset = 0;
- if (points.size() == 0)
+ if (points.size() == 0) {
prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
prev.color = points[0].color; //Extend color of first point to the beginning.
+ }
for (int i = -1; i < points.size(); i++) {
Gradient::Point next;
//If there is no next point
if (i + 1 == points.size()) {
- if (points.size() == 0)
+ if (points.size() == 0) {
next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
next.color = points[i].color; //Extend color of last point to the end.
+ }
next.offset = 1;
} else {
next = points[i + 1];
@@ -424,8 +431,9 @@ Size2 GradientEdit::get_minimum_size() const {
}
void GradientEdit::_color_changed(const Color &p_color) {
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
points.write[grabbed].color = p_color;
update();
emit_signal("ramp_changed");
@@ -447,21 +455,24 @@ void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
Vector<float> GradientEdit::get_offsets() const {
Vector<float> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].offset);
+ }
return ret;
}
Vector<Color> GradientEdit::get_colors() const {
Vector<Color> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].color);
+ }
return ret;
}
void GradientEdit::set_points(Vector<Gradient::Point> &p_points) {
- if (points.size() != p_points.size())
+ if (points.size() != p_points.size()) {
grabbed = -1;
+ }
points.clear();
points = p_points;
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 02363e909c..5489638125 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -52,8 +52,9 @@ GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
}
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- if (is_node_connected(p_from, p_from_port, p_to, p_to_port))
+ if (is_node_connected(p_from, p_from_port, p_to, p_to_port)) {
return OK;
+ }
Connection c;
c.from = p_from;
c.from_port = p_from_port;
@@ -70,8 +71,9 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S
bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port)
+ if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
return true;
+ }
}
return false;
@@ -127,8 +129,9 @@ void GraphEdit::_update_scroll_offset() {
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Point2 pos = gn->get_offset() * zoom;
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
@@ -144,8 +147,9 @@ void GraphEdit::_update_scroll_offset() {
}
void GraphEdit::_update_scroll() {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -154,8 +158,9 @@ void GraphEdit::_update_scroll() {
Rect2 screen;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r;
r.position = gn->get_offset() * zoom;
@@ -169,19 +174,21 @@ void GraphEdit::_update_scroll() {
h_scroll->set_min(screen.position.x);
h_scroll->set_max(screen.position.x + screen.size.x);
h_scroll->set_page(get_size().x);
- if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
+ if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) {
h_scroll->hide();
- else
+ } else {
h_scroll->show();
+ }
v_scroll->set_min(screen.position.y);
v_scroll->set_max(screen.position.y + screen.size.y);
v_scroll->set_page(get_size().y);
- if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
+ if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) {
v_scroll->hide();
- else
+ } else {
v_scroll->show();
+ }
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -301,10 +308,11 @@ void GraphEdit::_notification(int p_what) {
for (int i = from.x; i < from.x + len.x; i++) {
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.x * zoom;
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
@@ -313,10 +321,11 @@ void GraphEdit::_notification(int p_what) {
for (int i = from.y; i < from.y + len.y; i++) {
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.y * zoom;
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
@@ -335,13 +344,15 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
- if (is_in_hot_zone(pos, p_point))
+ if (is_in_hot_zone(pos, p_point)) {
return true;
+ }
}
for (int j = 0; j < gn->get_connection_input_count(); j++) {
@@ -362,8 +373,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Vector2 mpos(mb->get_position().x, mb->get_position().y);
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
@@ -462,8 +474,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Vector2 mpos = mm->get_position();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
if (!connecting_out) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
@@ -526,15 +539,17 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) {
- if (p_control->is_set_as_toplevel() || !p_control->is_visible())
+ if (p_control->is_set_as_toplevel() || !p_control->is_visible()) {
return false;
+ }
if (!p_control->has_point(pos) || p_control->get_mouse_filter() == MOUSE_FILTER_IGNORE) {
//test children
for (int i = 0; i < p_control->get_child_count(); i++) {
Control *subchild = Object::cast_to<Control>(p_control->get_child(i));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, pos - subchild->get_position())) {
return true;
}
@@ -547,13 +562,15 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos)
}
bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
- if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos))
+ if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) {
return false;
+ }
for (int i = 0; i < get_child_count(); i++) {
Control *child = Object::cast_to<Control>(get_child(i));
- if (!child)
+ if (!child) {
continue;
+ }
Rect2 rect = child->get_rect();
if (rect.has_point(p_mouse_pos)) {
//check sub-controls
@@ -561,8 +578,9 @@ bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
for (int j = 0; j < child->get_child_count(); j++) {
Control *subchild = Object::cast_to<Control>(child->get_child(j));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, subpos - subchild->get_position())) {
return false;
@@ -700,10 +718,11 @@ void GraphEdit::_top_layer_draw() {
GraphNode *from = Object::cast_to<GraphNode>(fromn);
ERR_FAIL_COND(!from);
Vector2 pos;
- if (connecting_out)
+ if (connecting_out) {
pos = from->get_connection_output_position(connecting_index);
- else
+ } else {
pos = from->get_connection_input_position(connecting_index);
+ }
pos += from->get_position();
Vector2 topos;
@@ -732,8 +751,9 @@ void GraphEdit::_top_layer_draw() {
void GraphEdit::set_selected(Node *p_child) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
gn->set_selected(gn == p_child);
}
@@ -778,17 +798,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r = gn->get_rect();
r.size *= zoom;
bool in_box = r.intersects(box_selecting_rect);
- if (in_box)
+ if (in_box) {
gn->set_selected(box_selection_mode_additive);
- else
+ } else {
gn->set_selected(previus_selected.find(gn) != nullptr);
+ }
}
top_layer->update();
@@ -801,8 +823,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
box_selecting = false;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
gn->set_selected(previus_selected.find(gn) != nullptr);
}
@@ -826,8 +849,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (gn) {
Rect2 r = gn->get_rect();
r.size *= zoom;
- if (r.has_point(get_local_mouse_position()))
+ if (r.has_point(get_local_mouse_position())) {
gn->set_selected(false);
+ }
}
}
}
@@ -837,8 +861,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (gn && gn->is_selected())
+ if (gn && gn->is_selected()) {
gn->set_drag(false);
+ }
}
emit_signal("_end_node_move");
@@ -858,8 +883,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i));
if (gn_selected) {
- if (gn_selected->is_resizing())
+ if (gn_selected->is_resizing()) {
continue;
+ }
if (gn_selected->has_point(gn_selected->get_local_mouse_position())) {
gn = gn_selected;
@@ -869,8 +895,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (gn) {
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
+ }
dragging = true;
drag_accum = Vector2();
@@ -895,17 +922,21 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
gn->set_selected(true);
for (int i = 0; i < get_child_count(); i++) {
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (!o_gn)
+ if (!o_gn) {
continue;
- if (o_gn->is_selected())
+ }
+ if (o_gn->is_selected()) {
o_gn->set_drag(true);
+ }
}
} else {
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
- if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ }
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
return;
+ }
box_selecting = true;
box_selecting_from = get_local_mouse_position();
@@ -914,8 +945,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
@@ -924,8 +956,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
@@ -934,8 +967,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2)
+ if (!gn2) {
continue;
+ }
if (gn2->is_selected()) {
emit_signal("node_unselected", gn2);
}
@@ -1036,8 +1070,9 @@ void GraphEdit::set_zoom(float p_zoom) {
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
- if (zoom == p_zoom)
+ if (zoom == p_zoom) {
return;
+ }
zoom_minus->set_disabled(zoom == MIN_ZOOM);
zoom_plus->set_disabled(zoom == MAX_ZOOM);
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index c2203364d0..b6a96238dc 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -33,30 +33,33 @@
#include "core/method_bind_ext.gen.inc"
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
- if (!p_name.operator String().begins_with("slot/"))
+ if (!p_name.operator String().begins_with("slot/")) {
return false;
+ }
int idx = p_name.operator String().get_slice("/", 1).to_int();
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
si.enable_left = p_value;
- else if (what == "left_type")
+ } else if (what == "left_type") {
si.type_left = p_value;
- else if (what == "left_color")
+ } else if (what == "left_color") {
si.color_left = p_value;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
si.enable_right = p_value;
- else if (what == "right_type")
+ } else if (what == "right_type") {
si.type_right = p_value;
- else if (what == "right_color")
+ } else if (what == "right_color") {
si.color_right = p_value;
- else
+ } else {
return false;
+ }
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
update();
@@ -72,23 +75,25 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
r_ret = si.enable_left;
- else if (what == "left_type")
+ } else if (what == "left_type") {
r_ret = si.type_left;
- else if (what == "left_color")
+ } else if (what == "left_color") {
r_ret = si.color_left;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
r_ret = si.enable_right;
- else if (what == "right_type")
+ } else if (what == "right_type") {
r_ret = si.type_right;
- else if (what == "right_color")
+ } else if (what == "right_color") {
r_ret = si.color_right;
- else
+ } else {
return false;
+ }
return true;
}
@@ -97,8 +102,9 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
int idx = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c->is_set_as_toplevel())
+ if (!c || c->is_set_as_toplevel()) {
continue;
+ }
String base = "slot/" + itos(idx) + "/";
@@ -122,20 +128,23 @@ void GraphNode::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
int vofs = 0;
@@ -144,10 +153,12 @@ void GraphNode::_resort() {
cache_y.clear();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -228,8 +239,9 @@ void GraphNode::_notification(int p_what) {
int w = get_size().width - sb->get_minimum_size().x;
- if (show_close)
+ if (show_close) {
w -= close->get_width();
+ }
draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
if (show_close) {
@@ -242,10 +254,12 @@ void GraphNode::_notification(int p_what) {
}
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
- if (E->key() < 0 || E->key() >= cache_y.size())
+ if (E->key() < 0 || E->key() >= cache_y.size()) {
continue;
- if (!slot_info.has(E->key()))
+ }
+ if (!slot_info.has(E->key())) {
continue;
+ }
const Slot &s = slot_info[E->key()];
//left
if (s.enable_left) {
@@ -314,38 +328,44 @@ void GraphNode::clear_all_slots() {
}
bool GraphNode::is_slot_enabled_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_left;
}
int GraphNode::get_slot_type_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_left;
}
Color GraphNode::get_slot_color_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_left;
}
bool GraphNode::is_slot_enabled_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_right;
}
int GraphNode::get_slot_type_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_right;
}
Color GraphNode::get_slot_color_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_right;
}
@@ -365,28 +385,32 @@ Size2 GraphNode::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
return minsize + sb->get_minimum_size();
}
void GraphNode::set_title(const String &p_title) {
- if (title == p_title)
+ if (title == p_title) {
return;
+ }
title = p_title;
update();
_change_notify("title");
@@ -417,10 +441,11 @@ bool GraphNode::is_selected() {
}
void GraphNode::set_drag(bool p_drag) {
- if (p_drag)
+ if (p_drag) {
drag_from = get_offset();
- else
+ } else {
emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
+ }
}
Vector2 GraphNode::get_drag_from() {
@@ -449,10 +474,12 @@ void GraphNode::_connpos_update() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -476,8 +503,9 @@ void GraphNode::_connpos_update() {
}
}
- if (vofs > 0)
+ if (vofs > 0) {
vofs += sep;
+ }
vofs += size.y;
idx++;
}
@@ -486,22 +514,25 @@ void GraphNode::_connpos_update() {
}
int GraphNode::get_connection_input_count() {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_input_cache.size();
}
int GraphNode::get_connection_output_count() {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_output_cache.size();
}
Vector2 GraphNode::get_connection_input_position(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
Vector2 pos = conn_input_cache[p_idx].pos;
@@ -511,24 +542,27 @@ Vector2 GraphNode::get_connection_input_position(int p_idx) {
}
int GraphNode::get_connection_input_type(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
return conn_input_cache[p_idx].type;
}
Color GraphNode::get_connection_input_color(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
return conn_input_cache[p_idx].color;
}
Vector2 GraphNode::get_connection_output_position(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
Vector2 pos = conn_output_cache[p_idx].pos;
@@ -538,16 +572,18 @@ Vector2 GraphNode::get_connection_output_position(int p_idx) {
}
int GraphNode::get_connection_output_type(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
return conn_output_cache[p_idx].type;
}
Color GraphNode::get_connection_output_color(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
return conn_output_cache[p_idx].color;
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 1ba761e7a1..2f37461c4d 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -47,22 +47,25 @@ void GridContainer::_notification(int p_what) {
int valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
- if (row_minh.has(row))
+ }
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
if (c->get_h_size_flags() & SIZE_EXPAND) {
col_expanded.insert(col);
@@ -80,13 +83,15 @@ void GridContainer::_notification(int p_what) {
// Evaluate the remaining space for expanded columns/rows.
Size2 remaining_space = get_size();
for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) {
- if (!col_expanded.has(E->key()))
+ if (!col_expanded.has(E->key())) {
remaining_space.width -= E->get();
+ }
}
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
- if (!row_expanded.has(E->key()))
+ if (!row_expanded.has(E->key())) {
remaining_space.height -= E->get();
+ }
}
remaining_space.height -= vsep * MAX(max_row - 1, 0);
remaining_space.width -= hsep * MAX(max_col - 1, 0);
@@ -143,16 +148,18 @@ void GridContainer::_notification(int p_what) {
valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
if (col == 0) {
col_ofs = 0;
- if (row > 0)
+ if (row > 0) {
row_ofs += (row_expanded.has(row - 1) ? row_expand : row_minh[row - 1]) + vsep;
+ }
}
Point2 p(col_ofs, row_ofs);
@@ -201,22 +208,25 @@ Size2 GridContainer::get_minimum_size() const {
int valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
+ }
- if (row_minh.has(row))
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
max_col = MAX(col, max_col);
max_row = MAX(row, max_row);
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 06a4534e22..54150d130d 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -268,8 +268,9 @@ void ItemList::unselect(int p_idx) {
}
void ItemList::unselect_all() {
- if (items.size() < 1)
+ if (items.size() < 1) {
return;
+ }
for (int i = 0; i < items.size(); i++) {
items.write[i].selected = false;
@@ -287,9 +288,9 @@ bool ItemList::is_selected(int p_idx) const {
void ItemList::set_current(int p_current) {
ERR_FAIL_INDEX(p_current, items.size());
- if (select_mode == SELECT_SINGLE)
+ if (select_mode == SELECT_SINGLE) {
select(p_current, true);
- else {
+ } else {
current = p_current;
update();
}
@@ -410,12 +411,14 @@ Size2 ItemList::get_fixed_icon_size() const {
}
Size2 ItemList::Item::get_icon_size() const {
- if (icon.is_null())
+ if (icon.is_null()) {
return Size2();
+ }
Size2 size_result = Size2(icon_region.size).abs();
- if (icon_region.size.x == 0 || icon_region.size.y == 0)
+ if (icon_region.size.x == 0 || icon_region.size.y == 0) {
size_result = icon->get_size();
+ }
if (icon_transposed) {
Size2 size_tmp = size_result;
@@ -482,8 +485,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
for (int j = from; j <= to; j++) {
bool selected = !items[j].selected;
select(j, false);
- if (selected)
+ if (selected) {
emit_signal("multi_selected", j, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
@@ -505,8 +509,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (!selected || allow_reselect) {
if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected", i);
- } else
+ } else {
emit_signal("multi_selected", i, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
@@ -677,19 +682,22 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = current + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (current == 0 || current == -1)
+ if (current == 0 || current == -1) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == current)
+ if (i == current) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
set_current(i);
@@ -709,8 +717,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8);
}
- if (scroll_bar->get_value() != prev_scroll)
+ if (scroll_bar->get_value() != prev_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ItemList::ensure_current_is_visible() {
@@ -825,8 +834,9 @@ void ItemList::_notification(int p_what) {
}
}
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
minsize.x = fixed_column_width;
+ }
max_column_width = MAX(max_column_width, minsize.x);
// elements need to adapt to the selected size
@@ -840,8 +850,9 @@ void ItemList::_notification(int p_what) {
//2-attempt best fit
current_columns = 0x7FFFFFFF;
- if (max_columns > 0)
+ if (max_columns > 0) {
current_columns = max_columns;
+ }
while (true) {
//repeat until all fits
@@ -858,15 +869,17 @@ void ItemList::_notification(int p_what) {
break;
}
- if (same_column_width)
+ if (same_column_width) {
items.write[i].rect_cache.size.x = max_column_width;
+ }
items.write[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
- if (i < items.size() - 1)
+ if (i < items.size() - 1) {
separators.push_back(ofs.y + max_h + vseparation / 2);
+ }
for (int j = i; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
@@ -886,8 +899,9 @@ void ItemList::_notification(int p_what) {
if (all_fit) {
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
- if (auto_height)
+ if (auto_height) {
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
+ }
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
@@ -896,8 +910,9 @@ void ItemList::_notification(int p_what) {
} else {
scroll_bar->show();
- if (do_autoscroll_to_bottom)
+ if (do_autoscroll_to_bottom) {
scroll_bar->set_value(max);
+ }
}
break;
}
@@ -951,11 +966,13 @@ void ItemList::_notification(int p_what) {
for (int i = first_item_visible; i < items.size(); i++) {
Rect2 rcache = items[i].rect_cache;
- if (rcache.position.y > clip.position.y + clip.size.y)
+ if (rcache.position.y > clip.position.y + clip.size.y) {
break; // done
+ }
- if (!clip.intersects(rcache))
+ if (!clip.intersects(rcache)) {
continue;
+ }
if (current_columns == 1) {
rcache.size.width = width - rcache.position.x;
@@ -1020,8 +1037,9 @@ void ItemList::_notification(int p_what) {
}
Color modulate = items[i].icon_modulate;
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
// If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
@@ -1042,16 +1060,18 @@ void ItemList::_notification(int p_what) {
int max_len = -1;
Vector2 size2 = font->get_string_size(items[i].text);
- if (fixed_column_width)
+ if (fixed_column_width) {
max_len = fixed_column_width;
- else if (same_column_width)
+ } else if (same_column_width) {
max_len = items[i].rect_cache.size.x;
- else
+ } else {
max_len = size2.x;
+ }
Color modulate = items[i].selected ? font_color_selected : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
int ss = items[i].text.length();
@@ -1064,8 +1084,9 @@ void ItemList::_notification(int p_what) {
line_size_cache.write[line] = ofs;
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
} else {
ofs += cs;
}
@@ -1084,16 +1105,18 @@ void ItemList::_notification(int p_what) {
if (j == line_limit_cache[line]) {
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
}
ofs += drawer.draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate);
}
//special multiline mode
} else {
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
size2.x = MIN(size2.x, fixed_column_width);
+ }
if (icon_mode == ICON_MODE_TOP) {
text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
@@ -1138,8 +1161,9 @@ void ItemList::_notification(int p_what) {
}
for (int i = first_visible_separator; i < separators.size(); i++) {
- if (separators[i] > clip.position.y + clip.size.y)
+ if (separators[i] > clip.position.y + clip.size.y) {
break; // done
+ }
const int y = base_ofs.y + separators[i];
draw_line(Vector2(bg->get_margin(MARGIN_LEFT), y), Vector2(width, y), guide_color);
@@ -1182,8 +1206,9 @@ int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
}
bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
- if (items.empty())
+ if (items.empty()) {
return true;
+ }
Vector2 pos = p_pos;
Ref<StyleBox> bg = get_theme_stylebox("bg");
@@ -1276,8 +1301,9 @@ Vector<int> ItemList::get_selected_items() {
bool ItemList::is_anything_selected() {
for (int i = 0; i < items.size(); i++) {
- if (items[i].selected)
+ if (items[i].selected) {
return true;
+ }
}
return false;
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index f5487a49be..f49acc1b96 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -69,8 +69,9 @@ int Label::get_line_height() const {
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
String new_text = tr(text);
- if (new_text == xl_text)
+ if (new_text == xl_text) {
return; //nothing new
+ }
xl_text = new_text;
regenerate_word_cache();
@@ -82,8 +83,9 @@ void Label::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
- if (word_cache_dirty)
+ if (word_cache_dirty) {
regenerate_word_cache();
+ }
RID ci = get_canvas_item();
@@ -147,21 +149,25 @@ void Label::_notification(int p_what) {
}
WordCache *wc = word_cache;
- if (!wc)
+ if (!wc) {
return;
+ }
int line = 0;
int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1);
FontDrawer drawer(font, font_outline_modulate);
while (wc) {
/* handle lines not meant to be drawn quickly */
- if (line >= line_to)
+ if (line >= line_to) {
break;
+ }
if (line < lines_skipped) {
- while (wc && wc->char_pos >= 0)
+ while (wc && wc->char_pos >= 0) {
wc = wc->next;
- if (wc)
+ }
+ if (wc) {
wc = wc->next;
+ }
line++;
continue;
}
@@ -285,12 +291,13 @@ Size2 Label::get_minimum_size() const {
const_cast<Label *>(this)->regenerate_word_cache();
}
- if (autowrap)
+ if (autowrap) {
return Size2(1, clip ? 1 : minsize.height) + min_style;
- else {
+ } else {
Size2 ms = minsize;
- if (clip)
+ if (clip) {
ms.width = 1;
+ }
return ms + min_style;
}
}
@@ -302,13 +309,15 @@ int Label::get_longest_line_width() const {
for (int i = 0; i < xl_text.size(); i++) {
CharType current = xl_text[i];
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
if (current < 32) {
if (current == '\n') {
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
line_width = 0;
}
} else {
@@ -317,18 +326,21 @@ int Label::get_longest_line_width() const {
}
}
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
// ceiling to ensure autowrapping does not cut text
return Math::ceil(max_line_width);
}
int Label::get_line_count() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return 1;
- if (word_cache_dirty)
+ }
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return line_count;
}
@@ -338,11 +350,13 @@ int Label::get_visible_line_count() const {
int font_h = get_theme_font("font")->get_height() + line_spacing;
int lines_visible = (get_size().height - get_theme_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
- if (lines_visible > line_count)
+ if (lines_visible > line_count) {
lines_visible = line_count;
+ }
- if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
lines_visible = max_lines_visible;
+ }
return lines_visible;
}
@@ -378,8 +392,9 @@ void Label::regenerate_word_cache() {
for (int i = 0; i <= xl_text.length(); i++) {
CharType current = i < xl_text.length() ? xl_text[i] : L' '; //always a space at the end, so the algo works
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
// ranges taken from http://www.unicodemap.org/
// if your language is not well supported, consider helping improve
@@ -475,8 +490,9 @@ void Label::regenerate_word_cache() {
}
}
- if (!autowrap)
+ if (!autowrap) {
minsize.width = width;
+ }
if (max_lines_visible > 0 && line_count > max_lines_visible) {
minsize.height = (font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
@@ -512,13 +528,15 @@ Label::VAlign Label::get_valign() const {
}
void Label::set_text(const String &p_string) {
- if (text == p_string)
+ if (text == p_string) {
return;
+ }
text = p_string;
xl_text = tr(p_string);
word_cache_dirty = true;
- if (percent_visible < 1)
+ if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
+ }
update();
}
@@ -585,8 +603,9 @@ int Label::get_max_lines_visible() const {
}
int Label::get_total_character_count() const {
- if (word_cache_dirty)
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return total_char_cache;
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index fa08f6f512..e3c75491f7 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -60,8 +60,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
_reset_caret_blink_timer();
if (b->is_pressed()) {
@@ -117,8 +118,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = false;
selection.doubleclick = false;
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ }
}
update();
@@ -146,8 +148,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) {
@@ -286,14 +289,16 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_KP_ENTER:
case KEY_ENTER: {
emit_signal("text_entered", text);
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case KEY_BACKSPACE: {
- if (!editable)
+ if (!editable) {
break;
+ }
if (selection.enabled) {
selection_delete();
@@ -314,8 +319,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -369,8 +375,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -424,8 +431,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc < text.length()) {
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
@@ -442,21 +450,24 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_UP: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == 0)
+ if (get_cursor_position() == 0) {
handled = false;
+ }
set_cursor_position(0);
shift_selection_check_post(k->get_shift());
} break;
case KEY_DOWN: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == text.length())
+ if (get_cursor_position() == text.length()) {
handled = false;
+ }
set_cursor_position(text.length());
shift_selection_check_post(k->get_shift());
} break;
case KEY_DELETE: {
- if (!editable)
+ if (!editable) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt()) {
cut_text();
@@ -470,8 +481,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
int text_len = text.length();
- if (cursor_pos == text_len)
+ if (cursor_pos == text_len) {
break; // Nothing to do.
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt()) {
@@ -488,8 +500,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc < text.length()) {
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -602,8 +615,9 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
- for (int i = selection.begin; i < selection.end; i++)
+ for (int i = selection.begin; i < selection.end; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
text.erase(selection.begin, selected);
@@ -701,10 +715,11 @@ void LineEdit::_notification(int p_what) {
x_ofs = style->get_offset().x;
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
x_ofs = style->get_offset().x;
- else
+ } else {
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - (cached_text_width)) / 2);
+ }
} break;
case ALIGN_RIGHT: {
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_text_width)));
@@ -726,8 +741,9 @@ void LineEdit::_notification(int p_what) {
const String &t = using_placeholder ? placeholder_translated : text;
// Draw placeholder color.
- if (using_placeholder)
+ if (using_placeholder) {
font_color.a *= placeholder_alpha;
+ }
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
@@ -758,22 +774,25 @@ void LineEdit::_notification(int p_what) {
FontDrawer drawer(font, Color(1, 1, 1));
while (true) {
// End of string, break.
- if (char_ofs >= t.length())
+ if (char_ofs >= t.length()) {
break;
+ }
if (char_ofs == cursor_pos) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -795,13 +814,15 @@ void LineEdit::_notification(int p_what) {
int char_width = font->get_char_size(cchar, next).width;
// End of widget, break.
- if ((x_ofs + char_width) > ofs_max)
+ if ((x_ofs + char_width) > ofs_max) {
break;
+ }
bool selected = selection.enabled && char_ofs >= selection.begin && char_ofs < selection.end;
- if (selected)
+ if (selected) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
+ }
int yofs = y_ofs + (caret_height - font->get_height()) / 2;
drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
@@ -824,15 +845,17 @@ void LineEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -894,8 +917,9 @@ void LineEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
@@ -910,8 +934,9 @@ void LineEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
@@ -943,8 +968,9 @@ void LineEdit::paste_text() {
if (paste_buffer != "") {
int prev_len = text.length();
- if (selection.enabled)
+ if (selection.enabled) {
selection_delete();
+ }
append_at_cursor(paste_buffer);
if (!text_changed_dirty) {
@@ -972,8 +998,9 @@ void LineEdit::undo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
@@ -992,8 +1019,9 @@ void LineEdit::redo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
@@ -1002,13 +1030,15 @@ void LineEdit::shift_selection_check_pre(bool p_shift) {
if (!selection.enabled && p_shift) {
selection.cursor_start = cursor_pos;
}
- if (!p_shift)
+ if (!p_shift) {
deselect();
+ }
}
void LineEdit::shift_selection_check_post(bool p_shift) {
- if (p_shift)
+ if (p_shift) {
selection_fill_at_cursor();
+ }
}
void LineEdit::set_cursor_at_pixel_pos(int p_x) {
@@ -1026,19 +1056,22 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
@@ -1074,19 +1107,22 @@ int LineEdit::get_cursor_pixel_pos() {
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
@@ -1146,8 +1182,9 @@ void LineEdit::_toggle_draw_caret() {
}
void LineEdit::delete_char() {
- if ((text.length() <= 0) || (cursor_pos == 0))
+ if ((text.length() <= 0) || (cursor_pos == 0)) {
return;
+ }
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
@@ -1169,8 +1206,9 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
if (text.size() > 0) {
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
- for (int i = p_from_column; i < p_to_column; i++)
+ for (int i = p_from_column; i < p_to_column; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
} else {
cached_width = 0;
@@ -1241,11 +1279,13 @@ float LineEdit::get_placeholder_alpha() const {
}
void LineEdit::set_cursor_position(int p_pos) {
- if (p_pos > (int)text.length())
+ if (p_pos > (int)text.length()) {
p_pos = text.length();
+ }
- if (p_pos < 0)
+ if (p_pos < 0) {
p_pos = 0;
+ }
cursor_pos = p_pos;
@@ -1269,8 +1309,9 @@ void LineEdit::set_cursor_position(int p_pos) {
window_width -= r_icon->get_width();
}
- if (window_width < 0)
+ if (window_width < 0) {
return;
+ }
int wp = window_pos;
if (font.is_valid()) {
@@ -1287,15 +1328,17 @@ void LineEdit::set_cursor_position(int p_pos) {
accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do.
}
}
- if (accum_width > window_width)
+ if (accum_width > window_width) {
break;
+ }
wp = i;
}
}
- if (wp != window_pos)
+ if (wp != window_pos) {
set_window_pos(wp);
+ }
}
update();
}
@@ -1306,8 +1349,9 @@ int LineEdit::get_cursor_position() const {
void LineEdit::set_window_pos(int p_pos) {
window_pos = p_pos;
- if (window_pos < 0)
+ if (window_pos < 0) {
window_pos = 0;
+ }
}
void LineEdit::append_at_cursor(String p_text) {
@@ -1374,8 +1418,9 @@ void LineEdit::deselect() {
}
void LineEdit::selection_delete() {
- if (selection.enabled)
+ if (selection.enabled) {
delete_text(selection.begin, selection.end);
+ }
deselect();
}
@@ -1391,8 +1436,9 @@ int LineEdit::get_max_length() const {
}
void LineEdit::selection_fill_at_cursor() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
selection.begin = cursor_pos;
selection.end = selection.cursor_start;
@@ -1407,11 +1453,13 @@ void LineEdit::selection_fill_at_cursor() {
}
void LineEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (!text.length())
+ if (!text.length()) {
return;
+ }
selection.begin = 0;
selection.end = text.length();
@@ -1420,8 +1468,9 @@ void LineEdit::select_all() {
}
void LineEdit::set_editable(bool p_editable) {
- if (editable == p_editable)
+ if (editable == p_editable) {
return;
+ }
editable = p_editable;
_generate_context_menu();
@@ -1459,8 +1508,9 @@ String LineEdit::get_secret_character() const {
}
void LineEdit::select(int p_from, int p_to) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
if (p_from == 0 && p_to == 0) {
deselect();
@@ -1468,15 +1518,19 @@ void LineEdit::select(int p_from, int p_to) {
}
int len = text.length();
- if (p_from < 0)
+ if (p_from < 0) {
p_from = 0;
- if (p_from > len)
+ }
+ if (p_from > len) {
p_from = len;
- if (p_to < 0 || p_to > len)
+ }
+ if (p_to < 0 || p_to > len) {
p_to = len;
+ }
- if (p_from >= p_to)
+ if (p_from >= p_to) {
return;
+ }
selection.enabled = true;
selection.begin = p_from;
@@ -1581,8 +1635,9 @@ bool LineEdit::is_shortcut_keys_enabled() const {
void LineEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -1605,8 +1660,9 @@ Ref<Texture2D> LineEdit::get_right_icon() {
}
void LineEdit::_text_changed() {
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
_clear_redo();
@@ -1672,14 +1728,17 @@ void LineEdit::_create_undo_state() {
void LineEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (editable)
+ if (editable) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (editable)
+ if (editable) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (editable) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index d772b257fc..f8c8bd4caf 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -68,10 +68,11 @@ void LinkButton::_notification(int p_what) {
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
- if (has_theme_color("font_color_pressed"))
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
+ }
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 3f5bc43d93..0299065f77 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -40,18 +40,23 @@ Size2 MarginContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 s = c->get_combined_minimum_size();
- if (s.width > max.width)
+ if (s.width > max.width) {
max.width = s.width;
- if (s.height > max.height)
+ }
+ if (s.height > max.height) {
max.height = s.height;
+ }
}
max.width += (margin_left + margin_right);
@@ -72,10 +77,12 @@ void MarginContainer::_notification(int p_what) {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
int w = s.width - margin_left - margin_right;
int h = s.height - margin_top - margin_bottom;
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 2593784cbd..aa69fb39e7 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -34,18 +34,21 @@
#include "scene/main/window.h"
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
- if (disable_shortcuts)
+ if (disable_shortcuts) {
return;
+ }
if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
- if (!get_parent() || !is_visible_in_tree() || is_disabled())
+ if (!get_parent() || !is_visible_in_tree() || is_disabled()) {
return;
+ }
//bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this));
//if (popup->activate_item_by_event(p_event, global_only))
// accept_event();
- if (popup->activate_item_by_event(p_event, false))
+ if (popup->activate_item_by_event(p_event, false)) {
accept_event();
+ }
}
}
diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp
index 4d94bbf5d9..bc71ae94f5 100644
--- a/scene/gui/nine_patch_rect.cpp
+++ b/scene/gui/nine_patch_rect.cpp
@@ -34,8 +34,9 @@
void NinePatchRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
Rect2 rect = Rect2(Point2(), get_size());
Rect2 src_rect = region_rect;
@@ -86,8 +87,9 @@ void NinePatchRect::_bind_methods() {
}
void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
- if (texture == p_tex)
+ if (texture == p_tex) {
return;
+ }
texture = p_tex;
update();
/*
@@ -130,8 +132,9 @@ int NinePatchRect::get_patch_margin(Margin p_margin) const {
}
void NinePatchRect::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect == p_region_rect)
+ if (region_rect == p_region_rect) {
return;
+ }
region_rect = p_region_rect;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index bc4eec5ba3..e7de0f0912 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -52,8 +52,9 @@ Size2 OptionButton::get_minimum_size() const {
void OptionButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!has_theme_icon("arrow"))
+ if (!has_theme_icon("arrow")) {
return;
+ }
RID ci = get_canvas_item();
Ref<Texture2D> arrow = Control::get_theme_icon("arrow");
@@ -109,28 +110,32 @@ void OptionButton::pressed() {
void OptionButton::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id) {
popup->add_icon_radio_check_item(p_icon, p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
void OptionButton::add_item(const String &p_label, int p_id) {
popup->add_radio_check_item(p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
void OptionButton::set_item_text(int p_idx, const String &p_text) {
popup->set_item_text(p_idx, p_text);
- if (current == p_idx)
+ if (current == p_idx) {
set_text(p_text);
+ }
}
void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
popup->set_item_icon(p_idx, p_icon);
- if (current == p_idx)
+ if (current == p_idx) {
set_icon(p_icon);
+ }
}
void OptionButton::set_item_id(int p_idx, int p_id) {
@@ -184,10 +189,12 @@ void OptionButton::clear() {
}
void OptionButton::_select(int p_which, bool p_emit) {
- if (p_which < 0)
+ if (p_which < 0) {
return;
- if (p_which == current)
+ }
+ if (p_which == current) {
return;
+ }
ERR_FAIL_INDEX(p_which, popup->get_item_count());
@@ -199,13 +206,15 @@ void OptionButton::_select(int p_which, bool p_emit) {
set_text(popup->get_item_text(current));
set_icon(popup->get_item_icon(current));
- if (is_inside_tree() && p_emit)
+ if (is_inside_tree() && p_emit) {
emit_signal("item_selected", current);
+ }
}
void OptionButton::_select_int(int p_which) {
- if (p_which < 0 || p_which >= popup->get_item_count())
+ if (p_which < 0 || p_which >= popup->get_item_count()) {
return;
+ }
_select(p_which, false);
}
@@ -219,15 +228,17 @@ int OptionButton::get_selected() const {
int OptionButton::get_selected_id() const {
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return 0;
+ }
return get_item_id(current);
}
Variant OptionButton::get_selected_metadata() const {
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return Variant();
+ }
return get_item_metadata(current);
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 6cac15d9f0..9abdfac009 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -33,26 +33,30 @@
Size2 PanelContainer::get_minimum_size() const {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
}
- if (style.is_valid())
+ if (style.is_valid()) {
ms += style->get_minimum_size();
+ }
return ms;
}
@@ -61,10 +65,11 @@ void PanelContainer::_notification(int p_what) {
RID ci = get_canvas_item();
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
style->draw(ci, Rect2(Point2(), get_size()));
}
@@ -72,10 +77,11 @@ void PanelContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 size = get_size();
Point2 ofs;
@@ -86,10 +92,12 @@ void PanelContainer::_notification(int p_what) {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
fit_child_in_rect(c, Rect2(ofs, size));
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index e1fcb8c2fc..5fc5f9b669 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -151,11 +151,13 @@ Size2 PopupPanel::_get_contents_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c == panel)
+ if (!c || c == panel) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(cms.x, ms.x);
@@ -173,11 +175,13 @@ void PopupPanel::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (c == panel) {
c->set_position(Vector2());
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index c5c6305315..b439d85983 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -40,10 +40,11 @@
String PopupMenu::_get_accel_text(int p_item) const {
ERR_FAIL_INDEX_V(p_item, items.size(), String());
- if (items[p_item].shortcut.is_valid())
+ if (items[p_item].shortcut.is_valid()) {
return items[p_item].shortcut->get_as_text();
- else if (items[p_item].accel)
+ } else if (items[p_item].accel) {
return keycode_get_string(items[p_item].accel);
+ }
return String();
}
@@ -73,13 +74,15 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
size.width += items[i].h_ofs;
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
String text = items[i].xl_text;
size.width += font->get_string_size(text).width;
- if (i > 0)
+ if (i > 0) {
size.height += vseparation;
+ }
if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
int accel_w = hseparation * 2;
@@ -87,8 +90,9 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
accel_max_w = MAX(accel_w, accel_max_w);
}
- if (items[i].submenu != "")
+ if (items[i].submenu != "") {
size.width += get_theme_icon("submenu")->get_width();
+ }
max_w = MAX(max_w, size.width);
@@ -96,22 +100,25 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
}
minsize.width += max_w + icon_w + accel_max_w;
- if (has_check)
+ if (has_check) {
minsize.width += check_w;
+ }
return minsize;
}
int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
- if (p_over.x < 0 || p_over.x >= get_size().width)
+ if (p_over.x < 0 || p_over.x >= get_size().width) {
return -1;
+ }
Ref<StyleBox> style = get_theme_stylebox("panel");
Point2 ofs = style->get_offset();
- if (ofs.y > p_over.y)
+ if (ofs.y > p_over.y) {
return -1;
+ }
Ref<Font> font = get_theme_font("font");
int vseparation = get_theme_constant("vseparation");
@@ -142,8 +149,9 @@ void PopupMenu::_activate_submenu(int over) {
ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + ".");
Popup *pm = Object::cast_to<Popup>(n);
ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + ".");
- if (pm->is_visible())
+ if (pm->is_visible()) {
return; //already visible!
+ }
Point2 p = get_position();
Rect2 pr(p, get_size());
@@ -152,8 +160,9 @@ void PopupMenu::_activate_submenu(int over) {
Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y);
Size2 size = pm->get_size();
// fix pos
- if (pos.x + size.width > get_parent_rect().size.width)
+ if (pos.x + size.width > get_parent_rect().size.width) {
pos.x = p.x - size.width;
+ }
pm->set_position(pos);
// pm->set_scale(get_global_transform().get_scale());
@@ -175,8 +184,9 @@ void PopupMenu::_submenu_timeout() {
//if (!has_focus()) {
// return; //do not activate if not has focus
//}
- if (mouse_over == submenu_over)
+ if (mouse_over == submenu_over) {
_activate_submenu(mouse_over);
+ }
submenu_over = -1;
}
@@ -214,12 +224,14 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (p_event->is_action("ui_down") && p_event->is_pressed()) {
int search_from = mouse_over + 1;
- if (search_from >= items.size())
+ if (search_from >= items.size()) {
search_from = 0;
+ }
for (int i = search_from; i < items.size(); i++) {
- if (i < 0 || i >= items.size())
+ if (i < 0 || i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -231,12 +243,14 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
int search_from = mouse_over - 1;
- if (search_from < 0)
+ if (search_from < 0) {
search_from = items.size() - 1;
+ }
for (int i = search_from; i >= 0; i--) {
- if (i >= items.size())
+ if (i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -271,8 +285,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (b->is_pressed())
+ if (b->is_pressed()) {
return;
+ }
int button_idx = b->get_button_index();
switch (button_idx) {
@@ -302,8 +317,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
break; //non-activable
}
- if (items[over].separator || items[over].disabled)
+ if (items[over].separator || items[over].disabled) {
break;
+ }
if (items[over].submenu != "") {
_activate_submenu(over);
@@ -322,8 +338,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (m.is_valid()) {
if (invalidated_click) {
moved += m->get_relative();
- if (moved.length() > 4)
+ if (moved.length() > 4) {
invalidated_click = false;
+ }
}
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
@@ -370,19 +387,22 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = mouse_over + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (mouse_over <= 0)
+ if (mouse_over <= 0) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == mouse_over)
+ if (i == mouse_over) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
@@ -424,22 +444,27 @@ void PopupMenu::_draw() {
float icon_ofs = 0.0;
bool has_check = false;
for (int i = 0; i < items.size(); i++) {
- if (!items[i].icon.is_null())
+ if (!items[i].icon.is_null()) {
icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs);
+ }
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
}
- if (icon_ofs > 0.0)
+ if (icon_ofs > 0.0) {
icon_ofs += hseparation;
+ }
float check_ofs = 0.0;
- if (has_check)
+ if (has_check) {
check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
+ }
for (int i = 0; i < items.size(); i++) {
- if (i > 0)
+ if (i > 0) {
ofs.y += vseparation;
+ }
Point2 item_ofs = ofs;
Size2 icon_size;
float h;
@@ -570,16 +595,19 @@ void PopupMenu::_notification(int p_what) {
}
for (int i = 0; i < items.size(); i++) {
- if (items[i].submenu == "")
+ if (items[i].submenu == "") {
continue;
+ }
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm || !pm->is_visible())
+ if (!pm || !pm->is_visible()) {
continue;
+ }
pm->hide();
}
@@ -826,8 +854,9 @@ String PopupMenu::get_item_text(int p_idx) const {
int PopupMenu::get_item_idx_from_text(const String &text) const {
for (int idx = 0; idx < items.size(); idx++) {
- if (items[idx].text == text)
+ if (items[idx].text == text) {
return idx;
+ }
}
return -1;
@@ -865,8 +894,9 @@ int PopupMenu::get_item_id(int p_idx) const {
int PopupMenu::get_item_index(int p_id) const {
for (int i = 0; i < items.size(); i++) {
- if (items[i].id == p_id)
+ if (items[i].id == p_id) {
return i;
+ }
}
return -1;
@@ -962,8 +992,9 @@ void PopupMenu::toggle_item_multistate(int p_idx) {
}
++items.write[p_idx].state;
- if (items.write[p_idx].max_states <= items[p_idx].state)
+ if (items.write[p_idx].max_states <= items[p_idx].state) {
items.write[p_idx].state = 0;
+ }
control->update();
}
@@ -997,21 +1028,27 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
if (k.is_valid()) {
code = k->get_keycode();
- if (code == 0)
+ if (code == 0) {
code = k->get_unicode();
- if (k->get_control())
+ }
+ if (k->get_control()) {
code |= KEY_MASK_CTRL;
- if (k->get_alt())
+ }
+ if (k->get_alt()) {
code |= KEY_MASK_ALT;
- if (k->get_metakey())
+ }
+ if (k->get_metakey()) {
code |= KEY_MASK_META;
- if (k->get_shift())
+ }
+ if (k->get_shift()) {
code |= KEY_MASK_SHIFT;
+ }
}
for (int i = 0; i < items.size(); i++) {
- if (is_item_disabled(i) || items[i].shortcut_is_disabled)
+ if (is_item_disabled(i) || items[i].shortcut_is_disabled) {
continue;
+ }
if (items[i].shortcut.is_valid() && items[i].shortcut->is_shortcut(p_event) && (items[i].shortcut_is_global || !p_for_global_only)) {
activate_item(i);
@@ -1025,12 +1062,14 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
if (items[i].submenu != "") {
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm)
+ if (!pm) {
continue;
+ }
if (pm->activate_item_by_event(p_event, p_for_global_only)) {
return true;
@@ -1053,13 +1092,16 @@ void PopupMenu::activate_item(int p_item) {
// with hide_on_item_selection enabled
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection())
+ if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection()) {
break;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection())
+ if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection()) {
break;
- } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection())
+ }
+ } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection()) {
break;
+ }
pop->hide();
next = next->get_parent();
@@ -1072,13 +1114,16 @@ void PopupMenu::activate_item(int p_item) {
bool need_hide = true;
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection)
+ if (!hide_on_checkable_item_selection) {
need_hide = false;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection)
+ if (!hide_on_multistate_item_selection) {
need_hide = false;
- } else if (!hide_on_item_selection)
+ }
+ } else if (!hide_on_item_selection) {
need_hide = false;
+ }
emit_signal("id_pressed", id);
emit_signal("index_pressed", p_item);
@@ -1228,8 +1273,9 @@ bool PopupMenu::is_hide_on_multistate_item_selection() const {
}
void PopupMenu::set_submenu_popup_delay(float p_time) {
- if (p_time <= 0)
+ if (p_time <= 0) {
p_time = 0.01;
+ }
submenu_timer->set_wait_time(p_time);
}
@@ -1248,8 +1294,9 @@ bool PopupMenu::get_allow_search() const {
String PopupMenu::get_tooltip(const Point2 &p_pos) const {
int over = _get_mouse_over(p_pos);
- if (over < 0 || over >= items.size())
+ if (over < 0 || over >= items.size()) {
return "";
+ }
return items[over].tooltip;
}
@@ -1259,8 +1306,9 @@ void PopupMenu::set_parent_rect(const Rect2 &p_rect) {
void PopupMenu::get_translatable_strings(List<String> *p_strings) const {
for (int i = 0; i < items.size(); i++) {
- if (items[i].xl_text != "")
+ if (items[i].xl_text != "") {
p_strings->push_back(items[i].xl_text);
+ }
}
}
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 9e30063c5b..59e26d9e38 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -53,8 +53,9 @@ void Range::_value_changed_notify() {
void Range::Shared::emit_value_changed() {
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_value_changed_notify();
}
}
@@ -68,27 +69,33 @@ void Range::_changed_notify(const char *p_what) {
void Range::Shared::emit_changed(const char *p_what) {
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_changed_notify(p_what);
}
}
void Range::set_value(double p_val) {
- if (shared->step > 0)
+ if (shared->step > 0) {
p_val = Math::round(p_val / shared->step) * shared->step;
+ }
- if (_rounded_values)
+ if (_rounded_values) {
p_val = Math::round(p_val);
+ }
- if (!shared->allow_greater && p_val > shared->max - shared->page)
+ if (!shared->allow_greater && p_val > shared->max - shared->page) {
p_val = shared->max - shared->page;
+ }
- if (!shared->allow_lesser && p_val < shared->min)
+ if (!shared->allow_lesser && p_val < shared->min) {
p_val = shared->min;
+ }
- if (shared->val == p_val)
+ if (shared->val == p_val) {
return;
+ }
shared->val = p_val;
@@ -209,8 +216,9 @@ void Range::unshare() {
}
void Range::_ref_shared(Shared *p_shared) {
- if (shared && p_shared == shared)
+ if (shared && p_shared == shared) {
return;
+ }
_unref_shared();
shared = p_shared;
diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp
index 0f6ff4da26..27c57c684a 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -34,10 +34,12 @@
void ReferenceRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (Engine::get_singleton()->is_editor_hint() || !editor_only)
+ }
+ if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
draw_rect(Rect2(Point2(), get_size()), border_color, false);
+ }
}
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index d73c61f0f2..a57408b83b 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -59,10 +59,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->next()->get();
- else
+ } else {
return nullptr;
+ }
}
} else {
@@ -78,10 +79,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->next()->get();
- else
+ } else {
return nullptr;
+ }
}
}
@@ -102,10 +104,11 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->prev()->get();
- else
+ } else {
return nullptr;
+ }
}
} else {
@@ -121,10 +124,11 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->prev()->get();
- else
+ } else {
return nullptr;
+ }
}
}
@@ -140,13 +144,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
ERR_FAIL_INDEX_V((int)p_mode, 3, 0);
RID ci;
- if (r_outside)
+ if (r_outside) {
*r_outside = false;
+ }
if (p_mode == PROCESS_DRAW) {
ci = get_canvas_item();
- if (r_click_item)
+ if (r_click_item) {
*r_click_item = nullptr;
+ }
}
Line &l = p_frame->lines.write[p_line];
Item *it = l.from;
@@ -178,14 +184,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int spaces_size = 0;
int align_ofs = 0;
- if (p_mode != PROCESS_CACHE && align != ALIGN_FILL)
+ if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) {
wofs += line_ofs;
+ }
int begin = wofs;
Ref<Font> cfont = _find_font(it);
- if (cfont.is_null())
+ if (cfont.is_null()) {
cfont = p_base_font;
+ }
//line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed
int line_height = cfont->get_height();
@@ -337,8 +345,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
ItemText *text = static_cast<ItemText *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
const CharType *c = text->text.c_str();
const CharType *cf = c;
@@ -542,8 +551,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
w += font->get_char_size(c[i], c[i + 1]).x;
}
- if (c[i] == '\t')
+ if (c[i] == '\t') {
visible = false;
+ }
if (visible) {
if (selected) {
@@ -611,25 +621,29 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_IMAGE: {
lh = 0;
- if (p_mode != PROCESS_CACHE)
+ if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- else
+ } else {
l.char_count += 1; //images count as chars too
+ }
ItemImage *img = static_cast<ItemImage *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
- if (p_mode == PROCESS_POINTER && r_click_char)
+ if (p_mode == PROCESS_POINTER && r_click_char) {
*r_click_char = 0;
+ }
ENSURE_WIDTH(img->size.width);
bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->size.height, img->size.height));
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
if (p_mode == PROCESS_DRAW && visible) {
img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size));
@@ -695,17 +709,20 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < table->columns.size(); i++) {
remaining_width -= table->columns[i].min_width;
- if (table->columns[i].max_width > table->columns[i].min_width)
+ if (table->columns[i].max_width > table->columns[i].min_width) {
table->columns.write[i].expand = true;
- if (table->columns[i].expand)
+ }
+ if (table->columns[i].expand) {
total_ratio += table->columns[i].expand_ratio;
+ }
}
//assign actual widths
for (int i = 0; i < table->columns.size(); i++) {
table->columns.write[i].width = table->columns[i].min_width;
- if (table->columns[i].expand && total_ratio > 0)
+ if (table->columns[i].expand && total_ratio > 0) {
table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ }
table->total_width += table->columns[i].width + hseparation;
}
@@ -715,8 +732,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
table_need_fit = false;
//fit slim
for (int i = 0; i < table->columns.size(); i++) {
- if (!table->columns[i].expand)
+ if (!table->columns[i].expand) {
continue;
+ }
int dif = table->columns[i].width - table->columns[i].max_width;
if (dif > 0) {
table_need_fit = true;
@@ -778,8 +796,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int lines_ofs = p_ofs.y + offset.y + draw_ofs.y;
bool visible = lines_ofs < get_size().height && lines_ofs + lines_h >= 0;
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
for (int i = 0; i < frame->lines.size(); i++) {
if (visible) {
@@ -831,8 +850,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) {
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
//went to next line, but pointer was on the previous one
- if (r_outside)
+ if (r_outside) {
*r_outside = true;
+ }
*r_click_item = itp;
*r_click_char = rchar;
RETURN;
@@ -853,13 +873,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
void RichTextLabel::_scroll_changed(double) {
- if (updating_scroll || !scroll_active)
+ if (updating_scroll || !scroll_active) {
return;
+ }
- if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
- else
+ } else {
scroll_following = false;
+ }
scroll_updated = true;
@@ -938,8 +960,9 @@ void RichTextLabel::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
- if (bbcode != "")
+ if (bbcode != "") {
set_bbcode(bbcode);
+ }
main->first_invalid_line = 0; //invalidate ALL
update();
@@ -973,14 +996,16 @@ void RichTextLabel::_notification(int p_what) {
int from_line = 0;
int total_chars = 0;
while (from_line < main->lines.size()) {
- if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs)
+ if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) {
break;
+ }
total_chars += main->lines[from_line].char_count;
from_line++;
}
- if (from_line >= main->lines.size())
+ if (from_line >= main->lines.size()) {
break; //nothing to draw
+ }
int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
Color base_color = get_theme_color("default_color");
@@ -1006,8 +1031,9 @@ void RichTextLabel::_notification(int p_what) {
}
void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) {
- if (r_click_item)
+ if (r_click_item) {
*r_click_item = nullptr;
+ }
Rect2 text_rect = _get_text_rect();
int ofs = vscroll->get_value();
@@ -1019,13 +1045,15 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
int from_line = 0;
while (from_line < p_frame->lines.size()) {
- if (p_frame->lines[from_line].height_accum_cache >= ofs)
+ if (p_frame->lines[from_line].height_accum_cache >= ofs) {
break;
+ }
from_line++;
}
- if (from_line >= p_frame->lines.size())
+ if (from_line >= p_frame->lines.size()) {
return;
+ }
int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
@@ -1033,29 +1061,34 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) {
_process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, p_click, r_click_item, r_click_char, r_outside);
- if (r_click_item && *r_click_item)
+ if (r_click_item && *r_click_item) {
return;
+ }
from_line++;
}
}
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
- if (!underline_meta)
+ if (!underline_meta) {
return CURSOR_ARROW;
+ }
- if (selection.click)
+ if (selection.click) {
return CURSOR_IBEAM;
+ }
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return CURSOR_ARROW; //invalid
+ }
int line = 0;
Item *item = nullptr;
bool outside;
((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line, &outside);
- if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr))
+ if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr)) {
return CURSOR_POINTING_HAND;
+ }
return CURSOR_ARROW;
}
@@ -1064,8 +1097,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
if (b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed() && !b->is_doubleclick()) {
@@ -1141,20 +1175,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_WHEEL_UP) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
}
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
- if (scroll_active)
-
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
+ }
return;
}
@@ -1211,16 +1247,18 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
}
- if (handled)
+ if (handled) {
accept_event();
+ }
}
}
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
int line = 0;
Item *item = nullptr;
@@ -1228,8 +1266,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_find_click(main, m->get_position(), &item, &line, &outside);
if (selection.click) {
- if (!item)
+ if (!item) {
return; // do not update
+ }
selection.from = selection.click;
selection.from_char = selection.click_char;
@@ -1238,12 +1277,12 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
selection.to_char = line;
bool swap = false;
- if (selection.from->index > selection.to->index)
+ if (selection.from->index > selection.to->index) {
swap = true;
- else if (selection.from->index == selection.to->index) {
- if (selection.from_char > selection.to_char)
+ } else if (selection.from->index == selection.to->index) {
+ if (selection.from_char > selection.to_char) {
swap = true;
- else if (selection.from_char == selection.to_char) {
+ } else if (selection.from_char == selection.to_char) {
selection.active = false;
return;
}
@@ -1300,8 +1339,9 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
while (item) {
if (item->type == ITEM_INDENT) {
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
ItemIndent *indent = static_cast<ItemIndent *>(item);
@@ -1309,8 +1349,9 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
} else if (item->type == ITEM_LIST) {
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
}
item = item->parent;
@@ -1408,10 +1449,12 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item)
while (item) {
if (item->type == ITEM_META) {
ItemMeta *meta = static_cast<ItemMeta *>(item);
- if (r_meta)
+ if (r_meta) {
*r_meta = meta->meta;
- if (r_item)
+ }
+ if (r_item) {
*r_item = meta;
+ }
return true;
}
@@ -1423,14 +1466,16 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item)
bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
if (from && from != to) {
- if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH)
+ if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) {
return true;
+ }
for (List<Item *>::Element *E = from->subitems.front(); E; E = E->next()) {
bool layout = _find_layout_subitem(E->get(), to);
- if (layout)
+ if (layout) {
return true;
+ }
}
}
@@ -1438,8 +1483,9 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
}
void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
- if (p_frame->first_invalid_line == p_frame->lines.size())
+ if (p_frame->first_invalid_line == p_frame->lines.size()) {
return;
+ }
//validate invalid lines
Size2 size = get_size();
@@ -1459,21 +1505,24 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
p_frame->lines.write[i].height_cache = y;
p_frame->lines.write[i].height_accum_cache = y;
- if (i > 0)
+ if (i > 0) {
p_frame->lines.write[i].height_accum_cache += p_frame->lines[i - 1].height_accum_cache;
+ }
}
int total_height = 0;
- if (p_frame->lines.size())
+ if (p_frame->lines.size()) {
total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
main->first_invalid_line = p_frame->lines.size();
updating_scroll = true;
vscroll->set_max(total_height);
vscroll->set_page(size.height);
- if (scroll_follow && scroll_following)
+ if (scroll_follow && scroll_following) {
vscroll->set_value(total_height - size.height);
+ }
updating_scroll = false;
}
@@ -1486,8 +1535,9 @@ void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) {
}
void RichTextLabel::add_text(const String &p_text) {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return; //can't add anything here
+ }
int pos = 0;
@@ -1501,10 +1551,11 @@ void RichTextLabel::add_text(const String &p_text) {
eol = true;
}
- if (pos == 0 && end == p_text.length())
+ if (pos == 0 && end == p_text.length()) {
line = p_text;
- else
+ } else {
line = p_text.substr(pos, end - pos);
+ }
if (line.length() > 0) {
if (current->subitems.size() && current->subitems.back()->get()->type == ITEM_TEXT) {
@@ -1526,8 +1577,9 @@ void RichTextLabel::add_text(const String &p_text) {
item->line = current_frame->lines.size();
_add_item(item, false);
current_frame->lines.resize(current_frame->lines.size() + 1);
- if (item->type != ITEM_NEWLINE)
+ if (item->type != ITEM_NEWLINE) {
current_frame->lines.write[current_frame->lines.size() - 1].from = item;
+ }
_invalidate_current_line(current_frame);
}
@@ -1540,8 +1592,9 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++;
- if (p_enter)
+ if (p_enter) {
current = p_item;
+ }
if (p_ensure_newline) {
Item *from = current_frame->lines[current_frame->lines.size() - 1].from;
@@ -1571,8 +1624,9 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
if (p_item->type == ITEM_NEWLINE) {
current_frame->lines.remove(p_line);
for (int i = p_subitem_line; i < current->subitems.size(); i++) {
- if (current->subitems[i]->line > 0)
+ if (current->subitems[i]->line > 0) {
current->subitems[i]->line--;
+ }
}
}
} else {
@@ -1583,8 +1637,9 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
}
void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return;
+ }
ERR_FAIL_COND(p_image.is_null());
ItemImage *item = memnew(ItemImage);
@@ -1618,8 +1673,9 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
}
void RichTextLabel::add_newline() {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return;
+ }
ItemNewline *item = memnew(ItemNewline);
item->line = current_frame->lines.size();
_add_item(item, false);
@@ -1628,8 +1684,9 @@ void RichTextLabel::add_newline() {
}
bool RichTextLabel::remove_line(const int p_line) {
- if (p_line >= current_frame->lines.size() || p_line < 0)
+ if (p_line >= current_frame->lines.size() || p_line < 0) {
return false;
+ }
int i = 0;
while (i < current->subitems.size() && current->subitems[i]->line < p_line) {
@@ -1640,8 +1697,9 @@ bool RichTextLabel::remove_line(const int p_line) {
while (i < current->subitems.size()) {
was_newline = current->subitems[i]->type == ITEM_NEWLINE;
_remove_item(current->subitems[i], current->subitems[i]->line, p_line);
- if (was_newline)
+ if (was_newline) {
break;
+ }
}
if (!was_newline) {
@@ -1651,8 +1709,9 @@ bool RichTextLabel::remove_line(const int p_line) {
}
}
- if (p_line == 0 && current->subitems.size() > 0)
+ if (p_line == 0 && current->subitems.size() > 0) {
main->lines.write[0].from = main;
+ }
main->first_invalid_line = 0;
@@ -1903,8 +1962,9 @@ void RichTextLabel::set_offset(int p_pixel) {
}
void RichTextLabel::set_scroll_active(bool p_active) {
- if (scroll_active == p_active)
+ if (scroll_active == p_active) {
return;
+ }
scroll_active = p_active;
update();
@@ -1916,8 +1976,9 @@ bool RichTextLabel::is_scroll_active() const {
void RichTextLabel::set_scroll_follow(bool p_follow) {
scroll_follow = p_follow;
- if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
+ }
}
bool RichTextLabel::is_scroll_following() const {
@@ -1951,15 +2012,17 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
while (pos < p_bbcode.length()) {
int brk_pos = p_bbcode.find("[", pos);
- if (brk_pos < 0)
+ if (brk_pos < 0) {
brk_pos = p_bbcode.length();
+ }
if (brk_pos > pos) {
add_text(p_bbcode.substr(pos, brk_pos - pos));
}
- if (brk_pos == p_bbcode.length())
+ if (brk_pos == p_bbcode.length()) {
break; //nothing else to add
+ }
int brk_end = p_bbcode.find("]", brk_pos + 1);
@@ -1975,12 +2038,15 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
if (tag.begins_with("/") && tag_stack.size()) {
bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
- if (tag_stack.front()->get() == "b")
+ if (tag_stack.front()->get() == "b") {
in_bold = false;
- if (tag_stack.front()->get() == "i")
+ }
+ if (tag_stack.front()->get() == "i") {
in_italics = false;
- if (tag_stack.front()->get() == "indent")
+ }
+ if (tag_stack.front()->get() == "indent") {
indent_level--;
+ }
if (!tag_ok) {
add_text("[" + tag);
@@ -1990,25 +2056,28 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.pop_front();
pos = brk_end + 1;
- if (tag != "/img")
+ if (tag != "/img") {
pop();
+ }
} else if (tag == "b") {
//use bold font
in_bold = true;
- if (in_italics)
+ if (in_italics) {
push_font(bold_italics_font);
- else
+ } else {
push_font(bold_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "i") {
//use italics font
in_italics = true;
- if (in_bold)
+ if (in_bold) {
push_font(bold_italics_font);
- else
+ } else {
push_font(italics_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "code") {
@@ -2018,8 +2087,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag.begins_with("table=")) {
int columns = tag.substr(6, tag.length()).to_int();
- if (columns < 1)
+ if (columns < 1) {
columns = 1;
+ }
push_table(columns);
pos = brk_end + 1;
@@ -2030,8 +2100,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag.begins_with("cell=")) {
int ratio = tag.substr(5, tag.length()).to_int();
- if (ratio < 1)
+ if (ratio < 1) {
ratio = 1;
+ }
set_table_column_expand(get_current_table_column(), true, ratio);
push_cell();
@@ -2075,8 +2146,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
} else if (tag == "url") {
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String url = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
push_meta(url);
@@ -2090,14 +2162,16 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front("url");
} else if (tag == "img") {
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D");
- if (texture.is_valid())
+ if (texture.is_valid()) {
add_image(texture);
+ }
pos = end;
tag_stack.push_front(tag);
@@ -2115,14 +2189,16 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(image, "Texture");
- if (texture.is_valid())
+ if (texture.is_valid()) {
add_image(texture, width, height);
+ }
pos = end;
tag_stack.push_front("img");
@@ -2130,42 +2206,43 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String col = tag.substr(6, tag.length());
Color color;
- if (col.begins_with("#"))
+ if (col.begins_with("#")) {
color = Color::html(col);
- else if (col == "aqua")
+ } else if (col == "aqua") {
color = Color(0, 1, 1);
- else if (col == "black")
+ } else if (col == "black") {
color = Color(0, 0, 0);
- else if (col == "blue")
+ } else if (col == "blue") {
color = Color(0, 0, 1);
- else if (col == "fuchsia")
+ } else if (col == "fuchsia") {
color = Color(1, 0, 1);
- else if (col == "gray" || col == "grey")
+ } else if (col == "gray" || col == "grey") {
color = Color(0.5, 0.5, 0.5);
- else if (col == "green")
+ } else if (col == "green") {
color = Color(0, 0.5, 0);
- else if (col == "lime")
+ } else if (col == "lime") {
color = Color(0, 1, 0);
- else if (col == "maroon")
+ } else if (col == "maroon") {
color = Color(0.5, 0, 0);
- else if (col == "navy")
+ } else if (col == "navy") {
color = Color(0, 0, 0.5);
- else if (col == "olive")
+ } else if (col == "olive") {
color = Color(0.5, 0.5, 0);
- else if (col == "purple")
+ } else if (col == "purple") {
color = Color(0.5, 0, 0.5);
- else if (col == "red")
+ } else if (col == "red") {
color = Color(1, 0, 0);
- else if (col == "silver")
+ } else if (col == "silver") {
color = Color(0.75, 0.75, 0.75);
- else if (col == "teal")
+ } else if (col == "teal") {
color = Color(0, 0.5, 0.5);
- else if (col == "white")
+ } else if (col == "white") {
color = Color(1, 1, 1);
- else if (col == "yellow")
+ } else if (col == "yellow") {
color = Color(1, 1, 0);
- else
+ } else {
color = base_color;
+ }
push_color(color);
pos = brk_end + 1;
@@ -2175,10 +2252,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String fnt = tag.substr(5, tag.length());
Ref<Font> font = ResourceLoader::load(fnt, "Font");
- if (font.is_valid())
+ if (font.is_valid()) {
push_font(font);
- else
+ } else {
push_font(normal_font);
+ }
pos = brk_end + 1;
tag_stack.push_front("font");
@@ -2334,8 +2412,9 @@ int RichTextLabel::get_line_count() const {
}
int RichTextLabel::get_visible_line_count() const {
- if (!is_visible())
+ if (!is_visible()) {
return 0;
+ }
return visible_line_count;
}
@@ -2398,10 +2477,11 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
}
- if (p_search_previous)
+ if (p_search_previous) {
it = _get_prev_item(it, true);
- else
+ } else {
it = _get_next_item(it, true);
+ }
charidx = 0;
}
@@ -2409,8 +2489,9 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
void RichTextLabel::selection_copy() {
- if (!selection.active || !selection.enabled)
+ if (!selection.active || !selection.enabled) {
return;
+ }
String text;
@@ -2432,8 +2513,9 @@ void RichTextLabel::selection_copy() {
} else if (item->type == ITEM_NEWLINE) {
text += "\n";
}
- if (item == selection.to)
+ if (item == selection.to) {
break;
+ }
item = _get_next_item(item, true);
}
@@ -2449,9 +2531,9 @@ bool RichTextLabel::is_selection_enabled() const {
void RichTextLabel::set_bbcode(const String &p_bbcode) {
bbcode = p_bbcode;
- if (is_inside_tree() && use_bbcode)
+ if (is_inside_tree() && use_bbcode) {
parse_bbcode(p_bbcode);
- else { // raw text
+ } else { // raw text
clear();
add_text(p_bbcode);
}
@@ -2462,8 +2544,9 @@ String RichTextLabel::get_bbcode() const {
}
void RichTextLabel::set_use_bbcode(bool p_enable) {
- if (use_bbcode == p_enable)
+ if (use_bbcode == p_enable) {
return;
+ }
use_bbcode = p_enable;
set_bbcode(bbcode);
}
@@ -2540,8 +2623,9 @@ void RichTextLabel::install_effect(const Variant effect) {
int RichTextLabel::get_content_height() {
int total_height = 0;
- if (main->lines.size())
+ if (main->lines.size()) {
total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
return total_height;
}
@@ -2687,8 +2771,9 @@ int RichTextLabel::get_visible_characters() const {
int RichTextLabel::get_total_character_count() const {
int tc = 0;
- for (int i = 0; i < current_frame->lines.size(); i++)
+ for (int i = 0; i < current_frame->lines.size(); i++) {
tc += current_frame->lines[i].char_count;
+ }
return tc;
}
@@ -2709,8 +2794,9 @@ Size2 RichTextLabel::get_minimum_size() const {
Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) {
for (int i = 0; i < custom_effects.size(); i++) {
- if (!custom_effects[i].is_valid())
+ if (!custom_effects[i].is_valid()) {
continue;
+ }
if (custom_effects[i]->get_bbcode() == p_bbcode_identifier) {
return custom_effects[i];
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 98b6de0696..e7950bec98 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -62,8 +62,9 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
accept_event();
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (b->is_pressed()) {
double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
@@ -175,24 +176,28 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (p_event->is_pressed()) {
if (p_event->is_action("ui_left")) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_right")) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_up")) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_down")) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_home")) {
@@ -213,35 +218,39 @@ void ScrollBar::_notification(int p_what) {
Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll");
Ref<StyleBox> grabber;
- if (drag.active)
+ if (drag.active) {
grabber = get_theme_stylebox("grabber_pressed");
- else if (highlight == HIGHLIGHT_RANGE)
+ } else if (highlight == HIGHLIGHT_RANGE) {
grabber = get_theme_stylebox("grabber_highlight");
- else
+ } else {
grabber = get_theme_stylebox("grabber");
+ }
Point2 ofs;
decr->draw(ci, Point2());
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.x += decr->get_width();
- else
+ } else {
ofs.y += decr->get_height();
+ }
Size2 area = get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
area.width -= incr->get_width() + decr->get_width();
- else
+ } else {
area.height -= incr->get_height() + decr->get_height();
+ }
bg->draw(ci, Rect2(ofs, area));
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.width += area.width;
- else
+ } else {
ofs.height += area.height;
+ }
incr->draw(ci, ofs);
Rect2 grabber_rect;
@@ -385,8 +394,9 @@ double ScrollBar::get_grabber_min_size() const {
double ScrollBar::get_grabber_size() const {
float range = get_max() - get_min();
- if (range <= 0)
+ if (range <= 0) {
return 0;
+ }
float page = (get_page() > 0) ? get_page() : 0;
/*
@@ -444,10 +454,11 @@ double ScrollBar::get_click_pos(const Point2 &p_pos) const {
pos -= get_area_offset();
float area = get_area_size();
- if (area == 0)
+ if (area == 0) {
return 0;
- else
+ } else {
return pos / area;
+ }
}
double ScrollBar::get_grabber_offset() const {
@@ -498,8 +509,9 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
- if (mb->get_button_index() != 1)
+ if (mb->get_button_index() != 1) {
return;
+ }
if (mb->is_pressed()) {
drag_node_speed = Vector2();
@@ -537,11 +549,13 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
drag_node_accum -= motion;
Vector2 diff = drag_node_from + drag_node_accum;
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
set_value(diff.x);
+ }
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_value(diff.y);
+ }
time_since_motion = 0;
}
@@ -610,8 +624,9 @@ ScrollBar::ScrollBar(Orientation p_orientation) {
target_scroll = 0;
smooth_scroll_enabled = false;
- if (focus_by_default)
+ if (focus_by_default) {
set_focus_mode(FOCUS_ALL);
+ }
set_step(0);
}
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 0b00883a71..b72b913af0 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -42,12 +42,15 @@ Size2 ScrollContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
if (!scroll_h) {
@@ -121,14 +124,17 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
- if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())))
+ if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()))) {
return;
+ }
- if (mb->get_button_index() != BUTTON_LEFT)
+ if (mb->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (mb->is_pressed()) {
if (drag_touching) {
@@ -176,14 +182,16 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
drag_accum = -motion;
}
Vector2 diff = drag_from + drag_accum;
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(diff.x);
- else
+ } else {
drag_accum.x = 0;
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(diff.y);
- else
+ } else {
drag_accum.y = 0;
+ }
time_since_motion = 0;
}
}
@@ -199,8 +207,9 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ScrollContainer::_update_scrollbar_position() {
@@ -263,20 +272,25 @@ void ScrollContainer::_notification(int p_what) {
size -= sb->get_minimum_size();
ofs += sb->get_offset();
- if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.y -= h_scroll->get_minimum_size().y;
+ }
- if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.x -= v_scroll->get_minimum_size().x;
+ }
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
child_max_size.x = MAX(child_max_size.x, minsize.x);
child_max_size.y = MAX(child_max_size.y, minsize.y);
@@ -284,17 +298,19 @@ void ScrollContainer::_notification(int p_what) {
Rect2 r = Rect2(-scroll, minsize);
if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags() & SIZE_EXPAND)) {
r.position.x = 0;
- if (c->get_h_size_flags() & SIZE_EXPAND)
+ if (c->get_h_size_flags() & SIZE_EXPAND) {
r.size.width = MAX(size.width, minsize.width);
- else
+ } else {
r.size.width = minsize.width;
+ }
}
if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags() & SIZE_EXPAND)) {
r.position.y = 0;
- if (c->get_v_size_flags() & SIZE_EXPAND)
+ if (c->get_v_size_flags() & SIZE_EXPAND) {
r.size.height = MAX(size.height, minsize.height);
- else
+ } else {
r.size.height = minsize.height;
+ }
}
r.position += ofs;
fit_child_in_rect(c, r);
@@ -337,10 +353,12 @@ void ScrollContainer::_notification(int p_what) {
turnoff_v = true;
}
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(pos.x);
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(pos.y);
+ }
float sgn_x = drag_speed.x < 0 ? -1 : 1;
float val_x = Math::abs(drag_speed.x);
@@ -506,20 +524,24 @@ String ScrollContainer::get_configuration_warning() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
found++;
}
- if (found != 1)
+ if (found != 1) {
return TTR("ScrollContainer is intended to work with a single child control.\nUse a container as child (VBox, HBox, etc.), or a Control and set the custom minimum size manually.");
- else
+ } else {
return "";
+ }
}
HScrollBar *ScrollContainer::get_h_scrollbar() {
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index a529c52065..9f5b9c40c2 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -46,10 +46,11 @@ bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
}
String ShortCut::get_as_text() const {
- if (shortcut.is_valid())
+ if (shortcut.is_valid()) {
return shortcut->as_text();
- else
+ } else {
return "None";
+ }
}
bool ShortCut::is_valid() const {
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index b48922bf32..3dd5e022f0 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -38,10 +38,11 @@ Size2 Slider::get_minimum_size() const {
Ref<Texture2D> grabber = get_theme_icon("grabber");
Size2i rs = grabber->get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
return Size2i(ss.width, MAX(ss.height, rs.height));
- else
+ } else {
return Size2i(MAX(ss.width, rs.width), ss.height);
+ }
}
void Slider::_gui_input(Ref<InputEvent> p_event) {
@@ -60,10 +61,11 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
- else
+ } else {
set_as_ratio(((double)grab.pos - (grab_width / 2.0)) / max);
+ }
grab.active = true;
grab.uvalue = get_as_ratio();
} else {
@@ -85,11 +87,13 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
Size2i size = get_size();
Ref<Texture2D> grabber = get_theme_icon("grabber");
float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
motion = -motion;
+ }
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
- if (areasize <= 0)
+ if (areasize <= 0) {
return;
+ }
float umotion = motion / float(areasize);
set_as_ratio(grab.uvalue + umotion);
}
@@ -97,24 +101,28 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (!mm.is_valid() && !mb.is_valid()) {
if (p_event->is_action_pressed("ui_left", true)) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_right", true)) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_up", true)) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_down", true)) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action("ui_home") && p_event->is_pressed()) {
@@ -165,8 +173,9 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
for (int i = 0; i < ticks; i++) {
- if (!ticks_on_borders && (i == 0 || i + 1 == ticks))
+ if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
}
@@ -182,8 +191,9 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
for (int i = 0; i < ticks; i++) {
- if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks)))
+ if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
}
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index a82e9f7009..3670f13705 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -41,10 +41,12 @@ Size2 SpinBox::get_minimum_size() const {
void SpinBox::_value_changed(double) {
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
- if (prefix != "")
+ if (prefix != "") {
value = prefix + " " + value;
- if (suffix != "")
+ }
+ if (suffix != "") {
value += " " + suffix;
+ }
line_edit->set_text(value);
}
@@ -159,8 +161,9 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
void SpinBox::_line_edit_focus_exit() {
// discontinue because the focus_exit was caused by right-click context menu
- if (line_edit->get_menu()->is_visible())
+ if (line_edit->get_menu()->is_visible()) {
return;
+ }
_text_entered(line_edit->get_text());
}
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 14a4edc609..5c60153d91 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -38,13 +38,16 @@ Control *SplitContainer::_getch(int p_idx) const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
- if (idx == p_idx)
+ if (idx == p_idx) {
return c;
+ }
idx++;
}
@@ -126,14 +129,16 @@ Size2 SplitContainer::get_minimum_size() const {
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
for (int i = 0; i < 2; i++) {
- if (!_getch(i))
+ if (!_getch(i)) {
break;
+ }
if (i == 1) {
- if (vertical)
+ if (vertical) {
minimum.height += sep;
- else
+ } else {
minimum.width += sep;
+ }
}
Size2 ms = _getch(i)->get_combined_minimum_size();
@@ -157,27 +162,32 @@ void SplitContainer::_notification(int p_what) {
} break;
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
} break;
case NOTIFICATION_DRAW: {
- if (!_getch(0) || !_getch(1))
+ if (!_getch(0) || !_getch(1)) {
return;
+ }
- if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide")))
+ if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) {
return;
+ }
- if (dragger_visibility != DRAGGER_VISIBLE)
+ if (dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0;
Ref<Texture2D> tex = get_theme_icon("grabber");
Size2 size = get_size();
- if (vertical)
+ if (vertical) {
draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
- else
+ } else {
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
+ }
} break;
case NOTIFICATION_THEME_CHANGED: {
minimum_size_changed();
@@ -186,8 +196,9 @@ void SplitContainer::_notification(int p_what) {
}
void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
- if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
+ if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
Ref<InputEventMouseButton> mb = p_event;
@@ -219,19 +230,22 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid()) {
bool mouse_inside_state = false;
- if (vertical)
+ if (vertical) {
mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation");
- else
+ } else {
mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation");
+ }
if (mouse_inside != mouse_inside_state) {
mouse_inside = mouse_inside_state;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
}
- if (!dragging)
+ if (!dragging) {
return;
+ }
split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
should_clamp_split_offset = true;
@@ -241,18 +255,21 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
- if (dragging)
+ if (dragging) {
return (vertical ? CURSOR_VSPLIT : CURSOR_HSPLIT);
+ }
if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) {
int sep = get_theme_constant("separation");
if (vertical) {
- if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep)
+ if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
return CURSOR_VSPLIT;
+ }
} else {
- if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep)
+ if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) {
return CURSOR_HSPLIT;
+ }
}
}
@@ -260,8 +277,9 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
}
void SplitContainer::set_split_offset(int p_offset) {
- if (split_offset == p_offset)
+ if (split_offset == p_offset) {
return;
+ }
split_offset = p_offset;
@@ -279,8 +297,9 @@ void SplitContainer::clamp_split_offset() {
}
void SplitContainer::set_collapsed(bool p_collapsed) {
- if (collapsed == p_collapsed)
+ if (collapsed == p_collapsed) {
return;
+ }
collapsed = p_collapsed;
queue_sort();
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 7d0dabeaca..4e1ad2ae05 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -34,13 +34,15 @@
#include "scene/main/viewport.h"
Size2 SubViewportContainer::get_minimum_size() const {
- if (stretch)
+ if (stretch) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
Size2 minsize = c->get_size();
ms.width = MAX(ms.width, minsize.width);
@@ -62,18 +64,21 @@ bool SubViewportContainer::is_stretch_enabled() const {
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
ERR_FAIL_COND(p_shrink < 1);
- if (shrink == p_shrink)
+ if (shrink == p_shrink) {
return;
+ }
shrink = p_shrink;
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -87,13 +92,15 @@ int SubViewportContainer::get_stretch_shrink() const {
void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_RESIZED) {
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -102,13 +109,15 @@ void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
c->set_update_mode(SubViewport::UPDATE_ALWAYS);
- else
+ } else {
c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ }
c->set_handle_input_locally(false); //do not handle input locally here
}
@@ -117,20 +126,23 @@ void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (stretch)
+ if (stretch) {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
- else
+ } else {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
+ }
}
}
}
void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -144,16 +156,18 @@ void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->input(ev);
}
}
void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -167,8 +181,9 @@ void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->unhandled_input(ev);
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 4d861f380d..97b8362214 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -36,8 +36,9 @@
#include "scene/gui/texture_rect.h"
int TabContainer::_get_top_margin() const {
- if (!tabs_visible)
+ if (!tabs_visible) {
return 0;
+ }
// Respect the minimum tab height.
Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
@@ -53,12 +54,14 @@ int TabContainer::_get_top_margin() const {
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->has_meta("_tab_icon"))
+ if (!c->has_meta("_tab_icon")) {
continue;
+ }
Ref<Texture2D> tex = c->get_meta("_tab_icon");
- if (!tex.is_valid())
+ if (!tex.is_valid()) {
continue;
+ }
content_height = MAX(content_height, tex->get_size().height);
}
@@ -73,8 +76,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
Size2 size = get_size();
// Click must be on tabs in the tab header area.
- if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin())
+ if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin()) {
return;
+ }
// Handle menu button.
Ref<Texture2D> menu = get_theme_icon("menu");
@@ -91,8 +95,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
// Do not activate tabs when tabs is empty.
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return;
+ }
Vector<Control *> tabs = _get_tabs();
@@ -218,12 +223,15 @@ void TabContainer::_notification(int p_what) {
int header_width = get_size().width - side_margin * 2;
// Find the width of the header area.
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
- if (buttons_visible_cache)
+ }
+ if (buttons_visible_cache) {
header_width -= increment->get_width() + decrement->get_width();
- if (popup || buttons_visible_cache)
+ }
+ if (popup || buttons_visible_cache) {
header_width += side_margin;
+ }
// Find the width of all tabs after first_tab_cache.
int all_tabs_width = 0;
@@ -236,8 +244,9 @@ void TabContainer::_notification(int p_what) {
for (int i = first_tab_cache - 1; i >= 0; i--) {
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width)
+ if (all_tabs_width + tab_width > header_width) {
break;
+ }
all_tabs_width += tab_width;
first_tab_cache--;
@@ -275,8 +284,9 @@ void TabContainer::_notification(int p_what) {
int header_x = side_margin;
int header_width = size.width - side_margin * 2;
int header_height = _get_top_margin();
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
+ }
// Check if all tabs would fit into the header area.
int all_tabs_width = 0;
@@ -313,8 +323,9 @@ void TabContainer::_notification(int p_what) {
continue;
}
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
+ if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0) {
break;
+ }
all_tabs_width += tab_width;
tab_widths.push_back(tab_width);
}
@@ -373,8 +384,9 @@ void TabContainer::_notification(int p_what) {
if (icon.is_valid()) {
int y = y_center - (icon->get_height() / 2);
icon->draw(canvas, Point2i(x_content, y));
- if (text != "")
+ if (text != "") {
x_content += icon->get_width() + icon_text_distance;
+ }
}
}
@@ -390,10 +402,11 @@ void TabContainer::_notification(int p_what) {
x = get_size().width;
if (popup) {
x -= menu->get_width();
- if (menu_hovered)
+ if (menu_hovered) {
menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
- else
+ } else {
menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
+ }
}
// Draw the navigation buttons.
@@ -437,8 +450,9 @@ void TabContainer::_on_mouse_exited() {
int TabContainer::_get_tab_width(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
- if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index))
+ if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index)) {
return 0;
+ }
// Get the width of the text displayed on the tab.
Ref<Font> font = get_theme_font("font");
@@ -450,8 +464,9 @@ int TabContainer::_get_tab_width(int p_index) const {
Ref<Texture2D> icon = control->get_meta("_tab_icon");
if (icon.is_valid()) {
width += icon->get_width();
- if (text != "")
+ if (text != "") {
width += get_theme_constant("hseparation");
+ }
}
}
@@ -474,8 +489,9 @@ Vector<Control *> TabContainer::_get_tabs() const {
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
Control *control = Object::cast_to<Control>(get_child(i));
- if (!control || control->is_toplevel_control())
+ if (!control || control->is_toplevel_control()) {
continue;
+ }
controls.push_back(control);
}
@@ -490,16 +506,18 @@ void TabContainer::add_child_notify(Node *p_child) {
Container::add_child_notify(p_child);
Control *c = Object::cast_to<Control>(p_child);
- if (!c)
+ if (!c) {
return;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
return;
+ }
bool first = false;
- if (get_tab_count() != 1)
+ if (get_tab_count() != 1) {
c->hide();
- else {
+ } else {
c->show();
//call_deferred("set_current_tab",0);
first = true;
@@ -507,8 +525,9 @@ void TabContainer::add_child_notify(Node *p_child) {
previous = 0;
}
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
Ref<StyleBox> sb = get_theme_stylebox("panel");
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
@@ -517,8 +536,9 @@ void TabContainer::add_child_notify(Node *p_child) {
update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
- if (first && is_inside_tree())
+ if (first && is_inside_tree()) {
emit_signal("tab_changed", current);
+ }
}
int TabContainer::get_tab_count() const {
@@ -538,22 +558,24 @@ void TabContainer::set_current_tab(int p_current) {
if (i == current) {
c->show();
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT)));
c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM)));
- } else
+ } else {
c->hide();
+ }
}
_change_notify("current_tab");
- if (pending_previous == current)
+ if (pending_previous == current) {
emit_signal("tab_selected", current);
- else {
+ } else {
previous = pending_previous;
emit_signal("tab_selected", current);
emit_signal("tab_changed", current);
@@ -572,18 +594,20 @@ int TabContainer::get_previous_tab() const {
Control *TabContainer::get_tab_control(int p_idx) const {
Vector<Control *> tabs = _get_tabs();
- if (p_idx >= 0 && p_idx < tabs.size())
+ if (p_idx >= 0 && p_idx < tabs.size()) {
return tabs[p_idx];
- else
+ } else {
return nullptr;
+ }
}
Control *TabContainer::get_current_tab_control() const {
Vector<Control *> tabs = _get_tabs();
- if (current >= 0 && current < tabs.size())
+ if (current >= 0 && current < tabs.size()) {
return tabs[current];
- else
+ } else {
return nullptr;
+ }
}
void TabContainer::remove_child_notify(Node *p_child) {
@@ -598,22 +622,26 @@ void TabContainer::remove_child_notify(Node *p_child) {
void TabContainer::_update_current_tab() {
int tc = get_tab_count();
- if (current >= tc)
+ if (current >= tc) {
current = tc - 1;
- if (current < 0)
+ }
+ if (current < 0) {
current = 0;
- else
+ } else {
set_current_tab(current);
+ }
}
Variant TabContainer::get_drag_data(const Point2 &p_point) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -635,12 +663,14 @@ Variant TabContainer::get_drag_data(const Point2 &p_point) {
}
bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tabc_element") {
NodePath from_path = d["from_path"];
@@ -660,22 +690,25 @@ bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) c
}
void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tabc_element") {
int tab_from_id = d["tabc_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(get_tab_control(tab_from_id), hover_now);
set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) {
@@ -686,8 +719,9 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
Control *moving_tabc = from_tabc->get_tab_control(tab_from_id);
from_tabc->remove_child(moving_tabc);
add_child(moving_tabc);
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(moving_tabc, hover_now);
set_current_tab(hover_now);
emit_signal("tab_changed", hover_now);
@@ -698,12 +732,14 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
}
int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return -1;
+ }
// must be on tabs in the tab header area.
- if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin())
+ if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin()) {
return -1;
+ }
Size2 size = get_size();
int right_ofs = 0;
@@ -748,18 +784,20 @@ TabContainer::TabAlign TabContainer::get_tab_align() const {
}
void TabContainer::set_tabs_visible(bool p_visible) {
- if (p_visible == tabs_visible)
+ if (p_visible == tabs_visible) {
return;
+ }
tabs_visible = p_visible;
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (p_visible)
+ if (p_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
- else
+ } else {
c->set_margin(MARGIN_TOP, 0);
+ }
}
update();
@@ -784,10 +822,11 @@ void TabContainer::set_tab_title(int p_tab, const String &p_title) {
String TabContainer::get_tab_title(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, "");
- if (child->has_meta("_tab_name"))
+ if (child->has_meta("_tab_name")) {
return child->get_meta("_tab_name");
- else
+ } else {
return child->get_name();
+ }
}
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
@@ -800,10 +839,11 @@ void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, Ref<Texture2D>());
- if (child->has_meta("_tab_icon"))
+ if (child->has_meta("_tab_icon")) {
return child->get_meta("_tab_icon");
- else
+ } else {
return Ref<Texture2D>();
+ }
}
void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
@@ -816,10 +856,11 @@ void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
bool TabContainer::get_tab_disabled(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_disabled"))
+ if (child->has_meta("_tab_disabled")) {
return child->get_meta("_tab_disabled");
- else
+ } else {
return false;
+ }
}
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
@@ -844,10 +885,11 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
bool TabContainer::get_tab_hidden(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_hidden"))
+ if (child->has_meta("_tab_hidden")) {
return child->get_meta("_tab_hidden");
- else
+ } else {
return false;
+ }
}
void TabContainer::get_translatable_strings(List<String> *p_strings) const {
@@ -855,13 +897,15 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const {
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->has_meta("_tab_name"))
+ if (!c->has_meta("_tab_name")) {
continue;
+ }
String name = c->get_meta("_tab_name");
- if (name != "")
+ if (name != "") {
p_strings->push_back(name);
+ }
}
}
@@ -872,8 +916,9 @@ Size2 TabContainer::get_minimum_size() const {
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size)
+ if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(ms.x, cms.x);
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 4c3fa2f038..8f71aa7cab 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -47,18 +47,20 @@ Size2 Tabs::get_minimum_size() const {
Ref<Texture2D> tex = tabs[i].icon;
if (tex.is_valid()) {
ms.height = MAX(ms.height, tex->get_size().height);
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
ms.width += get_theme_constant("hseparation");
+ }
}
ms.width += Math::ceil(font->get_string_size(tabs[i].xl_text).width);
- if (tabs[i].disabled)
+ if (tabs[i].disabled) {
ms.width += tab_disabled->get_minimum_size().width;
- else if (current == i)
+ } else if (current == i) {
ms.width += tab_fg->get_minimum_size().width;
- else
+ } else {
ms.width += tab_bg->get_minimum_size().width;
+ }
if (tabs[i].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[i].right_button;
@@ -293,8 +295,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture2D> icon = tabs[i].icon;
if (icon.is_valid()) {
icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
w += icon->get_width() + get_theme_constant("hseparation");
+ }
}
font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].xl_text, col, tabs[i].size_text);
@@ -313,10 +316,11 @@ void Tabs::_notification(int p_what) {
rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
if (rb_hover == i) {
- if (rb_pressing)
+ if (rb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, rb_rect);
- else
+ } else {
style->draw(ci, rb_rect);
+ }
}
rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -336,10 +340,11 @@ void Tabs::_notification(int p_what) {
cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
if (!tabs[i].disabled && cb_hover == i) {
- if (cb_pressing)
+ if (cb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, cb_rect);
- else
+ } else {
style->draw(ci, cb_rect);
+ }
}
cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -353,15 +358,17 @@ void Tabs::_notification(int p_what) {
if (offset > 0 || missing_right) {
int vofs = (get_size().height - incr->get_size().height) / 2;
- if (offset > 0)
+ if (offset > 0) {
draw_texture(highlight_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
- else
+ } else {
draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));
+ }
- if (missing_right)
+ if (missing_right) {
draw_texture(highlight_arrow == 1 ? incr_hl : incr, Point2(limit + decr->get_size().width, vofs));
- else
+ } else {
draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));
+ }
buttons_visible = true;
} else {
@@ -376,8 +383,9 @@ int Tabs::get_tab_count() const {
}
void Tabs::set_current_tab(int p_current) {
- if (current == p_current)
+ if (current == p_current) {
return;
+ }
ERR_FAIL_INDEX(p_current, get_tab_count());
current = p_current;
@@ -587,29 +595,34 @@ void Tabs::clear_tabs() {
void Tabs::remove_tab(int p_idx) {
ERR_FAIL_INDEX(p_idx, tabs.size());
tabs.remove(p_idx);
- if (current >= p_idx)
+ if (current >= p_idx) {
current--;
+ }
_update_cache();
call_deferred("_update_hover");
update();
minimum_size_changed();
- if (current < 0)
+ if (current < 0) {
current = 0;
- if (current >= tabs.size())
+ }
+ if (current >= tabs.size()) {
current = tabs.size() - 1;
+ }
_ensure_no_over_offset();
}
Variant Tabs::get_drag_data(const Point2 &p_point) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -635,12 +648,14 @@ Variant Tabs::get_drag_data(const Point2 &p_point) {
}
bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tab_element") {
NodePath from_path = d["from_path"];
@@ -660,22 +675,25 @@ bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
}
void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tab_element") {
int tab_from_id = d["tab_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_tab(tab_from_id, hover_now);
emit_signal("reposition_active_tab_request", hover_now);
set_current_tab(hover_now);
@@ -684,11 +702,13 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
Node *from_node = get_node(from_path);
Tabs *from_tabs = Object::cast_to<Tabs>(from_node);
if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
- if (tab_from_id >= from_tabs->get_tab_count())
+ if (tab_from_id >= from_tabs->get_tab_count()) {
return;
+ }
Tab moving_tab = from_tabs->tabs[tab_from_id];
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count();
+ }
tabs.insert(hover_now, moving_tab);
from_tabs->remove_tab(tab_from_id);
set_current_tab(hover_now);
@@ -723,8 +743,9 @@ Tabs::TabAlign Tabs::get_tab_align() const {
}
void Tabs::move_tab(int from, int to) {
- if (from == to)
+ if (from == to) {
return;
+ }
ERR_FAIL_INDEX(from, tabs.size());
ERR_FAIL_INDEX(to, tabs.size());
@@ -750,18 +771,20 @@ int Tabs::get_tab_width(int p_idx) const {
Ref<Texture2D> tex = tabs[p_idx].icon;
if (tex.is_valid()) {
x += tex->get_width();
- if (tabs[p_idx].text != "")
+ if (tabs[p_idx].text != "") {
x += get_theme_constant("hseparation");
+ }
}
x += Math::ceil(font->get_string_size(tabs[p_idx].xl_text).width);
- if (tabs[p_idx].disabled)
+ if (tabs[p_idx].disabled) {
x += tab_disabled->get_minimum_size().width;
- else if (current == p_idx)
+ } else if (current == p_idx) {
x += tab_fg->get_minimum_size().width;
- else
+ } else {
x += tab_bg->get_minimum_size().width;
+ }
if (tabs[p_idx].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[p_idx].right_button;
@@ -779,8 +802,9 @@ int Tabs::get_tab_width(int p_idx) const {
}
void Tabs::_ensure_no_over_offset() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -803,11 +827,13 @@ void Tabs::_ensure_no_over_offset() {
}
void Tabs::ensure_tab_visible(int p_idx) {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (tabs.size() == 0)
+ if (tabs.size() == 0) {
return;
+ }
ERR_FAIL_INDEX(p_idx, tabs.size());
if (p_idx == offset) {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c5067c9efd..52aee8f089 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -89,23 +89,29 @@ static bool _is_pair_symbol(CharType c) {
}
static CharType _get_right_pair_symbol(CharType c) {
- if (c == '"')
+ if (c == '"') {
return '"';
- if (c == '\'')
+ }
+ if (c == '\'') {
return '\'';
- if (c == '(')
+ }
+ if (c == '(') {
return ')';
- if (c == '[')
+ }
+ if (c == '[') {
return ']';
- if (c == '{')
+ }
+ if (c == '{') {
return '}';
+ }
return 0;
}
static int _find_first_non_whitespace_column_of_line(const String &line) {
int left = 0;
- while (left < line.length() && _is_whitespace(line[left]))
+ while (left < line.length() && _is_whitespace(line[left])) {
left++;
+ }
return left;
}
@@ -138,8 +144,9 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
text.write[p_line].region_info.clear();
for (int i = 0; i < len; i++) {
- if (!_is_symbol(str[i]))
+ if (!_is_symbol(str[i])) {
continue;
+ }
if (str[i] == '\\') {
i++; // Skip quoted anything.
continue;
@@ -269,8 +276,9 @@ int TextEdit::Text::get_max_width(bool p_exclude_hidden) const {
int max = 0;
for (int i = 0; i < text.size(); i++) {
- if (!p_exclude_hidden || !is_hidden(i))
+ if (!p_exclude_hidden || !is_hidden(i)) {
max = MAX(max, get_line_width(i));
+ }
}
return max;
}
@@ -307,10 +315,11 @@ int TextEdit::Text::get_char_width(CharType c, CharType next_c, int px) const {
if (c == '\t') {
int left = px % tab_w;
- if (left == 0)
+ if (left == 0) {
w = tab_w;
- else
+ } else {
w = tab_w - px % tab_w; // Is right.
+ }
} else {
w = font->get_char_size(c, next_c).width;
}
@@ -337,8 +346,9 @@ void TextEdit::_update_scrollbars() {
int visible_width = size.width - cache.style_normal->get_minimum_size().width;
int total_width = text.get_max_width(true) + vmin.x;
- if (line_numbers)
+ if (line_numbers) {
total_width += cache.line_number_w;
+ }
if (draw_breakpoint_gutter || draw_bookmark_gutter) {
total_width += cache.breakpoint_gutter_width;
@@ -397,8 +407,9 @@ void TextEdit::_update_scrollbars() {
h_scroll->show();
h_scroll->set_max(total_width);
h_scroll->set_page(visible_width);
- if (cursor.x_ofs > (total_width - visible_width))
+ if (cursor.x_ofs > (total_width - visible_width)) {
cursor.x_ofs = (total_width - visible_width);
+ }
if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
h_scroll->set_value(cursor.x_ofs);
}
@@ -586,10 +597,12 @@ void TextEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
- if (cursor_changed_dirty)
+ if (cursor_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- if (text_changed_dirty)
+ }
+ if (text_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
_update_wrap_at();
} break;
case NOTIFICATION_RESIZED: {
@@ -705,8 +718,9 @@ void TextEdit::_notification(int p_what) {
cache.style_readonly->draw(ci, Rect2(Point2(), size));
draw_caret = false;
}
- if (has_focus())
+ if (has_focus()) {
cache.style_focus->draw(ci, Rect2(Point2(), size));
+ }
int ascent = cache.font->get_ascent();
@@ -787,10 +801,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_open_match_line = i;
@@ -800,12 +815,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_open_match_line != -1)
+ if (brace_open_match_line != -1) {
break;
+ }
}
- if (!brace_open_matching)
+ if (!brace_open_matching) {
brace_open_mismatch = true;
+ }
}
}
@@ -850,10 +867,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_close_match_line = i;
@@ -863,12 +881,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_close_match_line != -1)
+ if (brace_close_match_line != -1) {
break;
+ }
}
- if (!brace_close_matching)
+ if (!brace_close_matching) {
brace_close_mismatch = true;
+ }
}
}
}
@@ -951,8 +971,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= minimap_draw_amount)
+ if (i >= minimap_draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1039,8 +1060,9 @@ void TextEdit::_notification(int p_what) {
for (int i = 0; i < draw_amount; i++) {
line++;
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
while (is_line_hidden(line)) {
line++;
@@ -1049,8 +1071,9 @@ void TextEdit::_notification(int p_what) {
}
}
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
const String &fullstr = text[line];
@@ -1070,8 +1093,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= draw_amount)
+ if (i >= draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1080,8 +1104,9 @@ void TextEdit::_notification(int p_what) {
indent_px = 0;
}
- if (line_wrap_index > 0)
+ if (line_wrap_index > 0) {
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
+ }
int char_margin = xmargin_beg - cursor.x_ofs;
char_margin += indent_px;
@@ -1096,19 +1121,22 @@ void TextEdit::_notification(int p_what) {
int ofs_y = (i * get_row_height() + cache.line_spacing / 2) + ofs_readonly;
ofs_y -= cursor.wrap_ofs * get_row_height();
- if (smooth_scroll_enabled)
+ if (smooth_scroll_enabled) {
ofs_y += (-get_v_scroll_offset()) * get_row_height();
+ }
// Check if line contains highlighted word.
int highlighted_text_col = -1;
int search_text_col = -1;
int highlighted_word_col = -1;
- if (!search_text.empty())
+ if (!search_text.empty()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, 0);
+ }
- if (highlighted_text.length() != 0 && highlighted_text != search_text)
+ if (highlighted_text.length() != 0 && highlighted_text != search_text) {
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
+ }
if (select_identifiers_enabled && highlighted_word.length() != 0) {
if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') {
@@ -1283,8 +1311,9 @@ void TextEdit::_notification(int p_what) {
if (search_text_col != -1) {
// If we are at the end check for new search result on same line.
- if (j >= search_text_col + search_text.length())
+ if (j >= search_text_col + search_text.length()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, j);
+ }
in_search_result = j >= search_text_col && j < search_text_col + search_text.length();
@@ -1321,10 +1350,12 @@ void TextEdit::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color);
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color);
- if (j == search_text_col)
+ if (j == search_text_col) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color);
- if (j == search_text_col + search_text.length() - 1)
+ }
+ if (j == search_text_col + search_text.length() - 1) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color);
+ }
}
if (highlight_all_occurrences && !only_whitespaces_highlighted) {
@@ -1358,15 +1389,17 @@ void TextEdit::_notification(int p_what) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
if ((brace_open_match_line == line && brace_open_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
- if (brace_open_mismatch)
+ if (brace_open_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
if ((brace_close_match_line == line && brace_close_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j + 1 && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
- if (brace_close_mismatch)
+ if (brace_close_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
}
@@ -1384,15 +1417,17 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -1478,15 +1513,17 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -1545,8 +1582,9 @@ void TextEdit::_notification(int p_what) {
if (completion_options_size < 50) {
for (int i = 0; i < completion_options_size; i++) {
int w2 = MIN(cache.font->get_string_size(completion_options[i].display).x, cmax_width);
- if (w2 > w)
+ if (w2 > w) {
w = w2;
+ }
}
} else {
w = cmax_width;
@@ -1574,8 +1612,9 @@ void TextEdit::_notification(int p_what) {
completion_rect.size.width = w + 2;
completion_rect.size.height = h;
- if (completion_options_size <= maxlines)
+ if (completion_options_size <= maxlines) {
scrollw = 0;
+ }
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
@@ -1716,8 +1755,9 @@ void TextEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect());
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled) {
@@ -1731,8 +1771,9 @@ void TextEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
if (has_focus()) {
@@ -1760,8 +1801,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
&new_line, &new_column);
int to_col_offset = 0;
- if (get_selection_from_line() == get_selection_to_line())
+ if (get_selection_from_line() == get_selection_to_line()) {
to_col_offset = 1;
+ }
_insert_text(get_selection_to_line(),
get_selection_to_column() + to_col_offset,
@@ -1868,20 +1910,24 @@ void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column
}
void TextEdit::backspace_at_cursor() {
- if (readonly)
+ if (readonly) {
return;
+ }
- if (cursor.column == 0 && cursor.line == 0)
+ if (cursor.column == 0 && cursor.line == 0) {
return;
+ }
int prev_line = cursor.column ? cursor.line : cursor.line - 1;
int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
set_line_as_hidden(prev_line, true);
+ }
if (is_line_set_as_breakpoint(cursor.line)) {
- if (!text.is_breakpoint(prev_line))
+ if (!text.is_breakpoint(prev_line)) {
emit_signal("breakpoint_toggled", prev_line);
+ }
set_line_as_breakpoint(prev_line, true);
}
@@ -1956,8 +2002,9 @@ void TextEdit::indent_right() {
int spaces_to_add = _calculate_spaces_till_next_right_indent(left);
// Since we will add this much spaces we want move whole selection and cursor by this much.
selection_offset = spaces_to_add;
- for (int j = 0; j < spaces_to_add; j++)
+ for (int j = 0; j < spaces_to_add; j++) {
line_text = ' ' + line_text;
+ }
} else {
line_text = '\t' + line_text;
}
@@ -2034,8 +2081,9 @@ void TextEdit::indent_left() {
int TextEdit::_calculate_spaces_till_next_left_indent(int column) {
int spaces_till_indent = column % indent_size;
- if (spaces_till_indent == 0)
+ if (spaces_till_indent == 0) {
spaces_till_indent = indent_size;
+ }
return spaces_till_indent;
}
@@ -2054,14 +2102,16 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
if (is_wrap_enabled() || is_hiding_enabled()) {
int f_ofs = num_lines_from_rows(first_vis_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
- if (rows < 0)
+ if (rows < 0) {
row = first_vis_line - f_ofs;
- else
+ } else {
row = first_vis_line + f_ofs;
+ }
}
- if (row < 0)
+ if (row < 0) {
row = 0; // TODO.
+ }
int col = 0;
@@ -2079,8 +2129,9 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
for (int i = 0; i < wrap_index + 1; i++) {
row_end_col += rows2[i].length();
}
- if (col >= row_end_col)
+ if (col >= row_end_col) {
col -= 1;
+ }
}
}
@@ -2187,8 +2238,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb.is_valid()) {
if (completion_active && completion_rect.has_point(mb->get_position())) {
- if (!mb->is_pressed())
+ if (!mb->is_pressed()) {
return;
+ }
if (mb->get_button_index() == BUTTON_WHEEL_UP) {
if (completion_index > 0) {
@@ -2210,8 +2262,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_current = completion_options[completion_index];
update();
- if (mb->is_doubleclick())
+ if (mb->is_doubleclick()) {
_confirm_completion();
+ }
}
return;
} else {
@@ -2431,8 +2484,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_scroll_down(delta);
}
h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100);
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
return;
}
@@ -2479,8 +2533,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
Ref<InputEventKey> k = p_gui_input;
@@ -2502,16 +2557,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
if (completion_active) {
- if (readonly)
+ if (readonly) {
return;
+ }
bool valid = true;
- if (k->get_command() || k->get_metakey())
+ if (k->get_command() || k->get_metakey()) {
valid = false;
+ }
if (valid) {
if (!k->get_alt()) {
@@ -2543,8 +2601,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_keycode() == KEY_PAGEUP) {
completion_index -= get_theme_constant("completion_lines");
- if (completion_index < 0)
+ if (completion_index < 0) {
completion_index = 0;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2553,8 +2612,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_keycode() == KEY_PAGEDOWN) {
completion_index += get_theme_constant("completion_lines");
- if (completion_index >= completion_options.size())
+ if (completion_index >= completion_options.size()) {
completion_index = completion_options.size() - 1;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2722,16 +2782,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
case KEY_HOME:
case KEY_END:
// Ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys).
- if (k->get_command() || k->get_shift() || k->get_alt())
+ if (k->get_command() || k->get_shift() || k->get_alt()) {
break;
+ }
unselect = true;
break;
default:
- if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey())
+ if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey()) {
clear = true;
- if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode()))
+ }
+ if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode())) {
clear = false;
+ }
}
if (unselect) {
@@ -2750,8 +2813,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(selection.from_column);
update();
}
- if (dobreak)
+ if (dobreak) {
return;
+ }
}
selection.selecting_text = false;
@@ -2763,8 +2827,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
switch (k->get_keycode()) {
case KEY_KP_ENTER:
case KEY_ENTER: {
- if (readonly)
+ if (readonly) {
break;
+ }
String ins = "\n";
@@ -2794,8 +2859,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (is_folded(cursor.line))
+ if (is_folded(cursor.line)) {
unfold_line(cursor.line);
+ }
bool brace_indent = false;
@@ -2883,11 +2949,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_TAB: {
- if (k->get_command())
+ if (k->get_command()) {
break; // Avoid tab when command.
+ }
- if (readonly)
+ if (readonly) {
break;
+ }
if (is_selection_active()) {
if (k->get_shift()) {
@@ -2904,23 +2972,26 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int left = _find_first_non_whitespace_column_of_line(line);
cc = MIN(cc, left);
- while (cc < indent_size && cc < left && line[cc] == ' ')
+ while (cc < indent_size && cc < left && line[cc] == ' ') {
cc++;
+ }
if (cc > 0 && cc <= text[cursor.line].length()) {
if (text[cursor.line][cc - 1] == '\t') {
// Tabs unindentation.
_remove_text(cursor.line, cc - 1, cursor.line, cc);
- if (cursor.column >= left)
+ if (cursor.column >= left) {
cursor_set_column(MAX(0, cursor.column - 1));
+ }
update();
} else {
// Spaces unindentation.
int spaces_to_remove = _calculate_spaces_till_next_left_indent(cc);
if (spaces_to_remove > 0) {
_remove_text(cursor.line, cc - spaces_to_remove, cursor.line, cc);
- if (cursor.column > left - spaces_to_remove) // Inside text?
+ if (cursor.column > left - spaces_to_remove) { // Inside text?
cursor_set_column(MAX(0, cursor.column - spaces_to_remove));
+ }
update();
}
}
@@ -2934,8 +3005,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Insert only as much spaces as needed till next indentation level.
int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor.column);
String indent_to_insert = String();
- for (int i = 0; i < spaces_to_add; i++)
+ for (int i = 0; i < spaces_to_add; i++) {
indent_to_insert = ' ' + indent_to_insert;
+ }
_insert_text_at_cursor(indent_to_insert);
} else {
_insert_text_at_cursor("\t");
@@ -2945,8 +3017,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_BACKSPACE: {
- if (readonly)
+ if (readonly) {
break;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt() && cursor.column > 1) {
@@ -3001,8 +3074,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_remove_text(cursor.line, 0, cursor.line, cursor_current_column);
#endif
} else {
- if (cursor.line > 0 && is_line_hidden(cursor.line - 1))
+ if (cursor.line > 0 && is_line_hidden(cursor.line - 1)) {
unfold_line(cursor.line - 1);
+ }
backspace_at_cursor();
}
@@ -3015,14 +3089,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_LEFT: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3059,8 +3134,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc > 0) {
bool ischar = _is_text_char(text[cursor.line][cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -3077,8 +3153,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() - 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_6: {
@@ -3089,14 +3166,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_RIGHT: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3119,8 +3197,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc < text[cursor.line].length()) {
bool ischar = _is_text_char(text[cursor.line][cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -3136,8 +3215,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() + 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_8: {
@@ -3186,8 +3266,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
@@ -3233,14 +3314,16 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
case KEY_DELETE: {
- if (readonly)
+ if (readonly) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt() && is_shortcut_keys_enabled()) {
cut();
@@ -3249,8 +3332,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int curline_len = text[cursor.line].length();
- if (cursor.line == text.size() - 1 && cursor.column == curline_len)
+ if (cursor.line == text.size() - 1 && cursor.column == curline_len) {
break; // Nothing to do.
+ }
int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
int next_column;
@@ -3331,8 +3415,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
if (k->get_command()) {
cursor_set_line(0);
@@ -3350,24 +3435,27 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int current_line_whitespace_len = 0;
while (current_line_whitespace_len < text[cursor.line].length()) {
CharType c = text[cursor.line][current_line_whitespace_len];
- if (c != '\t' && c != ' ')
+ if (c != '\t' && c != ' ') {
break;
+ }
current_line_whitespace_len++;
}
- if (cursor_get_column() == current_line_whitespace_len)
+ if (cursor_get_column() == current_line_whitespace_len) {
cursor_set_column(0);
- else
+ } else {
cursor_set_column(current_line_whitespace_len);
+ }
} else {
cursor_set_column(row_start_col);
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
#endif
@@ -3391,11 +3479,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
- if (k->get_command())
+ if (k->get_command()) {
cursor_set_line(get_last_unhidden_line(), true, false, 9999);
+ }
// Move cursor column to end of wrapped row and then to end of text.
Vector<String> rows = get_wrap_rows_text(cursor.line);
@@ -3410,10 +3500,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(row_end_col);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
@@ -3427,15 +3518,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEUP: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line - num_lines_from_rows(cursor.line, get_cursor_wrap_index(), -get_visible_rows(), wi) + 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
@@ -3449,15 +3542,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEDOWN: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line + num_lines_from_rows(cursor.line, get_cursor_wrap_index(), get_visible_rows(), wi) - 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
@@ -3559,10 +3654,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (is_shortcut_keys_enabled()) {
- if (k->get_shift())
+ if (k->get_shift()) {
redo();
- else
+ } else {
undo();
+ }
}
} break;
case KEY_Y: {
@@ -3623,8 +3719,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
}
- if (keycode_handled)
+ if (keycode_handled) {
accept_event();
+ }
if (k->get_keycode() == KEY_INSERT) {
set_insert_mode(!insert_mode);
@@ -3635,8 +3732,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (!keycode_handled && !k->get_command()) { // For German keyboards.
if (k->get_unicode() >= 32) {
- if (readonly)
+ if (readonly) {
return;
+ }
// Remove the old character if in insert mode and no selection.
if (insert_mode && !had_selection) {
@@ -3808,10 +3906,12 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
int lines = substrings.size() - 1;
for (; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line))
+ if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line)) {
emit_signal("breakpoint_toggled", i);
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ }
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i + lines);
+ }
}
}
@@ -3857,8 +3957,9 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
r_end_column = text[r_end_line].length() - postinsert_text.length();
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_line);
@@ -3878,8 +3979,9 @@ String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_lin
int begin = (i == p_from_line) ? p_from_column : 0;
int end = (i == p_to_line) ? p_to_column : text[i].length();
- if (i > p_from_line)
+ if (i > p_from_line) {
ret += "\n";
+ }
ret += text[i].substr(begin, end - begin);
}
@@ -3901,10 +4003,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
for (int i = p_from_line + 1; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i);
- if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines)))
+ }
+ if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines))) {
emit_signal("breakpoint_toggled", i - lines);
+ }
}
}
@@ -3916,16 +4020,18 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
text.set_line_wrap_amount(p_from_line, -1);
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_from_line);
}
void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
if (undo_enabled) {
_clear_redo();
@@ -3933,13 +4039,16 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
int retline, retchar;
_base_insert_text(p_line, p_char, p_text, retline, retchar);
- if (r_end_line)
+ if (r_end_line) {
*r_end_line = retline;
- if (r_end_char)
+ }
+ if (r_end_char) {
*r_end_char = retchar;
+ }
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO!! */
TextOperation op;
@@ -3977,8 +4086,9 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
}
void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
String text;
if (undo_enabled) {
@@ -3988,8 +4098,9 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, i
_base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO! */
TextOperation op;
@@ -4054,8 +4165,9 @@ int TextEdit::get_char_count() {
int totalsize = 0;
for (int i = 0; i < text.size(); i++) {
- if (i > 0)
+ if (i > 0) {
totalsize++; // Include \n.
+ }
totalsize += text[i].length();
}
@@ -4078,14 +4190,17 @@ int TextEdit::_get_control_height() const {
void TextEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (!readonly) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
@@ -4105,8 +4220,9 @@ int TextEdit::_get_minimap_visible_rows() const {
int TextEdit::get_total_visible_rows() const {
// Returns the total amount of rows we need in the editor.
// This skips hidden lines and counts each wrapping of a line.
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return text.size();
+ }
int total_rows = 0;
for (int i = 0; i < text.size(); i++) {
@@ -4125,8 +4241,9 @@ void TextEdit::_update_wrap_at() {
for (int i = 0; i < text.size(); i++) {
// Update all values that wrap.
- if (!line_wraps(i))
+ if (!line_wraps(i)) {
continue;
+ }
Vector<String> rows = get_wrap_rows_text(i);
text.set_line_wrap_amount(i, rows.size() - 1);
}
@@ -4154,19 +4271,22 @@ void TextEdit::adjust_viewport_to_cursor() {
}
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (!is_wrap_enabled()) {
// Adjust x offset.
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4180,24 +4300,28 @@ void TextEdit::center_viewport_to_cursor() {
scrolling = false;
minimap_clicked = false;
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
unfold_line(cursor.line);
+ }
set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (is_wrap_enabled()) {
// Center x offset.
int cursor_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4218,15 +4342,17 @@ void TextEdit::update_cursor_wrap_offset() {
bool TextEdit::line_wraps(int line) const {
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!is_wrap_enabled())
+ if (!is_wrap_enabled()) {
return false;
+ }
return text.get_line_width(line) > wrap_at;
}
int TextEdit::times_line_wraps(int line) const {
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!line_wraps(line))
+ if (!line_wraps(line)) {
return 0;
+ }
int wrap_amount = text.get_line_wrap_amount(line);
if (wrap_amount == -1) {
@@ -4318,8 +4444,9 @@ int TextEdit::get_cursor_wrap_index() const {
int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
- if (!line_wraps(p_line))
+ if (!line_wraps(p_line)) {
return 0;
+ }
// Loop through wraps in the line text until we get to the column.
int wrap_index = 0;
@@ -4329,42 +4456,50 @@ int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_column)
+ if (col > p_column) {
break;
+ }
}
return wrap_index;
}
void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
- if (p_col < 0)
+ if (p_col < 0) {
p_col = 0;
+ }
cursor.column = p_col;
- if (cursor.column > get_line(cursor.line).length())
+ if (cursor.column > get_line(cursor.line).length()) {
cursor.column = get_line(cursor.line).length();
+ }
cursor.last_fit_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
- if (setting_row)
+ if (setting_row) {
return;
+ }
setting_row = true;
- if (p_row < 0)
+ if (p_row < 0) {
p_row = 0;
+ }
- if (p_row >= text.size())
+ if (p_row >= text.size()) {
p_row = text.size() - 1;
+ }
if (!p_can_be_hidden) {
if (is_line_hidden(CLAMP(p_row, 0, text.size() - 1))) {
@@ -4390,19 +4525,22 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_
for (int i = 0; i < p_wrap_index + 1; i++) {
row_end_col += rows[i].length();
}
- if (n_col >= row_end_col)
+ if (n_col >= row_end_col) {
n_col -= 1;
+ }
}
cursor.column = n_col;
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
setting_row = false;
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
@@ -4465,11 +4603,13 @@ void TextEdit::_v_scroll_input() {
}
void TextEdit::_scroll_moved(double p_to_val) {
- if (updating_scrolls)
+ if (updating_scrolls) {
return;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
cursor.x_ofs = h_scroll->get_value();
+ }
if (v_scroll->is_visible_in_tree()) {
// Set line ofs and wrap ofs.
int v_scroll_i = floor(get_v_scroll());
@@ -4479,8 +4619,9 @@ void TextEdit::_scroll_moved(double p_to_val) {
if (!is_line_hidden(n_line)) {
sc++;
sc += times_line_wraps(n_line);
- if (sc > v_scroll_i)
+ if (sc > v_scroll_i) {
break;
+ }
}
}
n_line = MIN(n_line, text.size() - 1);
@@ -4507,12 +4648,14 @@ int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) cons
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (p_wrap_index > line_wrap_amount)
+ if (p_wrap_index > line_wrap_amount) {
p_wrap_index = line_wrap_amount;
- if (p_wrap_index > 0)
+ }
+ if (p_wrap_index > 0) {
p_px -= wrap_offset_px;
- else
+ } else {
p_wrap_index = 0;
+ }
Vector<String> rows = get_wrap_rows_text(p_line);
int c_pos = get_char_pos_for(p_px, rows[p_wrap_index]);
for (int i = 0; i < p_wrap_index; i++) {
@@ -4538,8 +4681,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_char)
+ if (col > p_char) {
break;
+ }
n_char -= s.length();
}
int px = get_column_x_offset(n_char, rows[wrap_index]);
@@ -4548,8 +4692,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (wrap_index != 0)
+ if (wrap_index != 0) {
px += wrap_offset_px;
+ }
return px;
} else {
@@ -4564,8 +4709,9 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const {
while (c < p_str.length()) {
int w = text.get_char_width(p_str[c], p_str[c + 1], px);
- if (p_px < (px + w / 2))
+ if (p_px < (px + w / 2)) {
break;
+ }
px += w;
c++;
}
@@ -4577,8 +4723,9 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) const {
int px = 0;
for (int i = 0; i < p_char; i++) {
- if (i >= p_str.length())
+ if (i >= p_str.length()) {
break;
+ }
px += text.get_char_width(p_str[i], p_str[i + 1], px);
}
@@ -4601,8 +4748,9 @@ void TextEdit::insert_text_at_cursor(const String &p_text) {
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
- if (highlighted_word != String())
+ if (highlighted_word != String()) {
return CURSOR_POINTING_HAND;
+ }
int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width;
if ((completion_active && completion_rect.has_point(p_pos))) {
@@ -4629,10 +4777,11 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
// Fold icon.
if (draw_fold_gutter && p_pos.x > gutter_left + cache.line_number_w - 6 && p_pos.x <= gutter_left + cache.line_number_w + cache.fold_gutter_width - 3) {
- if (is_folded(row) || can_fold(row))
+ if (is_folded(row) || can_fold(row)) {
return CURSOR_POINTING_HAND;
- else
+ } else {
return CURSOR_ARROW;
+ }
}
return CURSOR_ARROW;
@@ -4687,8 +4836,9 @@ String TextEdit::get_text() {
int len = text.size();
for (int i = 0; i < len; i++) {
longthing += text[i];
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
@@ -4709,8 +4859,9 @@ String TextEdit::get_text_for_lookup_completion() {
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
@@ -4728,16 +4879,18 @@ String TextEdit::get_text_for_completion() {
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
};
String TextEdit::get_line(int line) const {
- if (line < 0 || line >= text.size())
+ if (line < 0 || line >= text.size()) {
return "";
+ }
return text[line];
};
@@ -4761,8 +4914,9 @@ void TextEdit::clear() {
};
void TextEdit::set_readonly(bool p_readonly) {
- if (readonly == p_readonly)
+ if (readonly == p_readonly) {
return;
+ }
readonly = p_readonly;
_generate_context_menu();
@@ -5094,11 +5248,13 @@ void TextEdit::paste() {
}
void TextEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (text.size() == 1 && text[0].length() == 0)
+ if (text.size() == 1 && text[0].length() == 0) {
return;
+ }
selection.active = true;
selection.from_line = 0;
selection.from_column = 0;
@@ -5119,26 +5275,33 @@ void TextEdit::deselect() {
}
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (p_from_line < 0)
+ if (p_from_line < 0) {
p_from_line = 0;
- else if (p_from_line >= text.size())
+ } else if (p_from_line >= text.size()) {
p_from_line = text.size() - 1;
- if (p_from_column >= text[p_from_line].length())
+ }
+ if (p_from_column >= text[p_from_line].length()) {
p_from_column = text[p_from_line].length();
- if (p_from_column < 0)
+ }
+ if (p_from_column < 0) {
p_from_column = 0;
+ }
- if (p_to_line < 0)
+ if (p_to_line < 0) {
p_to_line = 0;
- else if (p_to_line >= text.size())
+ } else if (p_to_line >= text.size()) {
p_to_line = text.size() - 1;
- if (p_to_column >= text[p_to_line].length())
+ }
+ if (p_to_column >= text[p_to_line].length()) {
p_to_column = text[p_to_line].length();
- if (p_to_column < 0)
+ }
+ if (p_to_column < 0) {
p_to_column = 0;
+ }
selection.from_line = p_from_line;
selection.from_column = p_from_column;
@@ -5200,8 +5363,9 @@ int TextEdit::get_selection_to_column() const {
}
String TextEdit::get_selection_text() const {
- if (!selection.active)
+ if (!selection.active) {
return "";
+ }
return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
}
@@ -5210,20 +5374,23 @@ String TextEdit::get_word_under_cursor() const {
int prev_cc = cursor.column;
while (prev_cc > 0) {
bool is_char = _is_text_char(text[cursor.line][prev_cc - 1]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
--prev_cc;
}
int next_cc = cursor.column;
while (next_cc < text[cursor.line].length()) {
bool is_char = _is_text_char(text[cursor.line][next_cc]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
++next_cc;
}
- if (prev_cc == cursor.column || next_cc == cursor.column)
+ if (prev_cc == cursor.column || next_cc == cursor.column) {
return "";
+ }
return text[cursor.line].substr(prev_cc, next_cc - prev_cc);
}
@@ -5297,8 +5464,9 @@ Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags,
}
bool TextEdit::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 {
- if (p_key.length() == 0)
+ if (p_key.length() == 0) {
return false;
+ }
ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, false);
@@ -5332,10 +5500,11 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
} else {
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
from_column = text_line.length() - 1;
- else
+ } else {
from_column = 0;
+ }
}
pos = -1;
@@ -5369,10 +5538,11 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
// Validate for whole words.
- if (pos > 0 && _is_text_char(text_line[pos - 1]))
+ if (pos > 0 && _is_text_char(text_line[pos - 1])) {
is_match = false;
- else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()]))
+ } else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()])) {
is_match = false;
+ }
}
if (pos_from == -1) {
@@ -5387,13 +5557,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
pos = -1;
}
- if (pos != -1)
+ if (pos != -1) {
break;
+ }
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
line--;
- else
+ } else {
line++;
+ }
}
if (pos == -1) {
@@ -5459,16 +5631,18 @@ void TextEdit::set_line_as_bookmark(int p_line, bool p_bookmark) {
void TextEdit::get_bookmarks(List<int> *p_bookmarks) const {
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
p_bookmarks->push_back(i);
+ }
}
}
Array TextEdit::get_bookmarks_array() const {
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
arr.append(i);
+ }
}
return arr;
}
@@ -5486,25 +5660,28 @@ void TextEdit::set_line_as_breakpoint(int p_line, bool p_breakpoint) {
void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
p_breakpoints->push_back(i);
+ }
}
}
Array TextEdit::get_breakpoints_array() const {
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
arr.append(i);
+ }
}
return arr;
}
void TextEdit::remove_breakpoints() {
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
/* Should "breakpoint_toggled" be fired when breakpoints are removed this way? */
text.set_breakpoint(i, false);
+ }
}
}
@@ -5521,8 +5698,9 @@ void TextEdit::clear_info_icons() {
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
ERR_FAIL_INDEX(p_line, text.size());
- if (is_hiding_enabled() || !p_hidden)
+ if (is_hiding_enabled() || !p_hidden) {
text.set_hidden(p_line, p_hidden);
+ }
update();
}
@@ -5551,8 +5729,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
// Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5562,8 +5741,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
} else {
visible_amount = ABS(visible_amount);
@@ -5572,8 +5752,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
}
return num_total;
@@ -5585,8 +5766,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
wrap_index = 0;
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5602,8 +5784,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = times_line_wraps(MIN(i, text.size() - 1)) - (num_visible - visible_amount);
} else {
@@ -5616,8 +5799,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = (num_visible - visible_amount);
}
@@ -5627,8 +5811,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
int TextEdit::get_last_unhidden_line() const {
// Returns the last line in the text that is not hidden.
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return text.size() - 1;
+ }
int last_line;
for (last_line = text.size() - 1; last_line > 0; last_line--) {
@@ -5680,24 +5865,31 @@ bool TextEdit::is_line_comment(int p_line) const {
bool TextEdit::can_fold(int p_line) const {
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return false;
- if (p_line + 1 >= text.size())
+ }
+ if (p_line + 1 >= text.size()) {
return false;
- if (text[p_line].strip_edges().size() == 0)
+ }
+ if (text[p_line].strip_edges().size() == 0) {
return false;
- if (is_folded(p_line))
+ }
+ if (is_folded(p_line)) {
return false;
- if (is_line_hidden(p_line))
+ }
+ if (is_line_hidden(p_line)) {
return false;
- if (is_line_comment(p_line))
+ }
+ if (is_line_comment(p_line)) {
return false;
+ }
int start_indent = get_indent_level(p_line);
for (int i = p_line + 1; i < text.size(); i++) {
- if (text[i].strip_edges().size() == 0)
+ if (text[i].strip_edges().size() == 0) {
continue;
+ }
int next_indent = get_indent_level(i);
if (is_line_comment(i)) {
continue;
@@ -5713,8 +5905,9 @@ bool TextEdit::can_fold(int p_line) const {
bool TextEdit::is_folded(int p_line) const {
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (p_line + 1 >= text.size())
+ if (p_line + 1 >= text.size()) {
return false;
+ }
return !is_line_hidden(p_line) && is_line_hidden(p_line + 1);
}
@@ -5731,10 +5924,12 @@ Vector<int> TextEdit::get_folded_lines() const {
void TextEdit::fold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return;
- if (!can_fold(p_line))
+ }
+ if (!can_fold(p_line)) {
return;
+ }
// Hide lines below this one.
int start_indent = get_indent_level(p_line);
@@ -5777,12 +5972,14 @@ void TextEdit::fold_line(int p_line) {
void TextEdit::unfold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line) && !is_line_hidden(p_line))
+ if (!is_folded(p_line) && !is_line_hidden(p_line)) {
return;
+ }
int fold_start;
for (fold_start = p_line; fold_start > 0; fold_start--) {
- if (is_folded(fold_start))
+ if (is_folded(fold_start)) {
break;
+ }
}
fold_start = is_folded(fold_start) ? fold_start : p_line;
@@ -5800,10 +5997,11 @@ void TextEdit::unfold_line(int p_line) {
void TextEdit::toggle_fold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line))
+ if (!is_folded(p_line)) {
fold_line(p_line);
- else
+ } else {
unfold_line(p_line);
+ }
}
int TextEdit::get_line_count() const {
@@ -5814,8 +6012,9 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
bool insert = p_op.type == TextOperation::TYPE_INSERT;
- if (p_reverse)
+ if (p_reverse) {
insert = !insert;
+ }
if (insert) {
int check_line;
@@ -5829,8 +6028,9 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
}
void TextEdit::_clear_redo() {
- if (undo_stack_pos == nullptr)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to clear.
+ }
_push_current_op();
@@ -5845,22 +6045,25 @@ void TextEdit::undo() {
_push_current_op();
if (undo_stack_pos == nullptr) {
- if (!undo_stack.size())
+ if (!undo_stack.size()) {
return; // Nothing to undo.
+ }
undo_stack_pos = undo_stack.back();
- } else if (undo_stack_pos == undo_stack.front())
+ } else if (undo_stack_pos == undo_stack.front()) {
return; // At the bottom of the undo stack.
- else
+ } else {
undo_stack_pos = undo_stack_pos->prev();
+ }
deselect();
TextOperation op = undo_stack_pos->get();
_do_text_op(op, true);
- if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1))
+ if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1)) {
select(op.from_line, op.from_column, op.to_line, op.to_column);
+ }
current_op.version = op.prev_version;
if (undo_stack_pos->get().chain_backward) {
@@ -5891,8 +6094,9 @@ void TextEdit::undo() {
void TextEdit::redo() {
_push_current_op();
- if (undo_stack_pos == nullptr)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to do.
+ }
deselect();
@@ -5906,8 +6110,9 @@ void TextEdit::redo() {
op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
- if (undo_stack_pos->get().chain_backward)
+ if (undo_stack_pos->get().chain_backward) {
break;
+ }
}
}
@@ -5943,8 +6148,9 @@ void TextEdit::end_complex_operation() {
}
void TextEdit::_push_current_op() {
- if (current_op.type == TextOperation::TYPE_NONE)
+ if (current_op.type == TextOperation::TYPE_NONE) {
return; // Nothing to do.
+ }
if (next_operation_is_complex) {
current_op.chain_forward = true;
@@ -6037,8 +6243,9 @@ void TextEdit::tag_saved_version() {
}
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
- if (!is_wrap_enabled() && !is_hiding_enabled())
+ if (!is_wrap_enabled() && !is_hiding_enabled()) {
return p_line;
+ }
// Count the number of visible lines up to this line.
double new_line_scroll_pos = 0;
@@ -6112,8 +6319,9 @@ double TextEdit::get_v_scroll() const {
void TextEdit::set_v_scroll(double p_scroll) {
v_scroll->set_value(p_scroll);
int max_v_scroll = v_scroll->get_max() - v_scroll->get_page();
- if (p_scroll >= max_v_scroll - 1.0)
+ if (p_scroll >= max_v_scroll - 1.0) {
_scroll_moved(v_scroll->get_value());
+ }
}
int TextEdit::get_h_scroll() const {
@@ -6147,8 +6355,9 @@ float TextEdit::get_v_scroll_speed() const {
void TextEdit::set_completion(bool p_enabled, const Vector<String> &p_prefixes) {
completion_prefixes.clear();
completion_enabled = p_enabled;
- for (int i = 0; i < p_prefixes.size(); i++)
+ for (int i = 0; i < p_prefixes.size(); i++) {
completion_prefixes.insert(p_prefixes[i]);
+ }
}
void TextEdit::_confirm_completion() {
@@ -6197,8 +6406,9 @@ void TextEdit::_cancel_code_hint() {
}
void TextEdit::_cancel_completion() {
- if (!completion_active)
+ if (!completion_active) {
return;
+ }
completion_active = false;
completion_forced = false;
@@ -6225,8 +6435,9 @@ void TextEdit::_update_completion_candidates() {
while (c >= 0) {
if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
- if (first_quote == -1)
+ if (first_quote == -1) {
first_quote = c;
+ }
restore_quotes = 0;
} else if (restore_quotes == 0 && l[c] == '$') {
restore_quotes = 1;
@@ -6247,8 +6458,9 @@ void TextEdit::_update_completion_candidates() {
} else if (cofs > 0 && l[cofs - 1] == ' ') {
int kofs = cofs - 1;
String kw;
- while (kofs >= 0 && l[kofs] == ' ')
+ while (kofs >= 0 && l[kofs] == ' ') {
kofs--;
+ }
while (kofs >= 0 && l[kofs] > 32 && _is_completable(l[kofs])) {
kw = String::chr(l[kofs]) + kw;
@@ -6260,8 +6472,9 @@ void TextEdit::_update_completion_candidates() {
} else {
while (cofs > 0 && l[cofs - 1] > 32 && (l[cofs - 1] == '/' || _is_completable(l[cofs - 1]))) {
s = String::chr(l[cofs - 1]) + s;
- if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$')
+ if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$') {
break;
+ }
cofs--;
}
@@ -6274,11 +6487,13 @@ void TextEdit::_update_completion_candidates() {
update();
bool prev_is_prefix = false;
- if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1])))
+ if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1]))) {
prev_is_prefix = true;
+ }
// Check with one space before prefix, to allow indent.
- if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2])))
+ if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2]))) {
prev_is_prefix = true;
+ }
if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !prev_is_prefix))) {
// None to complete, cancel.
@@ -6396,8 +6611,9 @@ void TextEdit::query_code_comple() {
int c = ofs - 1;
while (c >= 0) {
- if (l[c] == '"' || l[c] == '\'')
+ if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
+ }
c--;
}
@@ -6420,10 +6636,11 @@ void TextEdit::query_code_comple() {
}
if (!ignored) {
- if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1]))))
+ if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1])))) {
emit_signal("request_completion");
- else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) // Make it work with a space too, it's good enough.
+ } else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) { // Make it work with a space too, it's good enough.
emit_signal("request_completion");
+ }
}
}
@@ -6447,8 +6664,9 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return "";
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
bool inside_quotes = false;
@@ -6480,14 +6698,16 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
}
String TextEdit::get_tooltip(const Point2 &p_pos) const {
- if (!tooltip_obj)
+ if (!tooltip_obj) {
return Control::get_tooltip(p_pos);
+ }
int row, col;
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return Control::get_tooltip(p_pos);
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
@@ -6505,8 +6725,9 @@ void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_funct
}
void TextEdit::set_line(int line, String new_text) {
- if (line < 0 || line > text.size())
+ if (line < 0 || line > text.size()) {
return;
+ }
_remove_text(line, 0, line, text[line].length());
_insert_text(line, 0, new_text);
if (cursor.line == line) {
@@ -6646,8 +6867,9 @@ int TextEdit::get_minimap_width() const {
}
void TextEdit::set_hiding_enabled(bool p_enabled) {
- if (!p_enabled)
+ if (!p_enabled) {
unhide_all_lines();
+ }
hiding_enabled = p_enabled;
update();
}
@@ -6731,8 +6953,9 @@ void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
void TextEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -7185,8 +7408,9 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
if (in_region == -1 && !in_keyword && is_char && !prev_is_char) {
int to = j;
- while (to < str.length() && _is_text_char(str[to]))
+ while (to < str.length() && _is_text_char(str[to])) {
to++;
+ }
uint32_t hash = String::hash(&str[j], to - j);
StrRange range(&str[j], to - j);
@@ -7246,18 +7470,19 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
in_member_variable = false;
}
- if (in_region >= 0)
+ if (in_region >= 0) {
color = color_regions[in_region].color;
- else if (in_keyword)
+ } else if (in_keyword) {
color = keyword_color;
- else if (in_member_variable)
+ } else if (in_member_variable) {
color = cache.member_variable_color;
- else if (in_function_name)
+ } else if (in_function_name) {
color = cache.function_color;
- else if (is_symbol)
+ } else if (is_symbol) {
color = cache.symbol_color;
- else if (is_number)
+ } else if (is_number) {
color = cache.number_color;
+ }
prev_is_char = is_char;
prev_is_number = is_number;
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 0cc0e50a00..6e86f0f299 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -38,18 +38,22 @@ Size2 TextureButton::get_minimum_size() const {
if (!expand) {
if (normal.is_null()) {
if (pressed.is_null()) {
- if (hover.is_null())
- if (click_mask.is_null())
+ if (hover.is_null()) {
+ if (click_mask.is_null()) {
rscale = Size2();
- else
+ } else {
rscale = click_mask->get_size();
- else
+ }
+ } else {
rscale = hover->get_size();
- } else
+ }
+ } else {
rscale = pressed->get_size();
+ }
- } else
+ } else {
rscale = normal->get_size();
+ }
}
return rscale.abs();
@@ -121,36 +125,44 @@ void TextureButton::_notification(int p_what) {
switch (draw_mode) {
case DRAW_NORMAL: {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
+ }
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
if (pressed.is_null()) {
if (hover.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
- } else
+ } else {
texdraw = pressed;
+ }
} break;
case DRAW_HOVER: {
if (hover.is_null()) {
- if (pressed.is_valid() && is_pressed())
+ if (pressed.is_valid() && is_pressed()) {
texdraw = pressed;
- else if (normal.is_valid())
+ } else if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
} break;
case DRAW_DISABLED: {
if (disabled.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = disabled;
+ }
} break;
}
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index 5edb10958c..484b14d11c 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -77,14 +77,15 @@ bool TextureProgress::get_nine_patch_stretch() const {
}
Size2 TextureProgress::get_minimum_size() const {
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]);
- else if (under.is_valid())
+ } else if (under.is_valid()) {
return under->get_size();
- else if (over.is_valid())
+ } else if (over.is_valid()) {
return over->get_size();
- else if (progress.is_valid())
+ } else if (progress.is_valid()) {
return progress->get_size();
+ }
return Size2(1, 1);
}
@@ -127,13 +128,16 @@ Color TextureProgress::get_tint_over() const {
}
Point2 TextureProgress::unit_val_to_uv(float val) {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
- if (val < 0)
+ if (val < 0) {
val += 1;
- if (val > 1)
+ }
+ if (val > 1) {
val -= 1;
+ }
Point2 p = get_relative_center();
@@ -151,40 +155,46 @@ Point2 TextureProgress::unit_val_to_uv(float val) {
for (int edge = 0; edge < 4; edge++) {
if (edge == 0) {
- if (dir.x > 0)
+ if (dir.x > 0) {
continue;
+ }
cq = -(edgeLeft - p.x);
dir.x *= 2.0 * cq;
cp = -dir.x;
} else if (edge == 1) {
- if (dir.x < 0)
+ if (dir.x < 0) {
continue;
+ }
cq = (edgeRight - p.x);
dir.x *= 2.0 * cq;
cp = dir.x;
} else if (edge == 2) {
- if (dir.y > 0)
+ if (dir.y > 0) {
continue;
+ }
cq = -(edgeBottom - p.y);
dir.y *= 2.0 * cq;
cp = -dir.y;
} else if (edge == 3) {
- if (dir.y < 0)
+ if (dir.y < 0) {
continue;
+ }
cq = (edgeTop - p.y);
dir.y *= 2.0 * cq;
cp = dir.y;
}
cr = cq / cp;
- if (cr >= 0 && cr < t1)
+ if (cr >= 0 && cr < t1) {
t1 = cr;
+ }
}
return (p + t1 * dir);
}
Point2 TextureProgress::get_relative_center() {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
Point2 p = progress->get_size() / 2;
p += rad_center_off;
p.x /= progress->get_width();
@@ -311,8 +321,9 @@ void TextureProgress::_notification(int p_what) {
draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over);
}
} else {
- if (under.is_valid())
+ if (under.is_valid()) {
draw_texture(under, Point2(), tint_under);
+ }
if (progress.is_valid()) {
Size2 s = progress->get_size();
switch (mode) {
@@ -335,8 +346,9 @@ void TextureProgress::_notification(int p_what) {
case FILL_CLOCKWISE:
case FILL_COUNTER_CLOCKWISE:
case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: {
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
s = get_size();
+ }
float val = get_as_ratio() * rad_max_degrees / 360;
if (val == 1) {
@@ -358,9 +370,11 @@ void TextureProgress::_notification(int p_what) {
pts.append(end);
float from = MIN(start, end);
float to = MAX(start, end);
- for (int i = 0; i < 12; i++)
- if (corners[i] > from && corners[i] < to)
+ for (int i = 0; i < 12; i++) {
+ if (corners[i] > from && corners[i] < to) {
pts.append(corners[i]);
+ }
+ }
pts.sort();
Vector<Point2> uvs;
Vector<Point2> points;
@@ -368,8 +382,9 @@ void TextureProgress::_notification(int p_what) {
points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
for (int i = 0; i < pts.size(); i++) {
Point2 uv = unit_val_to_uv(pts[i]);
- if (uvs.find(uv) >= 0)
+ if (uvs.find(uv) >= 0) {
continue;
+ }
uvs.push_back(uv);
points.push_back(Point2(uv.x * s.x, uv.y * s.y));
}
@@ -380,10 +395,11 @@ void TextureProgress::_notification(int p_what) {
if (Engine::get_singleton()->is_editor_hint()) {
Point2 p;
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
p = get_size();
- else
+ } else {
p = progress->get_size();
+ }
p.x *= get_relative_center().x;
p.y *= get_relative_center().y;
@@ -404,10 +420,10 @@ void TextureProgress::_notification(int p_what) {
draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
}
}
- if (over.is_valid())
+ if (over.is_valid()) {
draw_texture(over, Point2(), tint_over);
+ }
}
-
} break;
}
}
@@ -423,10 +439,12 @@ int TextureProgress::get_fill_mode() {
}
void TextureProgress::set_radial_initial_angle(float p_angle) {
- while (p_angle > 360)
+ while (p_angle > 360) {
p_angle -= 360;
- while (p_angle < 0)
+ }
+ while (p_angle < 0) {
p_angle += 360;
+ }
rad_init_angle = p_angle;
update();
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index df4420ca8c..45fcb448f8 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -47,8 +47,9 @@
#include <limits.h>
void TreeItem::move_to_top() {
- if (!parent || parent->children == this)
+ if (!parent || parent->children == this) {
return; //already on top
+ }
TreeItem *prev = get_prev();
prev->next = next;
next = parent->children;
@@ -56,13 +57,15 @@ void TreeItem::move_to_top() {
}
void TreeItem::move_to_bottom() {
- if (!parent || !next)
+ if (!parent || !next) {
return;
+ }
TreeItem *prev = get_prev();
TreeItem *last = next;
- while (last->next)
+ while (last->next) {
last = last->next;
+ }
if (prev) {
prev->next = next;
@@ -74,17 +77,20 @@ void TreeItem::move_to_bottom() {
}
Size2 TreeItem::Cell::get_icon_size() const {
- if (icon.is_null())
+ if (icon.is_null()) {
return Size2();
- if (icon_region == Rect2i())
+ }
+ if (icon_region == Rect2i()) {
return icon->get_size();
- else
+ } else {
return icon_region.size;
+ }
}
void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Color &p_color) const {
- if (icon.is_null())
+ if (icon.is_null()) {
return;
+ }
Size2i dsize = (p_size == Size2()) ? icon->get_size() : p_size;
@@ -229,12 +235,15 @@ int TreeItem::get_icon_max_width(int p_column) const {
/* range works for mode number or mode combo */
void TreeItem::set_range(int p_column, double p_value) {
ERR_FAIL_INDEX(p_column, cells.size());
- if (cells[p_column].step > 0)
+ if (cells[p_column].step > 0) {
p_value = Math::stepify(p_value, cells[p_column].step);
- if (p_value < cells[p_column].min)
+ }
+ if (p_value < cells[p_column].min) {
p_value = cells[p_column].min;
- if (p_value > cells[p_column].max)
+ }
+ if (p_value > cells[p_column].max) {
p_value = cells[p_column].max;
+ }
cells.write[p_column].val = p_value;
_changed_notify(p_column);
@@ -286,8 +295,9 @@ void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName
}
void TreeItem::set_collapsed(bool p_collapsed) {
- if (collapsed == p_collapsed || !tree)
+ if (collapsed == p_collapsed || !tree) {
return;
+ }
collapsed = p_collapsed;
TreeItem *ci = tree->selected_item;
if (ci) {
@@ -329,12 +339,14 @@ TreeItem *TreeItem::get_next() {
}
TreeItem *TreeItem::get_prev() {
- if (!parent || parent->children == this)
+ if (!parent || parent->children == this) {
return nullptr;
+ }
TreeItem *prev = parent->children;
- while (prev && prev->next != this)
+ while (prev && prev->next != this) {
prev = prev->next;
+ }
return prev;
}
@@ -374,8 +386,9 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
//go to the very end
current = current->children;
- while (current->next)
+ while (current->next) {
current = current->next;
+ }
}
}
@@ -396,10 +409,11 @@ TreeItem *TreeItem::get_next_visible(bool p_wrap) {
}
if (!current) {
- if (p_wrap)
+ if (p_wrap) {
return tree->root;
- else
+ } else {
return nullptr;
+ }
} else {
current = current->next;
}
@@ -445,10 +459,12 @@ bool TreeItem::is_selected(int p_column) {
void TreeItem::set_as_cursor(int p_column) {
ERR_FAIL_INDEX(p_column, cells.size());
- if (!tree)
+ if (!tree) {
return;
- if (tree->select_mode != Tree::SELECT_MULTI)
+ }
+ if (tree->select_mode != Tree::SELECT_MULTI) {
return;
+ }
tree->selected_item = this;
tree->selected_col = p_column;
tree->update();
@@ -469,8 +485,9 @@ void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id
ERR_FAIL_COND(!p_button.is_valid());
TreeItem::Cell::Button button;
button.texture = p_button;
- if (p_id < 0)
+ if (p_id < 0) {
p_id = cells[p_column].buttons.size();
+ }
button.id = p_id;
button.disabled = p_disabled;
button.tooltip = p_tooltip;
@@ -511,8 +528,9 @@ void TreeItem::erase_button(int p_column, int p_idx) {
int TreeItem::get_button_by_id(int p_column, int p_id) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
for (int i = 0; i < cells[p_column].buttons.size(); i++) {
- if (cells[p_column].buttons[i].id == p_id)
+ if (cells[p_column].buttons[i].id == p_id) {
return i;
+ }
}
return -1;
@@ -568,8 +586,9 @@ void TreeItem::set_custom_color(int p_column, const Color &p_color) {
Color TreeItem::get_custom_color(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_color)
+ if (!cells[p_column].custom_color) {
return Color();
+ }
return cells[p_column].color;
}
@@ -607,8 +626,9 @@ void TreeItem::clear_custom_bg_color(int p_column) {
Color TreeItem::get_custom_bg_color(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_bg_color)
+ if (!cells[p_column].custom_bg_color) {
return Color();
+ }
return cells[p_column].bg_color;
}
@@ -832,8 +852,9 @@ TreeItem::TreeItem(Tree *p_tree) {
TreeItem::~TreeItem() {
clear_children();
- if (parent)
+ if (parent) {
parent->remove_child(this);
+ }
if (tree && tree->root == this) {
tree->root = nullptr;
@@ -848,14 +869,17 @@ TreeItem::~TreeItem() {
tree->cache.hover_item = nullptr;
}
- if (tree && tree->selected_item == this)
+ if (tree && tree->selected_item == this) {
tree->selected_item = nullptr;
+ }
- if (tree && tree->drop_mode_over == this)
+ if (tree && tree->drop_mode_over == this) {
tree->drop_mode_over = nullptr;
+ }
- if (tree && tree->single_select_defer == this)
+ if (tree && tree->single_select_defer == this) {
tree->single_select_defer = nullptr;
+ }
if (tree && tree->edited_item == this) {
tree->edited_item = nullptr;
@@ -915,8 +939,9 @@ void Tree::update_cache() {
}
int Tree::compute_item_height(TreeItem *p_item) const {
- if (p_item == root && hide_root)
+ if (p_item == root && hide_root) {
return 0;
+ }
ERR_FAIL_COND_V(cache.font.is_null(), 0);
int height = cache.font->get_height();
@@ -925,15 +950,17 @@ int Tree::compute_item_height(TreeItem *p_item) const {
for (int j = 0; j < p_item->cells[i].buttons.size(); j++) {
Size2i s; // = cache.button_pressed->get_minimum_size();
s += p_item->cells[i].buttons[j].texture->get_size();
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
switch (p_item->cells[i].mode) {
case TreeItem::CELL_MODE_CHECK: {
int check_icon_h = cache.checked->get_height();
- if (height < check_icon_h)
+ if (height < check_icon_h) {
height = check_icon_h;
+ }
[[fallthrough]];
}
case TreeItem::CELL_MODE_STRING:
@@ -945,8 +972,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
if (p_item->cells[i].icon_max_w > 0 && s.width > p_item->cells[i].icon_max_w) {
s.height = s.height * p_item->cells[i].icon_max_w / s.width;
}
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
height += cache.custom_button->get_minimum_size().height;
@@ -958,8 +986,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
}
}
int item_min_height = p_item->get_custom_minimum_height();
- if (height < item_min_height)
+ if (height < item_min_height) {
height = item_min_height;
+ }
height += cache.vseparation;
@@ -990,8 +1019,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
Rect2i rect = p_rect;
Ref<Font> font = cache.font;
String text = p_cell.text;
- if (p_cell.suffix != String())
+ if (p_cell.suffix != String()) {
text += " " + p_cell.suffix;
+ }
int w = 0;
if (!p_cell.icon.is_null()) {
@@ -1034,8 +1064,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
}
int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) {
- if (p_pos.y - cache.offset.y > (p_draw_size.height))
+ if (p_pos.y - cache.offset.y > (p_draw_size.height)) {
return -1; //draw no more!
+ }
RID ci = get_canvas_item();
@@ -1094,8 +1125,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = p_item->cells[i].buttons[j].texture;
Size2 s = b->get_size() + cache.button_pressed->get_minimum_size();
- if (s.height < label_h)
+ if (s.height < label_h) {
s.height = label_h;
+ }
Point2i o = Point2i(ofs + w - s.width, p_pos.y) - cache.offset + p_draw_ofs;
@@ -1128,10 +1160,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y));
//Rect2 r = Rect2i(row_rect.pos,row_rect.size);
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
- if (has_focus())
+ if (has_focus()) {
cache.selected_focus->draw(ci, row_rect);
- else
+ } else {
cache.selected->draw(ci, row_rect);
+ }
}
}
@@ -1224,8 +1257,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_RANGE: {
if (p_item->cells[i].text != "") {
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
int option = (int)p_item->cells[i].val;
@@ -1242,8 +1276,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
s += " " + p_item->cells[i].suffix;
+ }
Ref<Texture2D> downarrow = cache.select_arrow;
@@ -1259,13 +1294,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step));
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
valtext += " " + p_item->cells[i].suffix;
+ }
font->draw(ci, text_pos, valtext, col, item_rect.size.x - updown->get_width());
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
Point2i updown_pos = item_rect.position;
updown_pos.x += item_rect.size.x - updown->get_width();
@@ -1276,8 +1313,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_ICON: {
- if (p_item->cells[i].icon.is_null())
+ if (p_item->cells[i].icon.is_null()) {
break;
+ }
Size2i icon_size = p_item->cells[i].get_icon_size();
if (p_item->cells[i].icon_max_w > 0 && icon_size.width > p_item->cells[i].icon_max_w) {
icon_size.height = icon_size.height * p_item->cells[i].icon_max_w / icon_size.width;
@@ -1293,8 +1331,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
case TreeItem::CELL_MODE_CUSTOM: {
if (p_item->cells[i].custom_draw_obj.is_valid()) {
Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj);
- if (cdo)
+ if (cdo) {
cdo->call(p_item->cells[i].custom_draw_callback, p_item, Rect2(item_rect));
+ }
}
if (!p_item->cells[i].editable) {
@@ -1340,10 +1379,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (select_mode == SELECT_MULTI && selected_item == p_item && selected_col == i) {
- if (has_focus())
+ if (has_focus()) {
cache.cursor->draw(ci, cell_rect);
- else
+ } else {
cache.cursor_unfocus->draw(ci, cell_rect);
+ }
}
}
@@ -1381,8 +1421,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs;
- if (c->get_children() != nullptr)
+ if (c->get_children() != nullptr) {
root_pos -= Point2i(cache.arrow->get_width(), 0);
+ }
float line_width = 1.0;
#ifdef TOOLS_ENABLED
@@ -1428,8 +1469,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int Tree::_count_selected_items(TreeItem *p_from) const {
int count = 0;
for (int i = 0; i < columns.size(); i++) {
- if (p_from->is_selected(i))
+ if (p_from->is_selected(i)) {
count++;
+ }
}
if (p_from->get_children()) {
@@ -1457,8 +1499,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
for (int i = 0; i < columns.size(); i++) {
TreeItem::Cell &c = p_current->cells.write[i];
- if (!c.selectable)
+ if (!c.selectable) {
continue;
+ }
if (select_mode == SELECT_ROW) {
if (p_selected == p_current && (!c.selected || allow_reselect)) {
@@ -1487,10 +1530,11 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
selected_col = i;
emit_signal("cell_selected");
- if (select_mode == SELECT_MULTI)
+ if (select_mode == SELECT_MULTI) {
emit_signal("multi_selected", p_current, i, true);
- else if (select_mode == SELECT_SINGLE)
+ } else if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected");
+ }
} else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) {
selected_item = p_selected;
@@ -1505,8 +1549,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
}
} else if (!r_in_range || p_force_deselect) {
- if (select_mode == SELECT_MULTI && c.selected)
+ if (select_mode == SELECT_MULTI && c.selected) {
emit_signal("multi_selected", p_current, i, false);
+ }
c.selected = false;
}
//p_current->deselected_signal.call(p_col);
@@ -1558,8 +1603,9 @@ void Tree::_range_click_timeout() {
range_click_timer->start();
}
- if (!click_handled)
+ if (!click_handled) {
range_click_timer->stop();
+ }
if (propagate_mouse_activated) {
emit_signal("item_activated");
@@ -1584,8 +1630,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) {
- if (p_item->children)
+ if (p_item->children) {
p_item->set_collapsed(!p_item->is_collapsed());
+ }
return -1; //handled!
}
@@ -1617,9 +1664,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
break;
}
- if (col == -1)
+ if (col == -1) {
return -1;
- else if (col == 0) {
+ } else if (col == 0) {
int margin = x_ofs + cache.item_margin; //-cache.hseparation;
//int lm = cache.bg->get_margin(MARGIN_LEFT);
col_width -= margin;
@@ -1726,8 +1773,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
}
- if (!c.editable)
+ if (!c.editable) {
return -1; // if cell is not editable, don't bother
+ }
/* editing */
@@ -1813,8 +1861,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} else {
editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step));
- if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id)
+ if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) {
bring_up_editor = false;
+ }
}
}
click_handled = true;
@@ -1842,8 +1891,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} break;
};
- if (!bring_up_editor || p_button != BUTTON_LEFT)
+ if (!bring_up_editor || p_button != BUTTON_LEFT) {
return -1;
+ }
click_handled = true;
popup_edited_item = p_item;
@@ -1871,8 +1921,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
while (c) {
int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, p_doubleclick, c, p_button, p_mod);
- if (child_h < 0)
+ if (child_h < 0) {
return -1; // break, stop propagating, no need to anymore
+ }
new_pos.y -= child_h;
y_ofs += child_h;
@@ -1895,8 +1946,9 @@ void Tree::_text_editor_modal_close() {
return;
}
- if (value_editor->has_point(value_editor->get_local_mouse_position()))
+ if (value_editor->has_point(value_editor->get_local_mouse_position())) {
return;
+ }
_text_editor_enter(text_editor->get_text());
}
@@ -1904,11 +1956,13 @@ void Tree::_text_editor_modal_close() {
void Tree::_text_editor_enter(String p_text) {
popup_editor->hide();
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
TreeItem::Cell &c = popup_edited_item->cells.write[popup_edited_item_col];
switch (c.mode) {
@@ -1918,12 +1972,14 @@ void Tree::_text_editor_enter(String p_text) {
} break;
case TreeItem::CELL_MODE_RANGE: {
c.val = p_text.to_double();
- if (c.step > 0)
+ if (c.step > 0) {
c.val = Math::stepify(c.val, c.step);
- if (c.val < c.min)
+ }
+ if (c.val < c.min) {
c.val = c.min;
- else if (c.val > c.max)
+ } else if (c.val > c.max) {
c.val = c.max;
+ }
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break;
@@ -1951,11 +2007,13 @@ void Tree::value_editor_changed(double p_value) {
}
void Tree::popup_select(int p_option) {
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
popup_edited_item->cells.write[popup_edited_item_col].val = p_option;
//popup_edited_item->edited_signal.call( popup_edited_item_col );
@@ -2031,17 +2089,20 @@ void Tree::_go_up() {
}
if (select_mode == SELECT_MULTI) {
- if (!prev)
+ if (!prev) {
return;
+ }
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
int col = selected_col < 0 ? 0 : selected_col;
- while (prev && !prev->cells[col].selectable)
+ while (prev && !prev->cells[col].selectable) {
prev = prev->get_prev_visible();
- if (!prev)
+ }
+ if (!prev) {
return; // do nothing..
+ }
prev->select(col);
}
@@ -2080,8 +2141,9 @@ void Tree::_go_down() {
} else {
int col = selected_col < 0 ? 0 : selected_col;
- while (next && !next->cells[col].selectable)
+ while (next && !next->cells[col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2097,8 +2159,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
bool is_command = k.is_valid() && k->get_command();
if (p_event->is_action("ui_right") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) {
return;
@@ -2114,8 +2177,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
_go_right();
}
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col < 0) {
return;
@@ -2133,24 +2197,28 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
_go_up();
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
_go_down();
} else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
TreeItem *next = nullptr;
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
next = selected_item;
for (int i = 0; i < 10; i++) {
@@ -2161,16 +2229,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
break;
}
}
- if (next == selected_item)
+ if (next == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
selected_item = next;
emit_signal("cell_selected");
update();
} else {
- while (next && !next->cells[selected_col].selectable)
+ while (next && !next->cells[selected_col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2179,12 +2249,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
TreeItem *prev = nullptr;
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
prev = selected_item;
for (int i = 0; i < 10; i++) {
@@ -2195,16 +2267,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
break;
}
}
- if (prev == selected_item)
+ if (prev == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
- while (prev && !prev->cells[selected_col].selectable)
+ while (prev && !prev->cells[selected_col].selectable) {
prev = prev->get_prev_visible();
+ }
if (!prev) {
return; // do nothing..
}
@@ -2222,8 +2296,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
accept_event();
} else if (p_event->is_action("ui_select") && p_event->is_pressed()) {
if (select_mode == SELECT_MULTI) {
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
if (selected_item->is_selected(selected_col)) {
selected_item->deselect(selected_col);
emit_signal("multi_selected", selected_item, selected_col, false);
@@ -2237,15 +2312,19 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (k.is_valid()) { // Incremental search
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
- if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey())
+ }
+ if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) {
return;
- if (!root)
+ }
+ if (!root) {
return;
+ }
- if (hide_root && !root->get_next_visible())
+ if (hide_root && !root->get_next_visible()) {
return;
+ }
if (k->get_unicode() > 0) {
_do_incr_search(String::chr(k->get_unicode()));
@@ -2253,16 +2332,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
} else {
- if (k->get_keycode() != KEY_SHIFT)
+ if (k->get_keycode() != KEY_SHIFT) {
last_keypress = 0;
+ }
}
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
Ref<StyleBox> bg = cache.bg;
@@ -2295,10 +2376,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
mpos -= cache.bg->get_offset();
mpos.y -= _get_title_button_height();
if (mpos.y >= 0) {
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
mpos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
mpos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
@@ -2362,8 +2445,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
if (!b->is_pressed()) {
if (b->get_button_index() == BUTTON_LEFT) {
@@ -2434,8 +2518,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (range_drag_enabled)
+ if (range_drag_enabled) {
return;
+ }
switch (b->get_button_index()) {
case BUTTON_RIGHT:
@@ -2484,8 +2569,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pressing_pos = b->get_position();
}
- if (b->get_button_index() == BUTTON_RIGHT)
+ if (b->get_button_index() == BUTTON_RIGHT) {
break;
+ }
if (drag_touching) {
set_physics_process_internal(false);
@@ -2507,8 +2593,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_LEFT) {
- if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command())
+ if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) {
emit_signal("nothing_selected");
+ }
}
}
@@ -2558,8 +2645,9 @@ bool Tree::edit_selected() {
int col = get_selected_column();
ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected.");
- if (!s->cells[col].editable)
+ if (!s->cells[col].editable) {
return false;
+ }
Rect2 rect = s->get_meta("__focus_rect");
popup_edited_item = s;
@@ -2636,8 +2724,9 @@ bool Tree::edit_selected() {
Size2 Tree::get_internal_min_size() const {
Size2i size = cache.bg->get_offset();
- if (root)
+ if (root) {
size.height += get_item_height(root);
+ }
for (int i = 0; i < columns.size(); i++) {
size.width += columns[i].min_width;
}
@@ -2873,10 +2962,11 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
c = c->next;
}
- if (prev)
+ if (prev) {
prev->next = ti;
- else
+ } else {
p_parent->children = ti;
+ }
ti->parent = p_parent;
} else {
@@ -2904,12 +2994,13 @@ TreeItem *Tree::get_last_item() {
TreeItem *last = root;
while (last) {
- if (last->next)
+ if (last->next) {
last = last->next;
- else if (last->children)
+ } else if (last->children) {
last = last->children;
- else
+ } else {
break;
+ }
}
return last;
@@ -2918,10 +3009,11 @@ TreeItem *Tree::get_last_item() {
void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
edited_item = p_item;
edited_col = p_column;
- if (p_lmb)
+ if (p_lmb) {
emit_signal("item_edited");
- else
+ } else {
emit_signal("item_rmb_edited");
+ }
}
void Tree::item_changed(int p_column, TreeItem *p_item) {
@@ -2930,8 +3022,9 @@ void Tree::item_changed(int p_column, TreeItem *p_item) {
void Tree::item_selected(int p_column, TreeItem *p_item) {
if (select_mode == SELECT_MULTI) {
- if (!p_item->cells[p_column].selectable)
+ if (!p_item->cells[p_column].selectable) {
return;
+ }
p_item->cells.write[p_column].selected = true;
//emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select
@@ -3013,8 +3106,9 @@ bool Tree::is_root_hidden() const {
void Tree::set_column_min_width(int p_column, int p_min_width) {
ERR_FAIL_INDEX(p_column, columns.size());
- if (p_min_width < 1)
+ if (p_min_width < 1) {
return;
+ }
columns.write[p_column].min_width = p_min_width;
update();
}
@@ -3047,8 +3141,9 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
if (!p_item)
return nullptr;
*/
- if (!root)
+ if (!root) {
return nullptr;
+ }
while (true) {
if (!p_item) {
@@ -3062,17 +3157,20 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
} else {
while (!p_item->next) {
p_item = p_item->parent;
- if (p_item == nullptr)
+ if (p_item == nullptr) {
return nullptr;
+ }
}
p_item = p_item->next;
}
}
- for (int i = 0; i < columns.size(); i++)
- if (p_item->cells[i].selected)
+ for (int i = 0; i < columns.size(); i++) {
+ if (p_item->cells[i].selected) {
return p_item;
+ }
+ }
}
return nullptr;
@@ -3081,15 +3179,17 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
int Tree::get_column_width(int p_column) const {
ERR_FAIL_INDEX_V(p_column, columns.size(), -1);
- if (!columns[p_column].expand)
+ if (!columns[p_column].expand) {
return columns[p_column].min_width;
+ }
Ref<StyleBox> bg = cache.bg;
int expand_area = get_size().width - (bg->get_margin(MARGIN_LEFT) + bg->get_margin(MARGIN_RIGHT));
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
expand_area -= v_scroll->get_combined_minimum_size().width;
+ }
int expanding_columns = 0;
int expanding_total = 0;
@@ -3103,8 +3203,9 @@ int Tree::get_column_width(int p_column) const {
}
}
- if (expand_area < expanding_total)
+ if (expand_area < expanding_total) {
return columns[p_column].min_width;
+ }
ERR_FAIL_COND_V(expanding_columns == 0, -1); // shouldn't happen
@@ -3126,10 +3227,12 @@ void Tree::set_columns(int p_columns) {
ERR_FAIL_COND(blocked > 0);
columns.resize(p_columns);
- if (root)
+ if (root) {
propagate_set_columns(root);
- if (selected_col >= p_columns)
+ }
+ if (selected_col >= p_columns) {
selected_col = p_columns - 1;
+ }
update();
}
@@ -3148,12 +3251,14 @@ Rect2 Tree::get_custom_popup_rect() const {
int Tree::get_item_offset(TreeItem *p_item) const {
TreeItem *it = root;
int ofs = _get_title_button_height();
- if (!it)
+ if (!it) {
return 0;
+ }
while (true) {
- if (it == p_item)
+ if (it == p_item) {
return ofs;
+ }
ofs += compute_item_height(it);
if (it != root || !hide_root) {
@@ -3168,8 +3273,9 @@ int Tree::get_item_offset(TreeItem *p_item) const {
} else {
while (!it->next) {
it = it->parent;
- if (it == nullptr)
+ if (it == nullptr) {
return 0;
+ }
}
it = it->next;
@@ -3279,10 +3385,12 @@ String Tree::get_column_title(int p_column) const {
Point2 Tree::get_scroll() const {
Point2 ofs;
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
ofs.x = h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
ofs.y = v_scroll->get_value();
+ }
return ofs;
}
@@ -3309,19 +3417,22 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
while (p_at) {
for (int i = 0; i < columns.size(); i++) {
if (p_at->get_text(i).findn(p_find) == 0 && (!p_selectable || p_at->is_selectable(i))) {
- if (r_col)
+ if (r_col) {
*r_col = i;
+ }
return p_at;
}
}
- if (p_backwards)
+ if (p_backwards) {
p_at = p_at->get_prev_visible(true);
- else
+ } else {
p_at = p_at->get_next_visible(true);
+ }
- if ((p_at) == from)
+ if ((p_at) == from) {
break;
+ }
}
return nullptr;
@@ -3330,10 +3441,12 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) {
TreeItem *from = get_selected();
- if (!from)
+ if (!from) {
from = root;
- if (!from)
+ }
+ if (!from) {
return nullptr;
+ }
return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable);
}
@@ -3352,16 +3465,18 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const {
void Tree::_do_incr_search(const String &p_add) {
uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec
uint64_t diff = time - last_keypress;
- if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000)))
+ if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000))) {
incr_search = p_add;
- else if (incr_search != p_add)
+ } else if (incr_search != p_add) {
incr_search += p_add;
+ }
last_keypress = time;
int col;
TreeItem *item = search_item_text(incr_search, &col, true);
- if (!item)
+ if (!item) {
return;
+ }
item->select(col);
ensure_cursor_is_visible();
@@ -3403,8 +3518,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
h = 0;
}
- if (p_item->is_collapsed())
+ if (p_item->is_collapsed()) {
return nullptr; // do not try children, it's collapsed
+ }
TreeItem *n = p_item->get_children();
while (n) {
@@ -3412,8 +3528,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
TreeItem *r = _find_item_at_pos(n, pos, r_column, ch, section);
pos.y -= ch;
h += ch;
- if (r)
+ if (r) {
return r;
+ }
n = n->get_next();
}
@@ -3425,13 +3542,16 @@ int Tree::get_column_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -1;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3449,13 +3569,16 @@ int Tree::get_drop_section_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -100;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3473,13 +3596,16 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return nullptr;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3497,13 +3623,16 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return Control::get_tooltip(p_pos);
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3512,8 +3641,9 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
const TreeItem::Cell &c = it->cells[col];
int col_width = get_column_width(col);
- for (int i = 0; i < col; i++)
+ for (int i = 0; i < col; i++) {
pos.x -= get_column_width(i);
+ }
for (int j = c.buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = c.buttons[j].texture;
@@ -3527,10 +3657,11 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
col_width -= size.width;
}
String ret;
- if (it->get_tooltip(col) == "")
+ if (it->get_tooltip(col) == "") {
ret = it->get_text(col);
- else
+ } else {
ret = it->get_tooltip(col);
+ }
return ret;
}
}
@@ -3556,8 +3687,9 @@ bool Tree::is_folding_hidden() const {
}
void Tree::set_drop_mode_flags(int p_flags) {
- if (drop_mode_flags == p_flags)
+ if (drop_mode_flags == p_flags) {
return;
+ }
drop_mode_flags = p_flags;
if (drop_mode_flags == 0) {
drop_mode_over = nullptr;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index 52538203dd..881df06d8f 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -93,8 +93,9 @@ void VideoPlayer::_mix_audio() {
int buffer_size = mix_buffer.size();
// Resample
- if (!mix(buffer, buffer_size))
+ if (!mix(buffer, buffer_size)) {
return;
+ }
AudioFrame vol = AudioFrame(volume, volume);
@@ -144,16 +145,18 @@ void VideoPlayer::_notification(int p_notification) {
case NOTIFICATION_INTERNAL_PROCESS: {
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
- if (stream.is_null() || paused || playback.is_null() || !playback->is_playing())
+ if (stream.is_null() || paused || playback.is_null() || !playback->is_playing()) {
return;
+ }
double audio_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec());
double delta = last_audio_time == 0 ? 0 : audio_time - last_audio_time;
last_audio_time = audio_time;
- if (delta == 0)
+ if (delta == 0) {
return;
+ }
playback->update(delta); // playback->is_playing() returns false in the last video frame
@@ -164,10 +167,12 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_DRAW: {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
- if (texture->get_width() == 0)
+ }
+ if (texture->get_width() == 0) {
return;
+ }
Size2 s = expand ? get_size() : texture->get_size();
draw_texture_rect(texture, Rect2(Point2(), s), false);
@@ -177,10 +182,11 @@ void VideoPlayer::_notification(int p_notification) {
};
Size2 VideoPlayer::get_minimum_size() const {
- if (!expand && !texture.is_null())
+ if (!expand && !texture.is_null()) {
return texture->get_size();
- else
+ } else {
return Size2();
+ }
}
void VideoPlayer::set_expand(bool p_expand) {
@@ -215,14 +221,16 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
const int channels = playback->get_channels();
AudioServer::get_singleton()->lock();
- if (channels > 0)
+ if (channels > 0) {
resampler.setup(channels, playback->get_mix_rate(), AudioServer::get_singleton()->get_mix_rate(), buffering_ms, 0);
- else
+ } else {
resampler.clear();
+ }
AudioServer::get_singleton()->unlock();
- if (channels > 0)
+ if (channels > 0) {
playback->set_mix_callback(_audio_mix_callback, this);
+ }
} else {
texture.unref();
@@ -244,8 +252,9 @@ Ref<VideoStream> VideoPlayer::get_stream() const {
void VideoPlayer::play() {
ERR_FAIL_COND(!is_inside_tree());
- if (playback.is_null())
+ if (playback.is_null()) {
return;
+ }
playback->stop();
playback->play();
set_process_internal(true);
@@ -255,10 +264,12 @@ void VideoPlayer::play() {
};
void VideoPlayer::stop() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (playback.is_null())
+ }
+ if (playback.is_null()) {
return;
+ }
playback->stop();
// AudioServer::get_singleton()->stream_set_active(stream_rid,false);
@@ -268,8 +279,9 @@ void VideoPlayer::stop() {
};
bool VideoPlayer::is_playing() const {
- if (playback.is_null())
+ if (playback.is_null()) {
return false;
+ }
return playback->is_playing();
};
@@ -312,39 +324,45 @@ float VideoPlayer::get_volume() const {
};
void VideoPlayer::set_volume_db(float p_db) {
- if (p_db < -79)
+ if (p_db < -79) {
set_volume(0);
- else
+ } else {
set_volume(Math::db2linear(p_db));
+ }
};
float VideoPlayer::get_volume_db() const {
- if (volume == 0)
+ if (volume == 0) {
return -80;
- else
+ } else {
return Math::linear2db(volume);
+ }
};
String VideoPlayer::get_stream_name() const {
- if (stream.is_null())
+ if (stream.is_null()) {
return "<No Stream>";
+ }
return stream->get_name();
};
float VideoPlayer::get_stream_position() const {
- if (playback.is_null())
+ if (playback.is_null()) {
return 0;
+ }
return playback->get_playback_position();
};
void VideoPlayer::set_stream_position(float p_position) {
- if (playback.is_valid())
+ if (playback.is_valid()) {
playback->seek(p_position);
+ }
}
Ref<Texture2D> VideoPlayer::get_video_texture() const {
- if (playback.is_valid())
+ if (playback.is_valid()) {
return playback->get_texture();
+ }
return Ref<Texture2D>();
}
@@ -377,8 +395,9 @@ void VideoPlayer::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}