summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp2
-rw-r--r--scene/gui/control.cpp2
-rw-r--r--scene/gui/graph_edit.cpp2
-rw-r--r--scene/gui/item_list.cpp8
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/menu_button.cpp2
-rw-r--r--scene/gui/patch_9_rect.cpp1
-rw-r--r--scene/gui/popup_menu.cpp4
-rw-r--r--scene/gui/tabs.cpp2
-rw-r--r--scene/gui/text_edit.cpp127
-rw-r--r--scene/gui/tree.cpp9
11 files changed, 90 insertions, 73 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 9a5f55698e..4d55d8df75 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -508,7 +508,7 @@ void BaseButton::_bind_methods() {
ADD_SIGNAL(MethodInfo("toggled", PropertyInfo(Variant::BOOL, "pressed")));
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), "set_toggle_mode", "is_toggle_mode");
- ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "is_pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "action_mode", PROPERTY_HINT_ENUM, "Button Press,Button Release"), "set_action_mode", "get_action_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_enabled_focus_mode", "get_enabled_focus_mode");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_shortcut", "get_shortcut");
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index ee908428d9..ca81b72e89 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2536,7 +2536,7 @@ void Control::_bind_methods() {
ADD_GROUP("Size Flags", "size_flags_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_GROUP("", "");
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 1d37529a87..11f750ea70 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -601,7 +601,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
int cp_neg_len = get_constant("bezier_len_neg");
if (diff > 0) {
- cp_offset = MAX(cp_len, diff * 0.5);
+ cp_offset = MIN(cp_len, diff * 0.5);
} else {
cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 97f49da2be..34533375b2 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -431,7 +431,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) {
search_string = ""; //any mousepress cancels
- Vector2 pos(mb->get_position().x, mb->get_position().y);
+ Vector2 pos = mb->get_position();
Ref<StyleBox> bg = get_stylebox("bg");
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -475,7 +475,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
+ emit_signal("item_rmb_selected", i, pos);
}
} else {
@@ -486,7 +486,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
+ emit_signal("item_rmb_selected", i, pos);
} else {
bool selected = !items[i].selected;
@@ -501,7 +501,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
+ emit_signal("item_rmb_selected", i, pos);
} else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) {
emit_signal("item_activated", i);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index f4dd3e92cd..8556ce5db1 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -229,8 +229,8 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
bool handled = true;
switch (code) {
- case KEY_ENTER:
- case KEY_RETURN: {
+ case KEY_KP_ENTER:
+ case KEY_ENTER: {
emit_signal("text_entered", text);
if (OS::get_singleton()->has_virtual_keyboard())
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index fe76b16460..57aa72b7d0 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -55,7 +55,6 @@ void MenuButton::pressed() {
popup->set_size(Size2(size.width, 0));
popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size()));
popup->popup();
- popup->call_deferred("grab_click_focus");
popup->set_invalidate_click_until_motion();
}
@@ -112,6 +111,7 @@ MenuButton::MenuButton() {
popup->hide();
add_child(popup);
popup->set_as_toplevel(true);
+ connect("button_up", popup, "call_deferred", make_binds("grab_click_focus"));
set_process_unhandled_key_input(true);
set_action_mode(ACTION_MODE_BUTTON_PRESS);
}
diff --git a/scene/gui/patch_9_rect.cpp b/scene/gui/patch_9_rect.cpp
index 16f2bb6b6f..e577000f99 100644
--- a/scene/gui/patch_9_rect.cpp
+++ b/scene/gui/patch_9_rect.cpp
@@ -99,6 +99,7 @@ void NinePatchRect::set_texture(const Ref<Texture> &p_tex) {
*/
minimum_size_changed();
emit_signal("texture_changed");
+ _change_notify("texture");
}
Ref<Texture> NinePatchRect::get_texture() const {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index f59a2e06eb..b673f9d68a 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -249,8 +249,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} break;
- case KEY_RETURN:
- case KEY_ENTER: {
+ case KEY_ENTER:
+ case KEY_KP_ENTER: {
if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index c477a3156f..24eb19fbc2 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -793,7 +793,7 @@ void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &Tabs::set_tab_disabled);
ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &Tabs::get_tab_disabled);
ClassDB::bind_method(D_METHOD("remove_tab", "tab_idx"), &Tabs::remove_tab);
- ClassDB::bind_method(D_METHOD("add_tab", "title", "icon:Texture"), &Tabs::add_tab);
+ ClassDB::bind_method(D_METHOD("add_tab", "title", "icon:Texture"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture>()));
ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &Tabs::set_tab_align);
ClassDB::bind_method(D_METHOD("get_tab_align"), &Tabs::get_tab_align);
ClassDB::bind_method(D_METHOD("ensure_tab_visible", "idx"), &Tabs::ensure_tab_visible);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 8baca50d32..a7c31361e8 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -49,6 +49,10 @@ static bool _is_symbol(CharType c) {
return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
}
+static bool _is_whitespace(CharType c) {
+ return c == '\t' || c == ' ';
+}
+
static bool _is_char(CharType c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
@@ -1801,7 +1805,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
- if (k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_RETURN || k->get_scancode() == KEY_TAB) {
+ if (k->get_scancode() == KEY_KP_ENTER || k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_TAB) {
_confirm_completion();
accept_event();
@@ -1970,8 +1974,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
switch (k->get_scancode()) {
- case KEY_ENTER:
- case KEY_RETURN: {
+ case KEY_KP_ENTER:
+ case KEY_ENTER: {
if (readonly)
break;
@@ -2096,45 +2100,43 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
break;
#ifdef APPLE_STYLE_KEYS
- if (k->get_alt()) {
+ if (k->get_alt() && cursor.column > 1) {
#else
if (k->get_alt()) {
scancode_handled = false;
break;
- } else if (k->get_command()) {
+ } else if (k->get_command() && cursor.column > 1) {
#endif
int line = cursor.line;
int column = cursor.column;
- bool prev_char = false;
- bool only_whitespace = true;
-
- while (only_whitespace && line > 0) {
-
- while (column > 0) {
- CharType c = text[line][column - 1];
-
- if (c != '\t' && c != ' ') {
- only_whitespace = false;
- break;
- }
+ // check if we are removing a single whitespace, if so remove it and the next char type
+ // else we just remove the whitespace
+ bool only_whitespace = false;
+ if (_is_whitespace(text[line][column - 1]) && _is_whitespace(text[line][column - 2])) {
+ only_whitespace = true;
+ } else if (_is_whitespace(text[line][column - 1])) {
+ // remove the single whitespace
+ column--;
+ }
- column--;
- }
+ // check if its a text char
+ bool only_char = (_is_text_char(text[line][column - 1]) && !only_whitespace);
- if (only_whitespace) {
- line--;
- column = text[line].length();
- }
- }
+ // if its not whitespace or char then symbol.
+ bool only_symbols = !(only_whitespace || only_char);
while (column > 0) {
- bool ischar = _is_text_char(text[line][column - 1]);
+ bool is_whitespace = _is_whitespace(text[line][column - 1]);
+ bool is_text_char = _is_text_char(text[line][column - 1]);
- if (prev_char && !ischar)
+ if (only_whitespace && !is_whitespace) {
break;
-
- prev_char = ischar;
+ } else if (only_char && !is_text_char) {
+ break;
+ } else if (only_symbols && (is_whitespace || is_text_char)) {
+ break;
+ }
column--;
}
@@ -2356,52 +2358,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int next_column;
#ifdef APPLE_STYLE_KEYS
- if (k->get_alt()) {
+ if (k->get_alt() && cursor.column < curline_len - 1) {
#else
if (k->get_alt()) {
scancode_handled = false;
break;
- } else if (k->get_command()) {
+ } else if (k->get_command() && cursor.column < curline_len - 1) {
#endif
- int last_line = text.size() - 1;
int line = cursor.line;
int column = cursor.column;
- bool prev_char = false;
- bool only_whitespace = true;
-
- while (only_whitespace && line < last_line) {
-
- while (column < text[line].length()) {
- CharType c = text[line][column];
-
- if (c != '\t' && c != ' ') {
- only_whitespace = false;
- break;
- }
-
- column++;
- }
-
- if (only_whitespace) {
- line++;
- column = 0;
- }
+ // check if we are removing a single whitespace, if so remove it and the next char type
+ // else we just remove the whitespace
+ bool only_whitespace = false;
+ if (_is_whitespace(text[line][column]) && _is_whitespace(text[line][column + 1])) {
+ only_whitespace = true;
+ } else if (_is_whitespace(text[line][column])) {
+ // remove the single whitespace
+ column++;
}
- while (column < text[line].length()) {
+ // check if its a text char
+ bool only_char = (_is_text_char(text[line][column]) && !only_whitespace);
- bool ischar = _is_text_char(text[line][column]);
+ // if its not whitespace or char then symbol.
+ bool only_symbols = !(only_whitespace || only_char);
- if (prev_char && !ischar)
+ while (column < curline_len) {
+ bool is_whitespace = _is_whitespace(text[line][column]);
+ bool is_text_char = _is_text_char(text[line][column]);
+
+ if (only_whitespace && !is_whitespace) {
break;
- prev_char = ischar;
+ } else if (only_char && !is_text_char) {
+ break;
+ } else if (only_symbols && (is_whitespace || is_text_char)) {
+ break;
+ }
column++;
}
next_line = line;
next_column = column;
+
} else {
next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
}
@@ -4353,6 +4353,23 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
+ bool inside_quotes = false;
+ int qbegin, qend;
+ for (int i = 0; i < s.length(); i++) {
+ if (s[i] == '"') {
+ if (inside_quotes) {
+ qend = i;
+ inside_quotes = false;
+ if (col >= qbegin && col <= qend) {
+ return s.substr(qbegin, qend - qbegin);
+ }
+ } else {
+ qbegin = i + 1;
+ inside_quotes = true;
+ }
+ }
+ }
+
while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
beg--;
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 1456ab51c0..9499ba9dcd 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1605,7 +1605,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
int plus = 1;
while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
- plus++;
col_width += cache.hseparation;
col_width += get_column_width(i + plus);
plus++;
@@ -1918,8 +1917,8 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
void Tree::_text_editor_modal_close() {
if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE) ||
- Input::get_singleton()->is_key_pressed(KEY_ENTER) ||
- Input::get_singleton()->is_key_pressed(KEY_RETURN)) {
+ Input::get_singleton()->is_key_pressed(KEY_KP_ENTER) ||
+ Input::get_singleton()->is_key_pressed(KEY_ENTER)) {
return;
}
@@ -2238,8 +2237,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_F2:
- case KEY_RETURN:
- case KEY_ENTER: {
+ case KEY_ENTER:
+ case KEY_KP_ENTER: {
if (selected_item) {
//bring up editor if possible