# Copyright 2025 greenpixels # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and # associated documentation files (the “Software”), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial # portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT # LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. extends Node ## Easy Font Size Scaler by greenpixels # Intercepts every control that enters the tree, adds meta information about its font size and # then connects it to the _font_scale_changed event # # Should cover most use cases, but if you wanted to scale e.g # `bold_font_size` of RichTextLabel then you'd need to extend the logic here #region INTERNAL API signal _font_scale_changed(scale: float) var _current_font_scale : float = 1. func _enter_tree() -> void: get_tree().node_added.connect(func(node: Node) -> void: if not "get_theme_font_size" in node: return var original_font_size : int = node.get_theme_font_size("font_size" if not node is RichTextLabel else "normal_font_size") node.set_meta("original_font_size", original_font_size) # Create a callback event specific to that node var on_font_scale_change: Callable = func(scale: float) -> void: if not is_instance_valid(node): return var original_size : float = node.get_meta("original_font_size") if original_size == null: original_size = node.get_theme_font_size("font_size" if not node is RichTextLabel else "normal_font_size") node.add_theme_font_size_override("font_size" if not node is RichTextLabel else "normal_font_size", original_size * scale) _font_scale_changed.connect(on_font_scale_change) # Set the intial scale for that node on_font_scale_change.call(_current_font_scale) node.tree_exited.connect( func() -> void: if _font_scale_changed.is_connected(on_font_scale_change): _font_scale_changed.disconnect(on_font_scale_change), CONNECT_ONE_SHOT) ) #endregion #region PUBLIC API func set_font_scale(scale : float) -> void: _current_font_scale = scale _font_scale_changed.emit(_current_font_scale) #endregion
or share this direct link: