| 50 | } |
| 51 | |
| 52 | void CodeEdit::_notification(int p_what) { |
| 53 | switch (p_what) { |
| 54 | case NOTIFICATION_READY: { |
| 55 | _apply_project_settings(); |
| 56 | #ifdef TOOLS_ENABLED |
| 57 | if (Engine::get_singleton()->is_editor_hint()) { |
| 58 | ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CodeEdit::_apply_project_settings)); |
| 59 | } |
| 60 | #endif // TOOLS_ENABLED |
| 61 | } break; |
| 62 | |
| 63 | case NOTIFICATION_THEME_CHANGED: { |
| 64 | set_gutter_width(main_gutter, get_line_height()); |
| 65 | _update_line_number_gutter_width(); |
| 66 | set_gutter_width(fold_gutter, get_line_height() / 1.2); |
| 67 | _clear_line_number_text_cache(); |
| 68 | } break; |
| 69 | |
| 70 | case NOTIFICATION_TRANSLATION_CHANGED: |
| 71 | [[fallthrough]]; |
| 72 | case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: |
| 73 | [[fallthrough]]; |
| 74 | case NOTIFICATION_VISIBILITY_CHANGED: { |
| 75 | // Avoid having many hidden text editors with unused cache filling up memory. |
| 76 | _clear_line_number_text_cache(); |
| 77 | } break; |
| 78 | |
| 79 | case NOTIFICATION_DRAW: { |
| 80 | RID ci = get_canvas_item(); |
| 81 | const bool caret_visible = is_caret_visible(); |
| 82 | const bool rtl = is_layout_rtl(); |
| 83 | const int row_height = get_line_height(); |
| 84 | |
| 85 | if (caret_visible) { |
| 86 | const bool draw_code_completion = code_completion_active && !code_completion_options.is_empty(); |
| 87 | const bool draw_code_hint = !code_hint.is_empty(); |
| 88 | |
| 89 | /* Code hint */ |
| 90 | Size2 code_hint_minsize; |
| 91 | if (draw_code_hint) { |
| 92 | const int font_height = theme_cache.font->get_height(theme_cache.font_size); |
| 93 | |
| 94 | Vector<String> code_hint_lines = code_hint.split("\n"); |
| 95 | int line_count = code_hint_lines.size(); |
| 96 | |
| 97 | int max_width = 0; |
| 98 | for (int i = 0; i < line_count; i++) { |
| 99 | max_width = MAX(max_width, theme_cache.font->get_string_size(code_hint_lines[i], HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x); |
| 100 | } |
| 101 | code_hint_minsize = theme_cache.code_hint_style->get_minimum_size() + Size2(max_width, line_count * font_height + (theme_cache.line_spacing * line_count - 1)); |
| 102 | |
| 103 | int offset = theme_cache.font->get_string_size(code_hint_lines[0].substr(0, code_hint_lines[0].find(String::chr(0xFFFF))), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x; |
| 104 | if (code_hint_xpos == -0xFFFF) { |
| 105 | code_hint_xpos = get_caret_draw_pos().x - offset; |
| 106 | } |
| 107 | Point2 hint_ofs = Vector2(code_hint_xpos, get_caret_draw_pos().y); |
| 108 | if (code_hint_draw_below) { |
| 109 | hint_ofs.y += theme_cache.line_spacing / 2.0f; |
nothing calls this directly
no test coverage detected