summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp18
-rw-r--r--scene/gui/scroll_container.cpp28
-rw-r--r--scene/gui/scroll_container.h1
-rw-r--r--scene/gui/slider.cpp10
-rw-r--r--scene/gui/text_edit.cpp11
5 files changed, 48 insertions, 20 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 8b4d5d4980..ccc658b0aa 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2012,14 +2012,15 @@ Control *Control::find_next_valid_focus() const {
if (!data.focus_next.is_empty()) {
Node *n = get_node(data.focus_next);
+ Control *c;
if (n) {
- from = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!from, NULL, "Next focus node is not a control: " + n->get_name() + ".");
+ c = Object::cast_to<Control>(n);
+ ERR_FAIL_COND_V_MSG(!c, NULL, "Next focus node is not a control: " + n->get_name() + ".");
} else {
return NULL;
}
- if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE)
- return from;
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ return c;
}
// find next child
@@ -2102,14 +2103,15 @@ Control *Control::find_prev_valid_focus() const {
if (!data.focus_prev.is_empty()) {
Node *n = get_node(data.focus_prev);
+ Control *c;
if (n) {
- from = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!from, NULL, "Previous focus node is not a control: " + n->get_name() + ".");
+ c = Object::cast_to<Control>(n);
+ ERR_FAIL_COND_V_MSG(!c, NULL, "Previous focus node is not a control: " + n->get_name() + ".");
} else {
return NULL;
}
- if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE)
- return from;
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ return c;
}
// find prev child
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index fa23bf91dd..cb9ae875b7 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -30,6 +30,7 @@
#include "scroll_container.h"
#include "core/os/os.h"
+#include "scene/main/viewport.h"
bool ScrollContainer::clips_input() const {
@@ -232,6 +233,27 @@ void ScrollContainer::_update_scrollbar_position() {
v_scroll->raise();
}
+void ScrollContainer::_ensure_focused_visible(Control *p_control) {
+
+ if (is_a_parent_of(p_control)) {
+ Rect2 global_rect = get_global_rect();
+ Rect2 other_rect = p_control->get_global_rect();
+ float right_margin = 0;
+ if (v_scroll->is_visible()) {
+ right_margin += v_scroll->get_size().x;
+ }
+ float bottom_margin = 0;
+ if (h_scroll->is_visible()) {
+ bottom_margin += h_scroll->get_size().y;
+ }
+
+ float diff = MAX(MIN(other_rect.position.y, global_rect.position.y), other_rect.position.y + other_rect.size.y - global_rect.size.y + bottom_margin);
+ set_v_scroll(get_v_scroll() + (diff - global_rect.position.y));
+ diff = MAX(MIN(other_rect.position.x, global_rect.position.x), other_rect.position.x + other_rect.size.x - global_rect.size.x + right_margin);
+ set_h_scroll(get_h_scroll() + (diff - global_rect.position.x));
+ }
+}
+
void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
@@ -239,6 +261,11 @@ void ScrollContainer::_notification(int p_what) {
call_deferred("_update_scrollbar_position");
};
+ if (p_what == NOTIFICATION_READY) {
+
+ get_viewport()->connect("gui_focus_changed", this, "_ensure_focused_visible");
+ }
+
if (p_what == NOTIFICATION_SORT_CHILDREN) {
child_max_size = Size2(0, 0);
@@ -521,6 +548,7 @@ void ScrollContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll);
ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled);
ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position);
+ ClassDB::bind_method(D_METHOD("_ensure_focused_visible"), &ScrollContainer::_ensure_focused_visible);
ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll);
ClassDB::bind_method(D_METHOD("get_h_scroll"), &ScrollContainer::get_h_scroll);
ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &ScrollContainer::set_v_scroll);
diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h
index 2ab169f4d0..1d247f14c6 100644
--- a/scene/gui/scroll_container.h
+++ b/scene/gui/scroll_container.h
@@ -75,6 +75,7 @@ protected:
static void _bind_methods();
void _update_scrollbar_position();
+ void _ensure_focused_visible(Control *p_node);
public:
int get_v_scroll() const;
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index ba57be1686..cbb2db7788 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -166,7 +166,6 @@ void Slider::_notification(int p_what) {
RID ci = get_canvas_item();
Size2i size = get_size();
Ref<StyleBox> style = get_stylebox("slider");
- Ref<StyleBox> focus = get_stylebox("focus");
Ref<StyleBox> grabber_area = get_stylebox("grabber_area");
Ref<Texture> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled");
Ref<Texture> tick = get_icon("tick");
@@ -178,10 +177,7 @@ void Slider::_notification(int p_what) {
float areasize = size.height - grabber->get_size().height;
style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height)));
grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * ratio - grabber->get_size().height / 2), Size2i(widget_width, areasize * ratio + grabber->get_size().width / 2)));
- /*
- if (mouse_inside||has_focus())
- focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
- */
+
if (ticks > 1) {
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
for (int i = 0; i < ticks; i++) {
@@ -198,10 +194,6 @@ void Slider::_notification(int p_what) {
style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height)));
grabber_area->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(areasize * ratio + grabber->get_size().width / 2, widget_height)));
- /*
- if (mouse_inside||has_focus())
- focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
- */
if (ticks > 1) {
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index bf3ec9b05b..9bcacd6ee3 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -5177,11 +5177,16 @@ void TextEdit::cut() {
OS::get_singleton()->set_clipboard(clipboard);
cursor_set_line(cursor.line);
cursor_set_column(0);
- _remove_text(cursor.line, 0, cursor.line, text[cursor.line].length());
- backspace_at_cursor();
+ if (cursor.line == 0 && get_line_count() > 1) {
+ _remove_text(cursor.line, 0, cursor.line + 1, 0);
+ } else {
+ _remove_text(cursor.line, 0, cursor.line, text[cursor.line].length());
+ backspace_at_cursor();
+ cursor_set_line(cursor.line + 1);
+ }
+
update();
- cursor_set_line(cursor.line + 1);
cut_copy_line = clipboard;
} else {