Skip to content

Commit f352560

Browse files
committed
Fix various issues regarding the responsive UI
- Instead of `DisplayServer.window_set_min_size` the project now uses `get_window().min_size = ...` everywhere (as the docs recommend). - Overlay components are now checked for two meta property `x_padding` and `y_padding` which can be used to increase the minimum size of the window in cases where the component is bigger than the previous min. - Each component `item_rect_changed` signal is now connected to the new `_update_min_size` function when opened, which ensures that the window will always big enough to contain the entire component. - A label in the settings panel uses auto-wrapping, which currently leads to issues when the label has no custom_minimum_size, see: godotengine/godot#83546 I opted for an alternative fix (as proposed by nathanfranke in the issue linked above) which involves setting the anchors and offset of the label to the TOP_WIDE preset.
1 parent 8eb2001 commit f352560

File tree

8 files changed

+41
-12
lines changed

8 files changed

+41
-12
lines changed

entry_point/entry_point.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func _ready() -> void:
1717
change_to_main_scene.call_deferred()
1818
return
1919

20-
DisplayServer.window_set_min_size(size)
20+
get_window().min_size = size
2121

2222
%Path.text = Settings.store_path
2323
%BrowseFiles.grab_focus()

main_window/main_window.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ func _ready() -> void:
1414
if Engine.is_editor_hint():
1515
return
1616

17-
DisplayServer.window_set_min_size(Vector2i(
17+
get_window().min_size = Vector2i(
1818
# FIXME: get rid of those hardcoded values
1919
2 * 28 + 2 * 16 + 160, 2 * minimum_vertical_margin + 79 + 5 * 40
20-
))
20+
)
2121
get_tree().get_root().size_changed.connect(_on_window_size_changed)
2222

2323

main_window/overlay/calendar_widget/calendar_widget.gd

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func update_month() -> void:
1818

1919
# remove old children
2020
for child in $VBox/GridContainer.get_children():
21-
child.queue_free()
21+
# This *must* be free, not queue_free! Otherwise, it will blow up the vertical size of the
22+
# panel since it's not fast enough and old and new nodes briefly co-exist.
23+
child.free()
2224

2325
# add new children
2426
for day_name in Date._DAY_NAMES:
@@ -76,3 +78,8 @@ func _on_today_pressed() -> void:
7678
func _on_next_month_pressed() -> void:
7779
anchor_date = anchor_date.add_months(1)
7880
update_month()
81+
82+
83+
func _on_item_rect_changed() -> void:
84+
set_meta("x_padding", 2 * abs(offset_right))
85+
set_meta("y_padding", 18 + offset_top)

main_window/overlay/calendar_widget/calendar_widget.tscn

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ text = "Next Month"
6666
layout_mode = 2
6767
columns = 7
6868

69+
[connection signal="item_rect_changed" from="." to="." method="_on_item_rect_changed"]
6970
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
7071
[connection signal="pressed" from="VBox/HBox/PreviousMonth" to="." method="_on_previous_month_pressed"]
7172
[connection signal="pressed" from="VBox/HBox/Today" to="." method="_on_today_pressed"]

main_window/overlay/overlay.gd

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,34 @@ func _ready() -> void:
1010
EventBus.settings_button_pressed.connect(open_component.bind($SettingsPanel, true))
1111

1212

13-
func open_component(component : Node, dimmed_background : bool) -> void:
13+
func open_component(component : Control, dimmed_background : bool) -> void:
1414
$Background.color.a = 0.7 if dimmed_background else 0.0
1515

1616
self.show()
1717
component.show()
1818

1919
_previous_min_size = DisplayServer.window_get_min_size()
20-
DisplayServer.window_set_min_size(Vector2i(
21-
max(component.size.x, _previous_min_size.x),
22-
max(component.size.y, _previous_min_size.y)
23-
))
20+
21+
component.item_rect_changed.connect(_update_min_size.bind(component))
22+
_update_min_size(component)
23+
24+
25+
func _update_min_size(component : Control) -> void:
26+
get_window().min_size = Vector2i(
27+
max(component.size.x + component.get_meta("x_padding", 0), _previous_min_size.x),
28+
max(component.size.y + component.get_meta("y_padding", 0), _previous_min_size.y)
29+
)
2430

2531

2632
func close_overlay() -> void:
2733
self.hide()
28-
$CalendarWidget.hide()
29-
$SettingsPanel.hide()
34+
for component in [$CalendarWidget, $SettingsPanel]:
35+
component.hide()
36+
if component.item_rect_changed.is_connected(_update_min_size):
37+
component.item_rect_changed.disconnect(_update_min_size)
3038

3139
# FIXME: re-triggering the min_size calculation of the MainWindow would probably be cleaner
32-
DisplayServer.window_set_min_size(_previous_min_size)
40+
get_window().min_size = _previous_min_size
3341
_previous_min_size = Vector2i.ZERO
3442

3543

main_window/overlay/overlay.tscn

+4
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ visible = false
2020

2121
[node name="SettingsPanel" parent="." instance=ExtResource("2_qeh0g")]
2222
visible = false
23+
offset_left = -306.5
24+
offset_top = -150.5
25+
offset_right = 306.5
26+
offset_bottom = 150.5
2327

2428
[connection signal="gui_input" from="Background" to="." method="_on_dimmed_background_gui_input"]

main_window/overlay/settings_panel/settings_panel.gd

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
extends PanelContainer
22

33

4+
func _enter_tree() -> void:
5+
# See: https://github.com/godotengine/godot/issues/83546#issuecomment-1856927502
6+
# Without this line (or a custom_minimum_size for the label), the autowrapping will blow up the
7+
# vertical size of the panel. This can (as of now) only be done via code, not in the editor.
8+
$VBox/VBox1/Explanation.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
9+
10+
411
func _on_visibility_changed() -> void:
512
if visible:
613
%StorePath/Path.text = Settings.store_path

main_window/overlay/settings_panel/settings_panel.tscn

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ offset_bottom = 20.0
1515
grow_horizontal = 2
1616
grow_vertical = 2
1717
script = ExtResource("1_yrmyc")
18+
metadata/x_padding = 64
19+
metadata/y_padding = 64
1820

1921
[node name="VBox" type="VBoxContainer" parent="."]
2022
layout_mode = 2

0 commit comments

Comments
 (0)