Skip to content

Commit 4e6f5f3

Browse files
committed
Merge pull request godotengine#107305 from timothyqiu/single-window-title
Fix window title drawn outside the title bar
2 parents b3cc930 + f028bc9 commit 4e6f5f3

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

doc/classes/TextServer.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@
14001400
<param index="6" name="oversampling" type="float" default="0.0" />
14011401
<description>
14021402
Draw shaped text into a canvas item at a given position, with [param color]. [param pos] specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout). If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
1403+
[param clip_l] and [param clip_r] are offsets relative to [param pos], going to the right in horizontal layout and downward in vertical layout. If [param clip_l] is not negative, glyphs starting before the offset are clipped. If [param clip_r] is not negative, glyphs ending after the offset are clipped.
14031404
</description>
14041405
</method>
14051406
<method name="shaped_text_draw_outline" qualifiers="const">
@@ -1414,6 +1415,7 @@
14141415
<param index="7" name="oversampling" type="float" default="0.0" />
14151416
<description>
14161417
Draw the outline of the shaped text into a canvas item at a given position, with [param color]. [param pos] specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout). If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
1418+
[param clip_l] and [param clip_r] are offsets relative to [param pos], going to the right in horizontal layout and downward in vertical layout. If [param clip_l] is not negative, glyphs starting before the offset are clipped. If [param clip_r] is not negative, glyphs ending after the offset are clipped.
14171419
</description>
14181420
</method>
14191421
<method name="shaped_text_fit_to_width">

doc/classes/Window.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,10 +997,10 @@
997997
The color of the title's text outline.
998998
</theme_item>
999999
<theme_item name="close_h_offset" data_type="constant" type="int" default="18">
1000-
Horizontal position offset of the close button.
1000+
Horizontal position offset of the close button, relative to the end of the title bar, towards the beginning of the title bar.
10011001
</theme_item>
10021002
<theme_item name="close_v_offset" data_type="constant" type="int" default="24">
1003-
Vertical position offset of the close button.
1003+
Vertical position offset of the close button, relative to the bottom of the title bar, towards the top of the title bar.
10041004
</theme_item>
10051005
<theme_item name="resize_margin" data_type="constant" type="int" default="4">
10061006
Defines the outside margin at which the window border can be grabbed with mouse and resized.

scene/main/viewport.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void Viewport::_sub_window_update(Window *p_window) {
337337
sw.pending_window_update = false;
338338

339339
RS::get_singleton()->canvas_item_clear(sw.canvas_item);
340-
Rect2i r = Rect2i(p_window->get_position(), p_window->get_size());
340+
const Rect2i r = Rect2i(p_window->get_position(), p_window->get_size());
341341

342342
if (!p_window->get_flag(Window::FLAG_BORDERLESS)) {
343343
Ref<StyleBox> panel = gui.subwindow_focused == p_window ? p_window->theme_cache.embedded_border : p_window->theme_cache.embedded_unfocused_border;
@@ -351,18 +351,21 @@ void Viewport::_sub_window_update(Window *p_window) {
351351
int close_h_ofs = p_window->theme_cache.close_h_offset;
352352
int close_v_ofs = p_window->theme_cache.close_v_offset;
353353

354-
TextLine title_text = TextLine(p_window->get_translated_title(), title_font, font_size);
355-
title_text.set_width(r.size.width - panel->get_minimum_size().x - close_h_ofs);
356-
title_text.set_direction(p_window->is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
357-
int x = (r.size.width - title_text.get_size().x) / 2;
358-
int y = (-title_height - title_text.get_size().y) / 2;
359-
360-
Color font_outline_color = p_window->theme_cache.title_outline_modulate;
361-
int outline_size = p_window->theme_cache.title_outline_size;
362-
if (outline_size > 0 && font_outline_color.a > 0) {
363-
title_text.draw_outline(sw.canvas_item, r.position + Point2(x, y), outline_size, font_outline_color);
354+
const real_t title_space = r.size.width - panel->get_minimum_size().x - close_h_ofs;
355+
if (title_space > 0) {
356+
TextLine title_text = TextLine(p_window->get_translated_title(), title_font, font_size);
357+
title_text.set_width(title_space);
358+
title_text.set_direction(p_window->is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
359+
int x = (r.size.width - title_text.get_size().x) / 2;
360+
int y = (-title_height - title_text.get_size().y) / 2;
361+
362+
Color font_outline_color = p_window->theme_cache.title_outline_modulate;
363+
int outline_size = p_window->theme_cache.title_outline_size;
364+
if (outline_size > 0 && font_outline_color.a > 0) {
365+
title_text.draw_outline(sw.canvas_item, r.position + Point2(x, y), outline_size, font_outline_color);
366+
}
367+
title_text.draw(sw.canvas_item, r.position + Point2(x, y), title_color);
364368
}
365-
title_text.draw(sw.canvas_item, r.position + Point2(x, y), title_color);
366369

367370
bool pressed = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
368371
Ref<Texture2D> close_icon = pressed ? p_window->theme_cache.close_pressed : p_window->theme_cache.close;

0 commit comments

Comments
 (0)