You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
[TextEdit] Draw guidelines under the text and caret.
This commit is contained in:
@@ -70,29 +70,10 @@ void CodeEdit::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
RID ci = get_canvas_item();
|
||||
const Size2 size = get_size();
|
||||
const bool caret_visible = is_caret_visible();
|
||||
const bool rtl = is_layout_rtl();
|
||||
const int row_height = get_line_height();
|
||||
|
||||
if (line_length_guideline_columns.size() > 0) {
|
||||
const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
|
||||
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
|
||||
|
||||
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
|
||||
const int column_pos = theme_cache.font->get_string_size(String("0").repeat((int)line_length_guideline_columns[i]), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x;
|
||||
const int xoffset = xmargin_beg + column_pos - get_h_scroll();
|
||||
if (xoffset > xmargin_beg && xoffset < xmargin_end) {
|
||||
Color guideline_color = (i == 0) ? theme_cache.line_length_guideline_color : theme_cache.line_length_guideline_color * Color(1, 1, 1, 0.5);
|
||||
if (rtl) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color);
|
||||
continue;
|
||||
}
|
||||
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (caret_visible) {
|
||||
const bool draw_code_completion = code_completion_active && !code_completion_options.is_empty();
|
||||
const bool draw_code_hint = !code_hint.is_empty();
|
||||
@@ -280,6 +261,32 @@ void CodeEdit::_notification(int p_what) {
|
||||
}
|
||||
}
|
||||
|
||||
void CodeEdit::_draw_guidelines() {
|
||||
if (line_length_guideline_columns.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
const Size2 size = get_size();
|
||||
const bool rtl = is_layout_rtl();
|
||||
|
||||
const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
|
||||
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
|
||||
|
||||
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
|
||||
const int column_pos = theme_cache.font->get_string_size(String("0").repeat((int)line_length_guideline_columns[i]), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x;
|
||||
const int xoffset = xmargin_beg + column_pos - get_h_scroll();
|
||||
if (xoffset > xmargin_beg && xoffset < xmargin_end) {
|
||||
Color guideline_color = (i == 0) ? theme_cache.line_length_guideline_color : theme_cache.line_length_guideline_color * Color(1, 1, 1, 0.5);
|
||||
if (rtl) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color);
|
||||
continue;
|
||||
}
|
||||
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
Ref<InputEventPanGesture> pan_gesture = p_gui_input;
|
||||
if (pan_gesture.is_valid() && code_completion_active && code_completion_rect.has_point(pan_gesture->get_position())) {
|
||||
|
||||
Reference in New Issue
Block a user