summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2020-09-10 21:25:00 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2021-05-22 14:41:55 +0100
commit00e10a842f0fdffa79ba60700b0dce3221492576 (patch)
tree4f6ac928c2f1bdc0e24860b8474c8d991c366a41 /scene/gui
parent1cc8cc96cbbe5f2ba6614bed8cc69633f4c363d5 (diff)
Add custom background line colour to TextEdit and remove marked lines
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp38
-rw-r--r--scene/gui/text_edit.h15
2 files changed, 37 insertions, 16 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index e305c6210d..053af39701 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -253,7 +253,6 @@ void TextEdit::Text::set(int p_line, const String &p_text, const Vector<Vector2i
void TextEdit::Text::insert(int p_at, const String &p_text, const Vector<Vector2i> &p_bidi_override) {
Line line;
line.gutters.resize(gutter_count);
- line.marked = false;
line.hidden = false;
line.data = p_text;
line.bidi_override = p_bidi_override;
@@ -867,6 +866,8 @@ void TextEdit::_notification(int p_what) {
Dictionary color_map = _get_line_syntax_highlighting(minimap_line);
+ Color line_background_color = text.get_line_background_color(minimap_line);
+ line_background_color.a *= 0.6;
Color current_color = cache.font_color;
if (readonly) {
current_color = cache.font_readonly_color;
@@ -901,6 +902,12 @@ void TextEdit::_notification(int p_what) {
} else {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color);
}
+ } else if (line_background_color != Color(0, 0, 0, 0)) {
+ if (rtl) {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, i * 3, cache.minimap_width, 2), line_background_color);
+ } else {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), line_background_color);
+ }
}
Color previous_color;
@@ -1048,11 +1055,11 @@ void TextEdit::_notification(int p_what) {
break;
}
- if (text.is_marked(line)) {
+ if (text.get_line_background_color(line) != Color(0, 0, 0, 0)) {
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end - xmargin_beg, row_height), cache.mark_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end - xmargin_beg, row_height), text.get_line_background_color(line));
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, row_height), cache.mark_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, row_height), text.get_line_background_color(line));
}
}
@@ -4789,7 +4796,6 @@ void TextEdit::_update_caches() {
cache.font_selected_color = get_theme_color("font_selected_color");
cache.font_readonly_color = get_theme_color("font_readonly_color");
cache.selection_color = get_theme_color("selection_color");
- cache.mark_color = get_theme_color("mark_color");
cache.current_line_color = get_theme_color("current_line_color");
cache.line_length_guideline_color = get_theme_color("line_length_guideline_color");
cache.code_folding_color = get_theme_color("code_folding_color");
@@ -5019,6 +5025,18 @@ bool TextEdit::is_line_gutter_clickable(int p_line, int p_gutter) const {
return text.is_line_gutter_clickable(p_line, p_gutter);
}
+// Line style
+void TextEdit::set_line_background_color(int p_line, const Color &p_color) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ text.set_line_background_color(p_line, p_color);
+ update();
+}
+
+Color TextEdit::get_line_background_color(int p_line) {
+ ERR_FAIL_INDEX_V(p_line, text.size(), Color());
+ return text.get_line_background_color(p_line);
+}
+
void TextEdit::add_keyword(const String &p_keyword) {
keywords.insert(p_keyword);
}
@@ -5437,12 +5455,6 @@ void TextEdit::_text_changed_emit() {
text_changed_dirty = false;
}
-void TextEdit::set_line_as_marked(int p_line, bool p_marked) {
- ERR_FAIL_INDEX(p_line, text.size());
- text.set_marked(p_line, p_marked);
- update();
-}
-
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
ERR_FAIL_INDEX(p_line, text.size());
if (is_hiding_enabled() || !p_hidden) {
@@ -6980,6 +6992,10 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_line_gutter_clickable", "line", "gutter", "clickable"), &TextEdit::set_line_gutter_clickable);
ClassDB::bind_method(D_METHOD("is_line_gutter_clickable", "line", "gutter"), &TextEdit::is_line_gutter_clickable);
+ // Line style
+ ClassDB::bind_method(D_METHOD("set_line_background_color", "line", "color"), &TextEdit::set_line_background_color);
+ ClassDB::bind_method(D_METHOD("get_line_background_color", "line"), &TextEdit::get_line_background_color);
+
ClassDB::bind_method(D_METHOD("set_highlight_current_line", "enabled"), &TextEdit::set_highlight_current_line);
ClassDB::bind_method(D_METHOD("is_highlight_current_line_enabled"), &TextEdit::is_highlight_current_line_enabled);
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index b0c7314c65..93214a5197 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -92,7 +92,7 @@ private:
Vector<Vector2i> bidi_override;
Ref<TextParagraph> data_buf;
- bool marked = false;
+ Color background_color = Color(0, 0, 0, 0);
bool hidden = false;
Line() {
@@ -129,12 +129,11 @@ private:
void set_width(float p_width);
int get_line_wrap_amount(int p_line) const;
+
Vector<Vector2i> get_line_wrap_ranges(int p_line) const;
const Ref<TextParagraph> get_line_data(int p_line) const;
void set(int p_line, const String &p_text, const Vector<Vector2i> &p_bidi_override);
- void set_marked(int p_line, bool p_marked) { text.write[p_line].marked = p_marked; }
- bool is_marked(int p_line) const { return text[p_line].marked; }
void set_hidden(int p_line, bool p_hidden) { text.write[p_line].hidden = p_hidden; }
bool is_hidden(int p_line) const { return text[p_line].hidden; }
void insert(int p_at, const String &p_text, const Vector<Vector2i> &p_bidi_override);
@@ -167,6 +166,10 @@ private:
void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable) { text.write[p_line].gutters.write[p_gutter].clickable = p_clickable; }
bool is_line_gutter_clickable(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].clickable; }
+
+ /* Line style. */
+ void set_line_background_color(int p_line, const Color &p_color) { text.write[p_line].background_color = p_color; }
+ const Color get_line_background_color(int p_line) const { return text[p_line].background_color; }
};
struct Cursor {
@@ -484,7 +487,6 @@ protected:
Color font_selected_color;
Color font_readonly_color;
Color selection_color;
- Color mark_color;
Color code_folding_color;
Color current_line_color;
Color line_length_guideline_color;
@@ -561,6 +563,10 @@ public:
void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable);
bool is_line_gutter_clickable(int p_line, int p_gutter) const;
+ // Line style
+ void set_line_background_color(int p_line, const Color &p_color);
+ Color get_line_background_color(int p_line);
+
enum MenuItems {
MENU_CUT,
MENU_COPY,
@@ -637,7 +643,6 @@ public:
void insert_text_at_cursor(const String &p_text);
void insert_at(const String &p_text, int at);
int get_line_count() const;
- void set_line_as_marked(int p_line, bool p_marked);
void set_line_as_hidden(int p_line, bool p_hidden);
bool is_line_hidden(int p_line) const;