summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/box_container.cpp2
-rw-r--r--scene/gui/container.cpp2
-rw-r--r--scene/gui/control.cpp5
-rw-r--r--scene/gui/graph_edit.cpp1
-rw-r--r--scene/gui/grid_container.cpp2
-rw-r--r--scene/gui/line_edit.cpp39
-rw-r--r--scene/gui/line_edit.h1
-rw-r--r--scene/gui/option_button.cpp9
-rw-r--r--scene/gui/panel.cpp2
-rw-r--r--scene/gui/panel_container.cpp2
-rw-r--r--scene/gui/rich_text_label.cpp24
-rw-r--r--scene/gui/split_container.cpp6
-rw-r--r--scene/gui/text_edit.cpp2
-rw-r--r--scene/gui/tree.cpp13
-rw-r--r--scene/gui/tree.h3
15 files changed, 74 insertions, 39 deletions
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 24312af1b5..e0bfeac9f7 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -289,8 +289,6 @@ BoxContainer::BoxContainer(bool p_vertical) {
vertical = p_vertical;
align = ALIGN_BEGIN;
- //set_ignore_mouse(true);
- set_mouse_filter(MOUSE_FILTER_PASS);
}
void BoxContainer::_bind_methods() {
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index b07fec90c2..b411f563b8 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -197,4 +197,6 @@ void Container::_bind_methods() {
Container::Container() {
pending_sort = false;
+ // All containers should let mouse events pass by default.
+ set_mouse_filter(MOUSE_FILTER_PASS);
}
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index ae48a1356e..4c70bd1d39 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -462,11 +462,6 @@ void Control::_update_canvas_item_transform() {
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
- // We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot()
- if (is_inside_tree() && Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) {
- xform[2] = xform[2].round();
- }
-
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 00ce57eb04..c09b2414b2 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -1342,7 +1342,6 @@ GraphEdit::GraphEdit() {
top_layer->set_mouse_filter(MOUSE_FILTER_PASS);
top_layer->set_anchors_and_margins_preset(Control::PRESET_WIDE);
top_layer->connect("draw", this, "_top_layer_draw");
- top_layer->set_mouse_filter(MOUSE_FILTER_PASS);
top_layer->connect("gui_input", this, "_top_layer_input");
connections_layer = memnew(Control);
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 04aed532d4..0028093a95 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -247,7 +247,5 @@ Size2 GridContainer::get_minimum_size() const {
}
GridContainer::GridContainer() {
-
- set_mouse_filter(MOUSE_FILTER_PASS);
columns = 1;
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 7afc3b0d00..2504989d2c 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -184,6 +184,12 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_H: {
remap_key = KEY_BACKSPACE;
} break;
+ case KEY_A: {
+ remap_key = KEY_HOME;
+ } break;
+ case KEY_E: {
+ remap_key = KEY_END;
+ } break;
}
if (remap_key != KEY_UNKNOWN) {
@@ -240,15 +246,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
deselect();
text = text.substr(cursor_pos, text.length() - cursor_pos);
-
- Ref<Font> font = get_font("font");
-
- cached_width = 0;
- if (font != NULL) {
- for (int i = 0; i < text.length(); i++)
- cached_width += font->get_char_size(text[i]).width;
- }
-
+ update_cached_width();
set_cursor_position(0);
_text_changed();
}
@@ -1358,18 +1356,10 @@ void LineEdit::set_window_pos(int p_pos) {
void LineEdit::append_at_cursor(String p_text) {
if ((max_length <= 0) || (text.length() + p_text.length() <= max_length)) {
-
- Ref<Font> font = get_font("font");
- if (font != NULL) {
- for (int i = 0; i < p_text.length(); i++)
- cached_width += font->get_char_size(p_text[i]).width;
- } else {
- cached_width = 0;
- }
-
String pre = text.substr(0, cursor_pos);
String post = text.substr(cursor_pos, text.length() - cursor_pos);
text = pre + p_text + post;
+ update_cached_width();
set_cursor_position(cursor_pos + p_text.length());
} else {
emit_signal("text_change_rejected");
@@ -1499,6 +1489,7 @@ bool LineEdit::is_editable() const {
void LineEdit::set_secret(bool p_secret) {
pass = p_secret;
+ update_cached_width();
update();
}
@@ -1514,6 +1505,7 @@ void LineEdit::set_secret_character(const String &p_string) {
ERR_FAIL_COND_MSG(p_string.length() != 1, "Secret character must be exactly one character long (" + itos(p_string.length()) + " characters given).");
secret_character = p_string;
+ update_cached_width();
update();
}
@@ -1685,6 +1677,17 @@ void LineEdit::_emit_text_change() {
text_changed_dirty = false;
}
+void LineEdit::update_cached_width() {
+ Ref<Font> font = get_font("font");
+ cached_width = 0;
+ if (font != NULL) {
+ String text = get_text();
+ for (int i = 0; i < text.length(); i++) {
+ cached_width += font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
+ }
+}
+
void LineEdit::update_placeholder_width() {
if ((max_length <= 0) || (placeholder_translated.length() <= max_length)) {
Ref<Font> font = get_font("font");
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index cf597d11b6..037238d682 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -132,6 +132,7 @@ private:
void _emit_text_change();
bool expand_to_text_length;
+ void update_cached_width();
void update_placeholder_width();
bool caret_blink_enabled;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 8598a953b4..3f46afa8e8 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -36,7 +36,14 @@ Size2 OptionButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
if (has_icon("arrow")) {
- minsize.width += Control::get_icon("arrow")->get_width() + get_constant("hseparation");
+ const Size2 padding = get_stylebox("normal")->get_minimum_size();
+ const Size2 arrow_size = Control::get_icon("arrow")->get_size();
+
+ Size2 content_size = minsize - padding;
+ content_size.width += arrow_size.width + get_constant("hseparation");
+ content_size.height = MAX(content_size.height, arrow_size.height);
+
+ minsize = content_size + padding;
}
return minsize;
diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp
index aa1a381934..0356607071 100644
--- a/scene/gui/panel.cpp
+++ b/scene/gui/panel.cpp
@@ -42,7 +42,7 @@ void Panel::_notification(int p_what) {
}
Panel::Panel() {
-
+ // Has visible stylebox, so stop by default.
set_mouse_filter(MOUSE_FILTER_STOP);
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 74663c33e3..6cf23b8a32 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -103,4 +103,6 @@ void PanelContainer::_notification(int p_what) {
}
PanelContainer::PanelContainer() {
+ // Has visible stylebox, so stop by default.
+ set_mouse_filter(MOUSE_FILTER_STOP);
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 6c2928c65c..b19e1d8362 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -33,8 +33,13 @@
#include "core/math/math_defs.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
-#include "modules/regex/regex.h"
#include "scene/scene_string_names.h"
+
+#include "modules/modules_enabled.gen.h"
+#ifdef MODULE_REGEX_ENABLED
+#include "modules/regex/regex.h"
+#endif
+
#ifdef TOOLS_ENABLED
#include "editor/editor_scale.h"
#endif
@@ -199,6 +204,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int line_ascent = cfont->get_ascent();
int line_descent = cfont->get_descent();
+ int backtrack = 0; // for dynamic hidden content.
+
int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW
Variant meta;
@@ -209,6 +216,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
{ \
if (p_mode != PROCESS_CACHE) { \
line++; \
+ backtrack = 0; \
if (!line_is_blank) { \
nonblank_line_count++; \
} \
@@ -258,7 +266,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \
l.minimum_width = MAX(l.minimum_width, m_width); \
} \
- if (wofs + m_width > p_width) { \
+ if (wofs - backtrack + m_width > p_width) { \
line_wrapped = true; \
if (p_mode == PROCESS_CACHE) { \
if (spaces > 0) \
@@ -385,6 +393,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int fw = 0;
lh = 0;
+
if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1;
@@ -427,13 +436,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
{
- int ofs = 0;
+ int ofs = 0 - backtrack;
for (int i = 0; i < end; i++) {
int pofs = wofs + ofs;
if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
- //int o = (wofs+w)-p_click_pos.x;
int cw = font->get_char_size(c[i], c[i + 1]).x;
@@ -476,7 +484,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
bool visible = visible_characters < 0 || ((p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)) &&
faded_visibility > 0.0f);
+ const bool previously_visible = visible;
+
for (int j = 0; j < fx_stack.size(); j++) {
+
ItemFX *item_fx = fx_stack[j];
if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
@@ -570,6 +581,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} else {
cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color);
}
+ } else if (previously_visible) {
+ backtrack += font->get_char_size(fx_char, c[i + 1]).x;
}
p_char_count++;
@@ -643,6 +656,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
case ITEM_NEWLINE: {
lh = 0;
+
if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
line_is_blank = true;
@@ -2864,6 +2878,7 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi
Vector<String> values = parts[1].split(",", false);
+#ifdef MODULE_REGEX_ENABLED
RegEx color = RegEx();
color.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
RegEx nodepath = RegEx();
@@ -2897,6 +2912,7 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi
a.append(values[j]);
}
}
+#endif
if (values.size() > 1) {
d[key] = a;
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index bb5260b15e..079907db07 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -266,7 +266,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
if (dragging)
- return (vertical ? CURSOR_VSIZE : CURSOR_HSIZE);
+ return (vertical ? CURSOR_VSPLIT : CURSOR_HSPLIT);
if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) {
@@ -275,11 +275,11 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
if (vertical) {
if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep)
- return CURSOR_VSIZE;
+ return CURSOR_VSPLIT;
} else {
if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep)
- return CURSOR_HSIZE;
+ return CURSOR_HSPLIT;
}
}
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 6de2f0b570..93d0ae080b 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4480,7 +4480,7 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_
if (p_row - move_up > 0 && !is_line_hidden(p_row - move_up)) {
p_row -= move_up;
} else {
- WARN_PRINTS(("Cursor set to hidden line " + itos(p_row) + " and there are no nonhidden lines."));
+ WARN_PRINT(("Cursor set to hidden line " + itos(p_row) + " and there are no nonhidden lines."));
}
}
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 964f376dbd..790e1d5f4f 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1121,7 +1121,7 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
}
rect.position.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent();
- font->draw(ci, rect.position, text, p_color, rect.size.x);
+ font->draw(ci, rect.position, text, p_color, MAX(0, rect.size.width));
}
int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) {
@@ -3630,6 +3630,17 @@ TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_select
return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable);
}
+TreeItem *Tree::get_item_with_text(const String &p_find) const {
+ for (TreeItem *current = root; current; current = current->get_next_visible()) {
+ for (int i = 0; i < columns.size(); i++) {
+ if (current->get_text(i) == p_find) {
+ return current;
+ }
+ }
+ }
+ return NULL;
+}
+
void Tree::_do_incr_search(const String &p_add) {
uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index d87de6e773..f3c88eb5ac 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -577,7 +577,10 @@ public:
Rect2 get_item_rect(TreeItem *p_item, int p_column = -1) const;
bool edit_selected();
+ // First item that starts with the text, from the current focused item down and wraps around.
TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false);
+ // First item that matches the whole text, from the first item down.
+ TreeItem *get_item_with_text(const String &p_find) const;
Point2 get_scroll() const;
void scroll_to_item(TreeItem *p_item);