diff --git a/docs/docs/reference/modules/config.md b/docs/docs/reference/modules/config.md index f089209..1b79ab1 100644 --- a/docs/docs/reference/modules/config.md +++ b/docs/docs/reference/modules/config.md @@ -51,6 +51,8 @@ Enables or disables Log UI. The Log UI background color.. Set to `Color.TRANSPARENT` for a transparent background. ### *int* logui_font_size = *14* What font size the graphical log should have. +### *int* logui_max_lines = *100* +How many lines can be visible on the screen at any given time. **Never** set this higher than 100 or it will cause tremendous amounts of lag for no real benefit. Instead *lowering* that amount helps performance. ## Miscellaneous ### *bool* misc_stringify_show_type = *false* diff --git a/src/classes/config.gd b/src/classes/config.gd index e8143fe..6dfd198 100644 --- a/src/classes/config.gd +++ b/src/classes/config.gd @@ -46,6 +46,8 @@ class_name CoreConfiguration @export var logui_background_color: Color ## What font size the graphical log should have. @export var logui_font_size: int +## How many lines can be visible on the screen at any given time. [b]Never[/b] set this higher than 100 or it will cause tremendous amounts of lag for no real benefit. Instead [i]lowering[/i] that amount helps performance. +@export var logui_max_lines: int @export_category("Miscellaneous") ## Shows or hides the type when calling [code]stringify_variables[/code]. @@ -83,6 +85,7 @@ func _init() -> void: logui_enabled = true logui_background_color = Color.BLACK # To disable the background, use Color.TRANSPARENT logui_font_size = 14 + logui_max_lines = 100 # Misc misc_stringify_show_type = false diff --git a/src/logui.gd b/src/logui.gd index edc872e..f187f36 100644 --- a/src/logui.gd +++ b/src/logui.gd @@ -28,12 +28,21 @@ var logrtl: RichTextLabel var font_normal: Font var font_bold: Font +# Configuration +var config_max_lines: int + # +++ module +++ func _pull_config() -> void: - background.visible = !core.config.headless and core.config.logui_enabled + if !core.config.logui_enabled: + background.visible = false + logrtl.text = "" + else: + background.visible = !core.config.headless background.color = core.config.logui_background_color logrtl.add_theme_font_size_override("normal_font_size", core.config.logui_font_size) logrtl.add_theme_font_size_override("bold_font_size", core.config.logui_font_size) + + config_max_lines = core.config.logui_max_lines func _cleanup() -> void: background.remove_child(logrtl) @@ -90,7 +99,9 @@ func _ready() -> void: vsbar.add_theme_stylebox_override("grabber_pressed", StyleBoxEmpty.new()) # Connect log_event - core.logger.connect("log_event", func(allowed: bool, _level: CoreTypes.LoggerLevel, _origin: String, _message: String, format: String) -> void: if allowed: logrtl.text = logrtl.text + format + "\n") + core.logger.connect("log_event", func(allowed: bool, _level: CoreTypes.LoggerLevel, _origin: String, _message: String, format: String) -> void: + if allowed and core.config.logui_enabled: logrtl.text = logrtl.text + format + "\n" + ) # +++ process +++ func _process(_delta: float) -> void: @@ -98,3 +109,18 @@ func _process(_delta: float) -> void: var window_size: Vector2i = DisplayServer.window_get_size() background.size = window_size logrtl.size = window_size + + var stripped_text: String = "" + if logrtl.text.count("\n") > config_max_lines: + printerr("Stripping text") + var lines: PackedStringArray = logrtl.text.split("\n") + + var index: int = 0 + for line in lines: + if index >= lines.size()-config_max_lines: + if stripped_text == "": stripped_text = line + else: stripped_text += "\n" + line + + index += 1 + + logrtl.text = stripped_text