diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/aspect_ratio_container.cpp | 12 | ||||
-rw-r--r-- | scene/gui/code_edit.cpp | 4 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 113 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 12 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 10 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 1 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 14 | ||||
-rw-r--r-- | scene/gui/label.cpp | 259 | ||||
-rw-r--r-- | scene/gui/label.h | 4 | ||||
-rw-r--r-- | scene/gui/popup.cpp | 11 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 6 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 34 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 1 | ||||
-rw-r--r-- | scene/gui/tab_bar.cpp | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 5 |
15 files changed, 274 insertions, 214 deletions
diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cpp index 802189c374..94240ccead 100644 --- a/scene/gui/aspect_ratio_container.cpp +++ b/scene/gui/aspect_ratio_container.cpp @@ -30,6 +30,8 @@ #include "aspect_ratio_container.h" +#include "scene/gui/texture_rect.h" + Size2 AspectRatioContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { @@ -113,6 +115,16 @@ void AspectRatioContainer::_notification(int p_what) { if (c->is_set_as_top_level()) { continue; } + + // Temporary fix for editor crash. + TextureRect *trect = Object::cast_to<TextureRect>(c); + if (trect) { + if (trect->get_expand_mode() == TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL || trect->get_expand_mode() == TextureRect::EXPAND_FIT_HEIGHT_PROPORTIONAL) { + WARN_PRINT_ONCE("Proportional TextureRect is currently not supported inside AspectRatioContainer"); + continue; + } + } + Size2 child_minsize = c->get_combined_minimum_size(); Size2 child_size = Size2(ratio, 1.0); float scale_factor = 1.0; diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index b084cb5bea..ee39327d4d 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -896,6 +896,7 @@ void CodeEdit::indent_lines() { set_caret_column(get_caret_column(c) + selection_offset, false, c); } end_complex_operation(); + queue_redraw(); } void CodeEdit::unindent_lines() { @@ -973,6 +974,7 @@ void CodeEdit::unindent_lines() { set_caret_column(initial_cursor_column - removed_characters, false, c); } end_complex_operation(); + queue_redraw(); } int CodeEdit::_calculate_spaces_till_next_left_indent(int p_column) const { @@ -2856,7 +2858,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() { const int caret_line = get_caret_line(); const int caret_column = get_caret_column(); const String line = get_line(caret_line); - ERR_FAIL_INDEX_MSG(caret_column - 1, line.length(), "Caret column exceeds line length."); + ERR_FAIL_INDEX_MSG(caret_column, line.length() + 1, "Caret column exceeds line length."); if (caret_column > 0 && line[caret_column - 1] == '(' && !code_completion_forced) { cancel_code_completion(); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 0b0698188c..48e3759981 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -31,10 +31,12 @@ #include "color_picker.h" #include "core/input/input.h" +#include "core/io/image.h" #include "core/math/color.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "scene/gui/color_mode.h" +#include "servers/display_server.h" #include "thirdparty/misc/ok_color.h" #include "thirdparty/misc/ok_color_shader.h" @@ -90,8 +92,8 @@ void ColorPicker::_notification(int p_what) { } break; case NOTIFICATION_WM_CLOSE_REQUEST: { - if (screen != nullptr && screen->is_visible()) { - screen->hide(); + if (picker_window != nullptr && picker_window->is_visible()) { + picker_window->hide(); } } break; } @@ -1372,30 +1374,26 @@ void ColorPicker::_recent_preset_pressed(const bool p_pressed, ColorPresetButton emit_signal(SNAME("color_changed"), p_preset->get_preset_color()); } -void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { +void ColorPicker::_picker_texture_input(const Ref<InputEvent> &p_event) { if (!is_inside_tree()) { return; } Ref<InputEventMouseButton> bev = p_event; if (bev.is_valid() && bev->get_button_index() == MouseButton::LEFT && !bev->is_pressed()) { + set_pick_color(picker_color); emit_signal(SNAME("color_changed"), color); - screen->hide(); + picker_window->hide(); } Ref<InputEventMouseMotion> mev = p_event; if (mev.is_valid()) { - Viewport *r = get_tree()->get_root(); - if (!r->get_visible_rect().has_point(mev->get_global_position())) { - return; - } - - Ref<Image> img = r->get_texture()->get_image(); + Ref<Image> img = picker_texture_rect->get_texture()->get_image(); if (img.is_valid() && !img->is_empty()) { - Vector2 ofs = mev->get_global_position(); - Color c = img->get_pixel(ofs.x, ofs.y); - - set_pick_color(c); + Vector2 ofs = mev->get_position(); + picker_color = img->get_pixel(ofs.x, ofs.y); + picker_preview_style_box->set_bg_color(picker_color); + picker_preview_label->set_self_modulate(picker_color.get_luminance() < 0.5 ? Color(1.0f, 1.0f, 1.0f) : Color(0.0f, 0.0f, 0.0f)); } } } @@ -1409,27 +1407,79 @@ void ColorPicker::_add_preset_pressed() { emit_signal(SNAME("preset_added"), color); } -void ColorPicker::_screen_pick_pressed() { +void ColorPicker::_pick_button_pressed() { if (!is_inside_tree()) { return; } - Viewport *r = get_tree()->get_root(); - if (!screen) { - screen = memnew(Control); - r->add_child(screen); - screen->set_as_top_level(true); - screen->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - screen->set_default_cursor_shape(CURSOR_POINTING_HAND); - screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input)); - // It immediately toggles off in the first press otherwise. - screen->call_deferred(SNAME("connect"), "hidden", Callable(btn_pick, "set_pressed").bind(false)); + if (!picker_window) { + picker_window = memnew(Popup); + picker_window->hide(); + picker_window->set_transient(true); + add_child(picker_window); + + picker_texture_rect = memnew(TextureRect); + picker_texture_rect->set_anchors_preset(Control::PRESET_FULL_RECT); + picker_window->add_child(picker_texture_rect); + picker_texture_rect->set_default_cursor_shape(CURSOR_POINTING_HAND); + picker_texture_rect->connect(SNAME("gui_input"), callable_mp(this, &ColorPicker::_picker_texture_input)); + + picker_preview = memnew(Panel); + picker_preview->set_anchors_preset(Control::PRESET_CENTER_TOP); + picker_preview->set_mouse_filter(MOUSE_FILTER_IGNORE); + picker_window->add_child(picker_preview); + + picker_preview_label = memnew(Label); + picker_preview->set_anchors_preset(Control::PRESET_CENTER_TOP); + picker_preview_label->set_text("Color Picking active"); + picker_preview->add_child(picker_preview_label); + + picker_preview_style_box = (Ref<StyleBoxFlat>)memnew(StyleBoxFlat); + picker_preview_style_box->set_bg_color(Color(1.0, 1.0, 1.0)); + picker_preview->add_theme_style_override("panel", picker_preview_style_box); + } + + Rect2i screen_rect; + if (picker_window->is_embedded()) { + screen_rect = picker_window->get_embedder()->get_visible_rect(); + picker_window->set_position(Point2i()); + picker_texture_rect->set_texture(ImageTexture::create_from_image(picker_window->get_embedder()->get_texture()->get_image())); } else { - screen->show(); + screen_rect = picker_window->get_parent_rect(); + picker_window->set_position(screen_rect.position); + + Ref<Image> target_image = Image::create_empty(screen_rect.size.x, screen_rect.size.y, false, Image::FORMAT_RGB8); + DisplayServer *ds = DisplayServer::get_singleton(); + + // Add the Texture of each Window to the Image. + Vector<DisplayServer::WindowID> wl = ds->get_window_list(); + // FIXME: sort windows by visibility. + for (int index = 0; index < wl.size(); index++) { + DisplayServer::WindowID wid = wl[index]; + if (wid == DisplayServer::INVALID_WINDOW_ID) { + continue; + } + + ObjectID woid = DisplayServer::get_singleton()->window_get_attached_instance_id(wid); + if (woid == ObjectID()) { + continue; + } + + Window *w = Object::cast_to<Window>(ObjectDB::get_instance(woid)); + Ref<Image> img = w->get_texture()->get_image(); + if (!img.is_valid() || img->is_empty()) { + continue; + } + img->convert(Image::FORMAT_RGB8); + target_image->blit_rect(img, Rect2i(Point2i(0, 0), img->get_size()), w->get_position()); + } + + picker_texture_rect->set_texture(ImageTexture::create_from_image(target_image)); } - screen->move_to_front(); - // TODO: show modal no longer works, needs to be converted to a popup. - //screen->show_modal(); + + picker_window->set_size(screen_rect.size); + picker_preview->set_size(screen_rect.size / 10.0); // 10% of size in each axis. + picker_window->popup(); } void ColorPicker::_html_focus_exit() { @@ -1595,9 +1645,8 @@ ColorPicker::ColorPicker() { btn_pick = memnew(Button); sample_hbc->add_child(btn_pick); - btn_pick->set_toggle_mode(true); - btn_pick->set_tooltip_text(RTR("Pick a color from the editor window.")); - btn_pick->connect("pressed", callable_mp(this, &ColorPicker::_screen_pick_pressed)); + btn_pick->set_tooltip_text(RTR("Pick a color from the application window.")); + btn_pick->connect(SNAME("pressed"), callable_mp(this, &ColorPicker::_pick_button_pressed)); sample = memnew(TextureRect); sample_hbc->add_child(sample); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index f7578612cd..d02c3278e6 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -40,6 +40,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/menu_button.h" #include "scene/gui/option_button.h" +#include "scene/gui/panel.h" #include "scene/gui/popup.h" #include "scene/gui/separator.h" #include "scene/gui/slider.h" @@ -111,7 +112,12 @@ private: Vector<ColorMode *> modes; - Control *screen = nullptr; + Popup *picker_window = nullptr; + TextureRect *picker_texture_rect = nullptr; + Panel *picker_preview = nullptr; + Label *picker_preview_label = nullptr; + Ref<StyleBoxFlat> picker_preview_style_box; + Color picker_color; Control *uv_edit = nullptr; Control *w_edit = nullptr; AspectRatioContainer *wheel_edit = nullptr; @@ -211,10 +217,10 @@ private: void _line_edit_input(const Ref<InputEvent> &p_event); void _preset_input(const Ref<InputEvent> &p_event, const Color &p_color); void _recent_preset_pressed(const bool pressed, ColorPresetButton *p_preset); - void _screen_input(const Ref<InputEvent> &p_event); + void _picker_texture_input(const Ref<InputEvent> &p_event); void _text_changed(const String &p_new_text); void _add_preset_pressed(); - void _screen_pick_pressed(); + void _pick_button_pressed(); void _html_focus_exit(); inline int _get_preset_size(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 5dd8cde342..02abddaa43 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -35,7 +35,6 @@ #include "scene/gui/label.h" FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr; -FileDialog::GetIconFunc FileDialog::get_large_icon_func = nullptr; FileDialog::RegisterFunc FileDialog::register_func = nullptr; FileDialog::RegisterFunc FileDialog::unregister_func = nullptr; @@ -347,14 +346,15 @@ void FileDialog::_action_pressed() { } } - if (!valid) { + String file_name = file_text.strip_edges().get_file(); + if (!valid || file_name.is_empty()) { exterr->popup_centered(Size2(250, 80)); return; } if (dir_access->file_exists(f)) { - confirm_save->set_text(RTR("File exists, overwrite?")); - confirm_save->popup_centered(Size2(200, 80)); + confirm_save->set_text(vformat(RTR("File \"%s\" already exists.\nDo you want to overwrite it?"), f)); + confirm_save->popup_centered(Size2(250, 80)); } else { emit_signal(SNAME("file_selected"), f); hide(); @@ -1136,7 +1136,7 @@ FileDialog::FileDialog() { add_child(mkdirerr, false, INTERNAL_MODE_FRONT); exterr = memnew(AcceptDialog); - exterr->set_text(RTR("Must use a valid extension.")); + exterr->set_text(RTR("Invalid extension, or empty filename.")); add_child(exterr, false, INTERNAL_MODE_FRONT); update_filters(); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index d85cdcac90..7f80caf01d 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -60,7 +60,6 @@ public: typedef void (*RegisterFunc)(FileDialog *); static GetIconFunc get_icon_func; - static GetIconFunc get_large_icon_func; static RegisterFunc register_func; static RegisterFunc unregister_func; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 25a27d5e1a..d367a8d281 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -801,8 +801,9 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { search_string = ""; //any mousepress cancels for (int i = 4; i > 0; i--) { - if (current - current_columns * i >= 0 && CAN_SELECT(current - current_columns * i)) { - set_current(current - current_columns * i); + int index = current - current_columns * i; + if (index >= 0 && index < items.size() && CAN_SELECT(index)) { + set_current(index); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { emit_signal(SNAME("item_selected"), current); @@ -815,8 +816,9 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { search_string = ""; //any mousepress cancels for (int i = 4; i > 0; i--) { - if (current + current_columns * i < items.size() && CAN_SELECT(current + current_columns * i)) { - set_current(current + current_columns * i); + int index = current + current_columns * i; + if (index >= 0 && index < items.size() && CAN_SELECT(index)) { + set_current(index); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { emit_signal(SNAME("item_selected"), current); @@ -832,7 +834,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { if (current % current_columns != 0) { int current_row = current / current_columns; int next = current - 1; - while (!CAN_SELECT(next)) { + while (next >= 0 && !CAN_SELECT(next)) { next = next - 1; } if (next < 0 || !IS_SAME_ROW(next, current_row)) { @@ -852,7 +854,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { if (current % current_columns != (current_columns - 1) && current + 1 < items.size()) { int current_row = current / current_columns; int next = current + 1; - while (!CAN_SELECT(next)) { + while (next < items.size() && !CAN_SELECT(next)) { next = next + 1; } if (items.size() <= next || !IS_SAME_ROW(next, current_row)) { diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index c0ef71ee4f..b861d7af01 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -86,9 +86,7 @@ int Label::get_line_height(int p_line) const { } } -void Label::_shape() { - bool font_was_dirty = font_dirty; - +bool Label::_shape() { Ref<StyleBox> style = theme_cache.normal_style; int width = (get_size().width - style->get_minimum_size().width); @@ -103,7 +101,7 @@ void Label::_shape() { } const Ref<Font> &font = (settings.is_valid() && settings->get_font().is_valid()) ? settings->get_font() : theme_cache.font; int font_size = settings.is_valid() ? settings->get_font_size() : theme_cache.font_size; - ERR_FAIL_COND(font.is_null()); + ERR_FAIL_COND_V(font.is_null(), true); String txt = (uppercase) ? TS->string_to_upper(xl_text, language) : xl_text; if (visible_chars >= 0 && visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { txt = txt.substr(0, visible_chars); @@ -123,6 +121,7 @@ void Label::_shape() { dirty = false; font_dirty = false; lines_dirty = true; + // Note for future maintainers: forgetting stable width here (e.g., setting it to -1) may fix still undiscovered bugs. } if (lines_dirty) { @@ -135,129 +134,138 @@ void Label::_shape() { Size2i prev_minsize = minsize; minsize = Size2(); + bool can_process_lines = false; if (xl_text.length() == 0) { + can_process_lines = true; lines_dirty = false; - return; - } - - // Don't compute minimum size until width is stable (two shape requests in a row with the same width.) - // This avoids situations in which the initial width is very narrow and the label would break text - // into many very short lines, causing a very tall label that can leave a deformed container. - bool width_stabilized = get_size().width == stable_width; - stable_width = get_size().width; + } else { + // With autowrap on or off with trimming enabled, we won't compute the minimum size until width is stable + // (two shape requests in a row with the same width.) This avoids situations in which the initial width is + // very narrow and the label would break text into many very short lines, causing a very tall label that can + // leave a deformed container. In the remaining case (namely, autowrap off and no trimming), the label is + // free to dictate its own width, something that will be taken advtantage of. + bool can_dictate_width = autowrap_mode == TextServer::AUTOWRAP_OFF && overrun_behavior == TextServer::OVERRUN_NO_TRIMMING; + bool is_width_stable = get_size().width == stable_width; + can_process_lines = can_dictate_width || is_width_stable; + stable_width = get_size().width; + + if (can_process_lines) { + if (lines_dirty) { + BitField<TextServer::LineBreakFlag> autowrap_flags = TextServer::BREAK_MANDATORY; + switch (autowrap_mode) { + case TextServer::AUTOWRAP_WORD_SMART: + autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_ADAPTIVE | TextServer::BREAK_MANDATORY; + break; + case TextServer::AUTOWRAP_WORD: + autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY; + break; + case TextServer::AUTOWRAP_ARBITRARY: + autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY; + break; + case TextServer::AUTOWRAP_OFF: + break; + } + autowrap_flags = autowrap_flags | TextServer::BREAK_TRIM_EDGE_SPACES; - // With autowrap off, there's still a point in shaping before width is stable: to contribute a min width. - if (lines_dirty && (width_stabilized || autowrap_mode == TextServer::AUTOWRAP_OFF)) { - BitField<TextServer::LineBreakFlag> autowrap_flags = TextServer::BREAK_MANDATORY; - switch (autowrap_mode) { - case TextServer::AUTOWRAP_WORD_SMART: - autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_ADAPTIVE | TextServer::BREAK_MANDATORY; - break; - case TextServer::AUTOWRAP_WORD: - autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY; - break; - case TextServer::AUTOWRAP_ARBITRARY: - autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY; - break; - case TextServer::AUTOWRAP_OFF: - break; - } - autowrap_flags = autowrap_flags | TextServer::BREAK_TRIM_EDGE_SPACES; + PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags); + for (int i = 0; i < line_breaks.size(); i = i + 2) { + RID line = TS->shaped_text_substr(text_rid, line_breaks[i], line_breaks[i + 1] - line_breaks[i]); + lines_rid.push_back(line); + } + } - PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags); - for (int i = 0; i < line_breaks.size(); i = i + 2) { - RID line = TS->shaped_text_substr(text_rid, line_breaks[i], line_breaks[i + 1] - line_breaks[i]); - lines_rid.push_back(line); - } - } + if (can_dictate_width) { + for (int i = 0; i < lines_rid.size(); i++) { + if (minsize.width < TS->shaped_text_get_size(lines_rid[i]).x) { + minsize.width = TS->shaped_text_get_size(lines_rid[i]).x; + } + } - if (autowrap_mode == TextServer::AUTOWRAP_OFF) { - for (int i = 0; i < lines_rid.size(); i++) { - if (minsize.width < TS->shaped_text_get_size(lines_rid[i]).x) { - minsize.width = TS->shaped_text_get_size(lines_rid[i]).x; + width = (minsize.width - style->get_minimum_size().width); } - } - // With autowrap off, by now we already know the width the label will take. - width = (minsize.width - style->get_minimum_size().width); - width_stabilized = true; - } - - if (lines_dirty && width_stabilized) { - BitField<TextServer::TextOverrunFlag> overrun_flags = TextServer::OVERRUN_NO_TRIM; - switch (overrun_behavior) { - case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS: - overrun_flags.set_flag(TextServer::OVERRUN_TRIM); - overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY); - overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS); - break; - case TextServer::OVERRUN_TRIM_ELLIPSIS: - overrun_flags.set_flag(TextServer::OVERRUN_TRIM); - overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS); - break; - case TextServer::OVERRUN_TRIM_WORD: - overrun_flags.set_flag(TextServer::OVERRUN_TRIM); - overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY); - break; - case TextServer::OVERRUN_TRIM_CHAR: - overrun_flags.set_flag(TextServer::OVERRUN_TRIM); - break; - case TextServer::OVERRUN_NO_TRIMMING: - break; - } + if (lines_dirty) { + BitField<TextServer::TextOverrunFlag> overrun_flags = TextServer::OVERRUN_NO_TRIM; + switch (overrun_behavior) { + case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS: + overrun_flags.set_flag(TextServer::OVERRUN_TRIM); + overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY); + overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS); + break; + case TextServer::OVERRUN_TRIM_ELLIPSIS: + overrun_flags.set_flag(TextServer::OVERRUN_TRIM); + overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS); + break; + case TextServer::OVERRUN_TRIM_WORD: + overrun_flags.set_flag(TextServer::OVERRUN_TRIM); + overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY); + break; + case TextServer::OVERRUN_TRIM_CHAR: + overrun_flags.set_flag(TextServer::OVERRUN_TRIM); + break; + case TextServer::OVERRUN_NO_TRIMMING: + break; + } - // Fill after min_size calculation. + // Fill after min_size calculation. - int visible_lines = lines_rid.size(); - if (max_lines_visible >= 0 && visible_lines > max_lines_visible) { - visible_lines = max_lines_visible; - } - if (autowrap_mode != TextServer::AUTOWRAP_OFF) { - bool lines_hidden = visible_lines > 0 && visible_lines < lines_rid.size(); - if (lines_hidden) { - overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS); - } - if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL) { - for (int i = 0; i < lines_rid.size(); i++) { - if (i < visible_lines - 1 || lines_rid.size() == 1) { - TS->shaped_text_fit_to_width(lines_rid[i], width); - } else if (i == (visible_lines - 1)) { + int visible_lines = lines_rid.size(); + if (max_lines_visible >= 0 && visible_lines > max_lines_visible) { + visible_lines = max_lines_visible; + } + if (autowrap_mode != TextServer::AUTOWRAP_OFF) { + bool lines_hidden = visible_lines > 0 && visible_lines < lines_rid.size(); + if (lines_hidden) { + overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS); + } + if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL) { + for (int i = 0; i < lines_rid.size(); i++) { + if (i < visible_lines - 1 || lines_rid.size() == 1) { + TS->shaped_text_fit_to_width(lines_rid[i], width); + } else if (i == (visible_lines - 1)) { + TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags); + } + } + } else if (lines_hidden) { TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags); } - } - } else if (lines_hidden) { - TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags); - } - } else { - // Autowrap disabled. - for (int i = 0; i < lines_rid.size(); i++) { - if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL) { - TS->shaped_text_fit_to_width(lines_rid[i], width); - overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE); - TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags); - TS->shaped_text_fit_to_width(lines_rid[i], width, TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS); } else { - TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags); + // Autowrap disabled. + for (int i = 0; i < lines_rid.size(); i++) { + if (horizontal_alignment == HORIZONTAL_ALIGNMENT_FILL) { + TS->shaped_text_fit_to_width(lines_rid[i], width); + overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE); + TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags); + TS->shaped_text_fit_to_width(lines_rid[i], width, TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS); + } else { + TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags); + } + } + } + + int last_line = MIN(lines_rid.size(), visible_lines + lines_skipped); + int line_spacing = settings.is_valid() ? settings->get_line_spacing() : theme_cache.line_spacing; + for (int64_t i = lines_skipped; i < last_line; i++) { + minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; } - } - } - int last_line = MIN(lines_rid.size(), visible_lines + lines_skipped); - int line_spacing = settings.is_valid() ? settings->get_line_spacing() : theme_cache.line_spacing; - for (int64_t i = lines_skipped; i < last_line; i++) { - minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + lines_dirty = false; + } + } else { + callable_mp(this, &Label::_shape).call_deferred(); } + } - lines_dirty = false; + if (draw_pending) { + queue_redraw(); + draw_pending = false; } - if (minsize != prev_minsize || font_was_dirty) { + if (minsize != prev_minsize) { update_minimum_size(); } - if (!width_stabilized) { - callable_mp(this, &Label::_shape).call_deferred(); - } + return can_process_lines; } inline void draw_glyph(const Glyph &p_gl, const RID &p_canvas, const Color &p_font_color, const Vector2 &p_ofs) { @@ -367,10 +375,9 @@ void Label::_notification(int p_what) { } if (dirty || font_dirty || lines_dirty) { - _shape(); - if (lines_dirty) { + if (!_shape()) { // There will be another pass. - queue_redraw(); + draw_pending = true; break; } } @@ -396,7 +403,7 @@ void Label::_notification(int p_what) { style->draw(ci, Rect2(Point2(0, 0), get_size())); float total_h = 0.0; - int visible_lines = 0; + int lines_visible = 0; // Get number of lines to fit to the height. for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { @@ -404,14 +411,14 @@ void Label::_notification(int p_what) { if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } - visible_lines++; + lines_visible++; } - if (max_lines_visible >= 0 && visible_lines > max_lines_visible) { - visible_lines = max_lines_visible; + if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { + lines_visible = max_lines_visible; } - int last_line = MIN(lines_rid.size(), visible_lines + lines_skipped); + int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped); bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING); bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_LTR) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && !rtl_layout)); bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_RTL) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && rtl_layout)); @@ -428,7 +435,7 @@ void Label::_notification(int p_what) { total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM); int vbegin = 0, vsep = 0; - if (visible_lines > 0) { + if (lines_visible > 0) { switch (vertical_alignment) { case VERTICAL_ALIGNMENT_TOP: { // Nothing. @@ -445,8 +452,8 @@ void Label::_notification(int p_what) { } break; case VERTICAL_ALIGNMENT_FILL: { vbegin = 0; - if (visible_lines > 1) { - vsep = (size.y - (total_h - line_spacing)) / (visible_lines - 1); + if (lines_visible > 1) { + vsep = (size.y - (total_h - line_spacing)) / (lines_visible - 1); } else { vsep = 0; } @@ -615,6 +622,8 @@ void Label::_notification(int p_what) { } ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing; } + + draw_pending = false; } break; case NOTIFICATION_THEME_CHANGED: { @@ -666,25 +675,25 @@ int Label::get_line_count() const { int Label::get_visible_line_count() const { Ref<StyleBox> style = theme_cache.normal_style; int line_spacing = settings.is_valid() ? settings->get_line_spacing() : theme_cache.line_spacing; - int visible_lines = 0; + int lines_visible = 0; float total_h = 0.0; for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } - visible_lines++; + lines_visible++; } - if (visible_lines > lines_rid.size()) { - visible_lines = lines_rid.size(); + if (lines_visible > lines_rid.size()) { + lines_visible = lines_rid.size(); } - if (max_lines_visible >= 0 && visible_lines > max_lines_visible) { - visible_lines = max_lines_visible; + if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { + lines_visible = max_lines_visible; } - return visible_lines; + return lines_visible; } void Label::set_horizontal_alignment(HorizontalAlignment p_alignment) { @@ -969,7 +978,7 @@ void Label::_bind_methods() { ClassDB::bind_method(D_METHOD("get_visible_ratio"), &Label::get_visible_ratio); ClassDB::bind_method(D_METHOD("set_lines_skipped", "lines_skipped"), &Label::set_lines_skipped); ClassDB::bind_method(D_METHOD("get_lines_skipped"), &Label::get_lines_skipped); - ClassDB::bind_method(D_METHOD("set_max_lines_visible", "visible_lines"), &Label::set_max_lines_visible); + ClassDB::bind_method(D_METHOD("set_max_lines_visible", "lines_visible"), &Label::set_max_lines_visible); ClassDB::bind_method(D_METHOD("get_max_lines_visible"), &Label::get_max_lines_visible); ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "parser"), &Label::set_structured_text_bidi_override); ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override"), &Label::get_structured_text_bidi_override); diff --git a/scene/gui/label.h b/scene/gui/label.h index 448cb245eb..36b85f7af8 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -50,7 +50,6 @@ private: bool uppercase = false; bool lines_dirty = true; - bool dirty = true; bool font_dirty = true; RID text_rid; @@ -66,6 +65,7 @@ private: float visible_ratio = 1.0; int lines_skipped = 0; int max_lines_visible = -1; + bool draw_pending = false; Ref<LabelSettings> settings; @@ -83,7 +83,7 @@ private: int font_shadow_outline_size; } theme_cache; - void _shape(); + bool _shape(); void _invalidate(); protected: diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 2ea1b93810..432004dedc 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -36,7 +36,7 @@ void Popup::_input_from_window(const Ref<InputEvent> &p_event) { Ref<InputEventKey> key = p_event; - if (key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ESCAPE) { + if (get_flag(FLAG_POPUP) && key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ESCAPE) { _close_pressed(); } } @@ -102,12 +102,17 @@ void Popup::_notification(int p_what) { } } break; - case NOTIFICATION_WM_CLOSE_REQUEST: - case NOTIFICATION_APPLICATION_FOCUS_OUT: { + case NOTIFICATION_WM_CLOSE_REQUEST: { if (!is_in_edited_scene_root()) { _close_pressed(); } } break; + + case NOTIFICATION_APPLICATION_FOCUS_OUT: { + if (!is_in_edited_scene_root() && get_flag(FLAG_POPUP)) { + _close_pressed(); + } + } break; } } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1a6adca121..cf73729c0a 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1715,12 +1715,12 @@ void PopupMenu::activate_item(int p_item) { need_hide = false; } + emit_signal(SNAME("id_pressed"), id); + emit_signal(SNAME("index_pressed"), p_item); + if (need_hide) { hide(); } - - emit_signal(SNAME("id_pressed"), id); - emit_signal(SNAME("index_pressed"), p_item); } void PopupMenu::remove_item(int p_idx) { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index f9c9906efa..973b02b3a3 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1179,7 +1179,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o dot_ul_started = false; float y_off = TS->shaped_text_get_underline_position(rid); float underline_width = TS->shaped_text_get_underline_thickness(rid) * theme_cache.base_scale; - draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, underline_width * 2); + draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, MAX(2.0, underline_width * 2)); } if (_find_strikethrough(it)) { if (!st_started) { @@ -1341,7 +1341,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o dot_ul_started = false; float y_off = TS->shaped_text_get_underline_position(rid); float underline_width = TS->shaped_text_get_underline_thickness(rid) * theme_cache.base_scale; - draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, underline_width * 2); + draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, MAX(2.0, underline_width * 2)); } if (st_started) { st_started = false; @@ -1363,7 +1363,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o dot_ul_started = false; float y_off = TS->shaped_text_get_underline_position(rid); float underline_width = TS->shaped_text_get_underline_thickness(rid) * theme_cache.base_scale; - draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, underline_width * 2); + draw_dashed_line(dot_ul_start + Vector2(0, y_off), p_ofs + Vector2(off.x, off.y + y_off), dot_ul_color, underline_width, MAX(2.0, underline_width * 2)); } if (st_started) { st_started = false; @@ -5520,34 +5520,6 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(LIST_ROMAN); BIND_ENUM_CONSTANT(LIST_DOTS); - BIND_ENUM_CONSTANT(ITEM_FRAME); - BIND_ENUM_CONSTANT(ITEM_TEXT); - BIND_ENUM_CONSTANT(ITEM_IMAGE); - BIND_ENUM_CONSTANT(ITEM_NEWLINE); - BIND_ENUM_CONSTANT(ITEM_FONT); - BIND_ENUM_CONSTANT(ITEM_FONT_SIZE); - BIND_ENUM_CONSTANT(ITEM_FONT_FEATURES); - BIND_ENUM_CONSTANT(ITEM_COLOR); - BIND_ENUM_CONSTANT(ITEM_OUTLINE_SIZE); - BIND_ENUM_CONSTANT(ITEM_OUTLINE_COLOR); - BIND_ENUM_CONSTANT(ITEM_UNDERLINE); - BIND_ENUM_CONSTANT(ITEM_STRIKETHROUGH); - BIND_ENUM_CONSTANT(ITEM_PARAGRAPH); - BIND_ENUM_CONSTANT(ITEM_INDENT); - BIND_ENUM_CONSTANT(ITEM_LIST); - BIND_ENUM_CONSTANT(ITEM_TABLE); - BIND_ENUM_CONSTANT(ITEM_FADE); - BIND_ENUM_CONSTANT(ITEM_SHAKE); - BIND_ENUM_CONSTANT(ITEM_WAVE); - BIND_ENUM_CONSTANT(ITEM_TORNADO); - BIND_ENUM_CONSTANT(ITEM_RAINBOW); - BIND_ENUM_CONSTANT(ITEM_BGCOLOR); - BIND_ENUM_CONSTANT(ITEM_FGCOLOR); - BIND_ENUM_CONSTANT(ITEM_META); - BIND_ENUM_CONSTANT(ITEM_HINT); - BIND_ENUM_CONSTANT(ITEM_DROPCAP); - BIND_ENUM_CONSTANT(ITEM_CUSTOMFX); - BIND_ENUM_CONSTANT(MENU_COPY); BIND_ENUM_CONSTANT(MENU_SELECT_ALL); BIND_ENUM_CONSTANT(MENU_MAX); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index b01fccf14c..1dae8b75ca 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -740,7 +740,6 @@ public: }; VARIANT_ENUM_CAST(RichTextLabel::ListType); -VARIANT_ENUM_CAST(RichTextLabel::ItemType); VARIANT_ENUM_CAST(RichTextLabel::MenuItems); #endif // RICH_TEXT_LABEL_H diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index eca6cb3eef..5e378a0321 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -342,6 +342,8 @@ void TabBar::_notification(int p_what) { _shape(i); } + queue_redraw(); + [[fallthrough]]; } case NOTIFICATION_RESIZED: { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d785280701..ebca8296a0 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2681,6 +2681,7 @@ void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) { set_caret_line(get_caret_line(caret_idx), false, true, 0, caret_idx); set_caret_column(column, caret_idx == 0, caret_idx); + adjust_carets_after_edit(caret_idx, get_caret_line(caret_idx), column, get_caret_line(caret_idx), from_column); // Now we can clean up the overlapping caret. if (overlapping_caret_index != -1) { @@ -4362,7 +4363,9 @@ int TextEdit::get_minimap_line_at_pos(const Point2i &p_pos) const { if (first_vis_line > 0 && minimap_line >= 0) { minimap_line -= get_next_visible_line_index_offset_from(first_vis_line, 0, -num_lines_before).x; minimap_line -= (minimap_line > 0 && smooth_scroll_enabled ? 1 : 0); - } else { + } + + if (minimap_line < 0) { minimap_line = 0; } |