diff options
author | Eric M <itsjusteza@gmail.com> | 2021-09-29 19:37:27 +1000 |
---|---|---|
committer | Eric M <itsjusteza@gmail.com> | 2021-09-30 22:15:47 +1000 |
commit | e0f8410d1621f6766ebf0600fdb6fe85c3e8157f (patch) | |
tree | afc431eaa552b174e96ddf2e7005e7a52c3a3b61 /scene/gui | |
parent | b1237b5caca9c9193b63698d9a05f13e11e53860 (diff) |
Improved breakpoint gutter for CodeEdit.
Added preview of breakpoint placement on hover. Added override of icon for the Editor to use an SVG so it is no longer blurry.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/code_edit.cpp | 19 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 26 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
3 files changed, 40 insertions, 6 deletions
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index c7d1d7ef82..0476a764a5 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -1146,13 +1146,20 @@ bool CodeEdit::is_drawing_executing_lines_gutter() const { } void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) { - if (draw_breakpoints && is_line_breakpointed(p_line)) { - int padding = p_region.size.x / 6; + if (draw_breakpoints) { + bool hovering = p_region.has_point(get_local_mouse_pos()); + bool breakpointed = is_line_breakpointed(p_line); - Rect2 breakpoint_region = p_region; - breakpoint_region.position += Point2(padding, padding); - breakpoint_region.size -= Point2(padding, padding) * 2; - breakpoint_icon->draw_rect(get_canvas_item(), breakpoint_region, false, breakpoint_color); + if (breakpointed || (hovering && !is_dragging_cursor())) { + int padding = p_region.size.x / 6; + Rect2 icon_region = p_region; + icon_region.position += Point2(padding, padding); + icon_region.size -= Point2(padding, padding) * 2; + + // Darken icon when hovering & not yet breakpointed. + Color use_color = hovering && !breakpointed ? breakpoint_color.darkened(0.4) : breakpoint_color; + breakpoint_icon->draw_rect(get_canvas_item(), icon_region, false, use_color); + } } if (draw_bookmarks && is_line_bookmarked(p_line)) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5b13e1da0b..7a746c27ef 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1636,6 +1636,32 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) { } } } + + // Check if user is hovering a different gutter, and update if yes. + Vector2i current_hovered_gutter = Vector2i(-1, -1); + + int left_margin = style_normal->get_margin(SIDE_LEFT); + if (mpos.x <= left_margin + gutters_width + gutter_padding) { + int hovered_row = get_line_column_at_pos(mpos).y; + for (int i = 0; i < gutters.size(); i++) { + if (!gutters[i].draw || gutters[i].width <= 0) { + continue; + } + + if (mpos.x > left_margin && mpos.x <= (left_margin + gutters[i].width) - 3) { + // We are in this gutter i's horizontal area. + current_hovered_gutter = Vector2i(i, hovered_row); + break; + } + + left_margin += gutters[i].width; + } + } + + if (current_hovered_gutter != hovered_gutter) { + hovered_gutter = current_hovered_gutter; + update(); + } } if (draw_minimap && !dragging_selection) { diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b1226f2aff..db16d09c58 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -477,6 +477,7 @@ private: Vector<GutterInfo> gutters; int gutters_width = 0; int gutter_padding = 0; + Vector2i hovered_gutter = Vector2i(-1, -1); // X = gutter index, Y = row. void _update_gutter_width(); |