Skip to content

Commit

Permalink
Merge pull request godotengine#45922 from bruvzg/space_width
Browse files Browse the repository at this point in the history
Use get_char_size(' ') to calculate space width.
  • Loading branch information
akien-mga authored Feb 12, 2021
2 parents bc55238 + 6c9e608 commit 5e528f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ Size2 LineEdit::get_minimum_size() const {
Size2 min_size;

// Minimum size of text.
int space_size = font->get_char_size('m', 0, font_size).x;
int space_size = font->get_char_size(' ', 0, font_size).x;
min_size.width = get_theme_constant("minimum_spaces") * space_size;

if (expand_to_text_length) {
Expand Down
8 changes: 4 additions & 4 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>

if (tab_size > 0) { // Align inline tabs.
Vector<float> tabs;
tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width);
tabs.push_back(tab_size * p_base_font->get_char_size(' ', 0, p_base_font_size).width);
l.text_buf->tab_align(tabs);
}

Expand Down Expand Up @@ -392,7 +392,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>

if (tab_size > 0) { // Align inline tabs.
Vector<float> tabs;
tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width);
tabs.push_back(tab_size * p_base_font->get_char_size(' ', 0, p_base_font_size).width);
l.text_buf->tab_align(tabs);
}

Expand Down Expand Up @@ -1859,7 +1859,7 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int
if (font_size == -1) {
font_size = p_base_font_size;
}
margin += tab_size * font->get_char_size('m', 0, font_size).width;
margin += tab_size * font->get_char_size(' ', 0, font_size).width;

} else if (item->type == ITEM_LIST) {
Ref<Font> font = _find_font(item);
Expand All @@ -1870,7 +1870,7 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int
if (font_size == -1) {
font_size = p_base_font_size;
}
margin += tab_size * font->get_char_size('m', 0, font_size).width;
margin += tab_size * font->get_char_size(' ', 0, font_size).width;
}

item = item->parent;
Expand Down
6 changes: 3 additions & 3 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_
// Apply tab align.
if (indent_size > 0) {
Vector<float> tabs;
tabs.push_back(font->get_char_size('m', 0, font_size).width * indent_size);
tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size);
text.write[p_line].data_buf->tab_align(tabs);
}
}
Expand All @@ -212,7 +212,7 @@ void TextEdit::Text::invalidate_all_lines() {
text.write[i].data_buf->set_width(width);
if (indent_size > 0) {
Vector<float> tabs;
tabs.push_back(font->get_char_size('m', 0, font_size).width * indent_size);
tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size);
text.write[i].data_buf->tab_align(tabs);
}
}
Expand Down Expand Up @@ -1050,7 +1050,7 @@ void TextEdit::_notification(int p_what) {

// Give visual indication of empty selected line.
if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) {
int char_w = cache.font->get_char_size('m', 0, cache.font_size).width;
int char_w = cache.font->get_char_size(' ', 0, cache.font_size).width;
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), cache.selection_color);
} else {
Expand Down

0 comments on commit 5e528f3

Please sign in to comment.