Skip to content

Commit fdd5c91

Browse files
committed
better auto scroll and background alpha setting
1 parent 5e80a86 commit fdd5c91

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class DebugLogger(
3636
) {
3737
private val logs = LinkedList<LogEntry>()
3838

39+
private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log")
3940
private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long")
4041
private val showDebug by setting("Show Debug", true, "Shows debug logs")
4142
private val showSuccess by setting("Show Success", true, "Shows success logs")
@@ -49,6 +50,7 @@ abstract class DebugLogger(
4950
}
5051
}
5152
}
53+
private val backgroundAlpha by setting("Background Alpha", 0.3f, 0f..1f, 0.01f, "Sets the opacity for the elements background")
5254

5355
private fun log(message: String, logColor: LogType) {
5456
logs.add(LogEntry(message, logColor))
@@ -64,8 +66,10 @@ abstract class DebugLogger(
6466

6567
override fun ImGuiBuilder.buildLayout() {
6668
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
69+
ImGui.setNextWindowBgAlpha(backgroundAlpha)
6770
window(name, flags = ImGuiWindowFlags.NoTitleBar) {
68-
child("Log Content") {
71+
val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
72+
child("Log Content", extraFlags = noScroll) {
6973
if (wrapText) ImGui.pushTextWrapPos()
7074

7175
logs.forEach { logEntry ->
@@ -83,6 +87,10 @@ abstract class DebugLogger(
8387
}
8488

8589
if (wrapText) ImGui.popTextWrapPos()
90+
91+
if (autoScroll) {
92+
ImGui.setScrollHereY(1f)
93+
}
8694
}
8795
button("Clear") { clear() }
8896
}

0 commit comments

Comments
 (0)