浏览代码

Add padding options in theme for fg/bgcolor tags

golfinq 3 年之前
父节点
当前提交
b341339415
共有 3 个文件被更改,包括 15 次插入4 次删除
  1. 6 0
      doc/classes/RichTextLabel.xml
  2. 6 4
      scene/gui/rich_text_label.cpp
  3. 3 0
      scene/resources/default_theme/default_theme.cpp

+ 6 - 0
doc/classes/RichTextLabel.xml

@@ -666,6 +666,12 @@
 		<theme_item name="table_v_separation" data_type="constant" type="int" default="3">
 		<theme_item name="table_v_separation" data_type="constant" type="int" default="3">
 			The vertical separation of elements in a table.
 			The vertical separation of elements in a table.
 		</theme_item>
 		</theme_item>
+		<theme_item name="text_highlight_h_padding" data_type="constant" type="int" default="3">
+			The horizontal padding around a highlighting and background color box.
+		</theme_item>
+		<theme_item name="text_highlight_v_padding" data_type="constant" type="int" default="3">
+			The vertical padding around a highlighting and background color box.
+		</theme_item>
 		<theme_item name="bold_font" data_type="font" type="Font">
 		<theme_item name="bold_font" data_type="font" type="Font">
 			The font used for bold text.
 			The font used for bold text.
 		</theme_item>
 		</theme_item>

+ 6 - 4
scene/gui/rich_text_label.cpp

@@ -5386,6 +5386,8 @@ void RichTextLabel::_draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item
 	Vector2i fbg_index = Vector2i(end, start);
 	Vector2i fbg_index = Vector2i(end, start);
 	Color last_color = Color(0, 0, 0, 0);
 	Color last_color = Color(0, 0, 0, 0);
 	bool draw_box = false;
 	bool draw_box = false;
+	int hpad = get_theme_constant(SNAME("text_highlight_h_padding"));
+	int vpad = get_theme_constant(SNAME("text_highlight_v_padding"));
 	// Draw a box based on color tags associated with glyphs
 	// Draw a box based on color tags associated with glyphs
 	for (int i = start; i < end; i++) {
 	for (int i = start; i < end; i++) {
 		Item *it = _get_item_at_pos(it_from, it_to, i);
 		Item *it = _get_item_at_pos(it_from, it_to, i);
@@ -5415,8 +5417,8 @@ void RichTextLabel::_draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item
 		if (draw_box) {
 		if (draw_box) {
 			Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, fbg_index.y);
 			Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, fbg_index.y);
 			for (int j = 0; j < sel.size(); j++) {
 			for (int j = 0; j < sel.size(); j++) {
-				Vector2 rect_off = line_off + Vector2(sel[j].x, -TS->shaped_text_get_ascent(p_rid));
-				Vector2 rect_size = Vector2(sel[j].y - sel[j].x, TS->shaped_text_get_size(p_rid).y);
+				Vector2 rect_off = line_off + Vector2(sel[j].x - hpad, -TS->shaped_text_get_ascent(p_rid) - vpad);
+				Vector2 rect_size = Vector2(sel[j].y - sel[j].x + 2 * hpad, TS->shaped_text_get_size(p_rid).y + 2 * vpad);
 				RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color);
 				RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color);
 			}
 			}
 			fbg_index = Vector2i(end, start);
 			fbg_index = Vector2i(end, start);
@@ -5434,8 +5436,8 @@ void RichTextLabel::_draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item
 	if (last_color.a > 0) {
 	if (last_color.a > 0) {
 		Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, end);
 		Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, end);
 		for (int i = 0; i < sel.size(); i++) {
 		for (int i = 0; i < sel.size(); i++) {
-			Vector2 rect_off = line_off + Vector2(sel[i].x, -TS->shaped_text_get_ascent(p_rid));
-			Vector2 rect_size = Vector2(sel[i].y - sel[i].x, TS->shaped_text_get_size(p_rid).y);
+			Vector2 rect_off = line_off + Vector2(sel[i].x - hpad, -TS->shaped_text_get_ascent(p_rid) - vpad);
+			Vector2 rect_size = Vector2(sel[i].y - sel[i].x + 2 * hpad, TS->shaped_text_get_size(p_rid).y + 2 * vpad);
 			RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color);
 			RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color);
 		}
 		}
 	}
 	}

+ 3 - 0
scene/resources/default_theme/default_theme.cpp

@@ -965,6 +965,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
 	theme->set_color("table_even_row_bg", "RichTextLabel", Color(0, 0, 0, 0));
 	theme->set_color("table_even_row_bg", "RichTextLabel", Color(0, 0, 0, 0));
 	theme->set_color("table_border", "RichTextLabel", Color(0, 0, 0, 0));
 	theme->set_color("table_border", "RichTextLabel", Color(0, 0, 0, 0));
 
 
+	theme->set_constant("text_highlight_h_padding", "RichTextLabel", 3 * scale);
+	theme->set_constant("text_highlight_v_padding", "RichTextLabel", 3 * scale);
+
 	// Containers
 	// Containers
 
 
 	theme->set_icon("grabber", "VSplitContainer", icons["vsplitter"]);
 	theme->set_icon("grabber", "VSplitContainer", icons["vsplitter"]);