aboutsummaryrefslogtreecommitdiff
path: root/client/gui/components/smart_margin_container.gd
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-04 23:47:24 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-05 23:07:07 +0200
commit81deaf81c800900e30046cb927be1c9d91ae61b8 (patch)
tree20ce9898465e8d4c49eeff12a9ea55572517ea7b /client/gui/components/smart_margin_container.gd
parentfd80142282fcef628466a18e3ea62f0d1372d807 (diff)
downloadhurrycurry-81deaf81c800900e30046cb927be1c9d91ae61b8.tar
hurrycurry-81deaf81c800900e30046cb927be1c9d91ae61b8.tar.bz2
hurrycurry-81deaf81c800900e30046cb927be1c9d91ae61b8.tar.zst
reorganize client gui files
Diffstat (limited to 'client/gui/components/smart_margin_container.gd')
-rw-r--r--client/gui/components/smart_margin_container.gd41
1 files changed, 41 insertions, 0 deletions
diff --git a/client/gui/components/smart_margin_container.gd b/client/gui/components/smart_margin_container.gd
new file mode 100644
index 00000000..046dc6f3
--- /dev/null
+++ b/client/gui/components/smart_margin_container.gd
@@ -0,0 +1,41 @@
+# Hurry Curry! - a game about cooking
+# Copyright (C) 2025 Hurry Curry! contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+extends MarginContainer
+class_name SmartMarginContainer
+# A smart margin container which automatically adjusts the margin such that it doesn't cover notch on phones
+
+func _ready() -> void:
+ var os := OS.get_name()
+ if os == "iOS" or os == "Android":
+ update_margins()
+
+func update_margins() -> void:
+ var screen_safe_rect := Rect2(DisplayServer.get_display_safe_area())
+ var viewport_transform := get_viewport().get_final_transform()
+ var viewport_safe_rect := screen_safe_rect * viewport_transform.affine_inverse()
+ var viewport_full_rect := get_viewport().get_visible_rect()
+ var left := viewport_safe_rect.position.x - viewport_full_rect.position.x
+ var top := viewport_safe_rect.position.y - viewport_full_rect.position.y
+ var right := viewport_full_rect.end.x - viewport_safe_rect.end.x
+ var bottom := viewport_full_rect.end.y - viewport_safe_rect.end.y
+ # print("OLD: ", get_theme_constant("margin_left"))
+ begin_bulk_theme_override()
+ add_theme_constant_override('margin_left', roundi(left) + get_theme_constant("margin_left"))
+ add_theme_constant_override('margin_top', roundi(top) + get_theme_constant("margin_top"))
+ add_theme_constant_override('margin_right', roundi(right) + get_theme_constant("margin_right"))
+ add_theme_constant_override('margin_bottom', roundi(bottom) + get_theme_constant("margin_bottom"))
+ end_bulk_theme_override()
+ # print("NEW: ", get_theme_constant("margin_left"))