Skip to content

Commit adb2ec0

Browse files
committed
Merge pull request #110303 from Unbansheee/master
Fix vertical alignment of Inspector category titles
2 parents 1a89648 + 47756c9 commit adb2ec0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

editor/inspector/editor_inspector.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,9 +1678,18 @@ void EditorInspectorCategory::_notification(int p_what) {
16781678
if (is_layout_rtl()) {
16791679
ofs = get_size().width - ofs - w;
16801680
}
1681-
float text_pos_y = font->get_ascent(font_size) + (get_size().height - font->get_height(font_size)) / 2 + v_margin_offset;
1681+
1682+
// Use TextLine so we have access to accurate font metrics. This way,
1683+
// we can ensure the line is vertically centered regardless of the font used
1684+
// or its size.
1685+
Ref<TextLine> tl;
1686+
tl.instantiate();
1687+
tl->add_string(label, font, font_size);
1688+
tl->set_width(w);
1689+
tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
1690+
float text_pos_y = (get_size().height - tl->get_size().height) / 2 + v_margin_offset;
16821691
Point2 text_pos = Point2(ofs, text_pos_y).round();
1683-
draw_string(font, text_pos, label, HORIZONTAL_ALIGNMENT_LEFT, w, font_size, theme_cache.font_color);
1692+
tl->draw(get_canvas_item(), text_pos, theme_cache.font_color);
16841693
} break;
16851694
}
16861695
}

0 commit comments

Comments
 (0)