From 0c1e445a953dc8dd5443dbd4c2339969e824c00e Mon Sep 17 00:00:00 2001 From: downthecrop Date: Fri, 21 Nov 2025 17:05:40 -0800 Subject: [PATCH] Edge snap fix --- .../src/main/kotlin/KondoKit/.DS_Store | Bin 6148 -> 6148 bytes .../src/main/kotlin/KondoKit/plugin.kt | 103 +++++++++++------- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/plugin-playground/src/main/kotlin/KondoKit/.DS_Store b/plugin-playground/src/main/kotlin/KondoKit/.DS_Store index a55bac8f7f79314d3eab1a194be16626c5431052..4caffeadb00587b54a4eb88e40717f76b32117d9 100644 GIT binary patch delta 87 zcmZoMXfc=|#>B)qu~2NHo}wr#0|Nsi1A_nqLncEWgC0XRLy2e3#=_-{jI5Jiuw38F o&-R0HV}lO!W_AvK4xqNpf*jwOC-aLqasV}gbh2!Y5Lv?v0BZOXod5s; delta 371 zcmaiwziPrz6vltKDHwwI2UNN^_yWOKNL}h&2d9Fjsgy=zP3qdk&86Z)xCjn;6`_yf zsGpsJ3f{{-TsY@W)h=m#zVF=M8x6GFX|jGjp3FY+&AaZ|LdaWg`wchjvb`yotl*R#MXJ~i_PSj2 N9VKccM%J%w?GwIVSTO(q diff --git a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt index 08fec9f..b0b03b9 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt @@ -320,52 +320,77 @@ class plugin : Plugin() { } private fun updateDisplaySettings() { - val mode = GetWindowMode() - val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH - lastUIOffset = uiOffset + val applyDisplaySettings = { + val mode = GetWindowMode() + val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH + lastUIOffset = uiOffset - if(mode != WindowMode.FIXED) { - destroyAltCanvas() - } else if (useScaledFixed && altCanvas == null) { - initAltCanvas() - } else if (!useScaledFixed && altCanvas != null) { - // Was using scaled fixed but toggled the setting - // restore the original canvas - moveCanvasToFront() - destroyAltCanvas() - } - - when (mode) { - WindowMode.FIXED -> { - if (frame.width < FIXED_WIDTH + currentScrollPaneWidth + uiOffset) { - frame.setSize(FIXED_WIDTH + currentScrollPaneWidth + uiOffset, frame.height) - } - - val difference = frame.width - (uiOffset + currentScrollPaneWidth) - - if (useScaledFixed) { - GameShell.leftMargin = 0 - val canvasWidth = difference + uiOffset / 2 - val canvasHeight = frame.height - canvas.y // Restricting height to frame height - - altCanvas?.size = Dimension(canvasWidth, canvasHeight) - altCanvas?.setLocation(0, canvas.y) - canvas.setLocation(0, canvas.y) - } else { - val difference = frame.width - (FIXED_WIDTH + uiOffset + currentScrollPaneWidth) - GameShell.leftMargin = difference / 2 + // Ensure the scroll wrapper stays attached on the EAST edge even if the game resets the layout + rightPanelWrapper?.let { wrapper -> + val needsLayoutReset = frame.layout !is BorderLayout + val needsAttach = wrapper.parent != frame + if (needsLayoutReset || needsAttach) { + wrapper.parent?.remove(wrapper) + frame.layout = BorderLayout() + frame.add(wrapper, BorderLayout.EAST) + if (altCanvas != null) { + moveAltCanvasToFront() + } else { + moveCanvasToFront() + } } } - WindowMode.RESIZABLE -> { - GameShell.canvasWidth = frame.width - (currentScrollPaneWidth + uiOffset) + if(mode != WindowMode.FIXED) { + destroyAltCanvas() + } else if (useScaledFixed && altCanvas == null) { + initAltCanvas() + } else if (!useScaledFixed && altCanvas != null) { + // Was using scaled fixed but toggled the setting + // restore the original canvas + moveCanvasToFront() + destroyAltCanvas() } + + when (mode) { + WindowMode.FIXED -> { + if (frame.width < FIXED_WIDTH + currentScrollPaneWidth + uiOffset) { + frame.setSize(FIXED_WIDTH + currentScrollPaneWidth + uiOffset, frame.height) + } + + val difference = frame.width - (uiOffset + currentScrollPaneWidth) + + if (useScaledFixed) { + GameShell.leftMargin = 0 + val canvasWidth = difference + uiOffset / 2 + val canvasHeight = frame.height - canvas.y // Restricting height to frame height + + altCanvas?.size = Dimension(canvasWidth, canvasHeight) + altCanvas?.setLocation(0, canvas.y) + canvas.setLocation(0, canvas.y) + } else { + val difference = frame.width - (FIXED_WIDTH + uiOffset + currentScrollPaneWidth) + GameShell.leftMargin = difference / 2 + } + } + + WindowMode.RESIZABLE -> { + GameShell.canvasWidth = frame.width - (currentScrollPaneWidth + uiOffset) + } + } + + rightPanelWrapper?.preferredSize = Dimension(currentScrollPaneWidth, frame.height) + rightPanelWrapper?.isDoubleBuffered = true + rightPanelWrapper?.revalidate() + rightPanelWrapper?.repaint() + frame.validate() } - rightPanelWrapper?.preferredSize = Dimension(currentScrollPaneWidth, frame.height) - rightPanelWrapper?.isDoubleBuffered = true - rightPanelWrapper?.revalidate() - rightPanelWrapper?.repaint() + if (SwingUtilities.isEventDispatchThread()) { + applyDisplaySettings() + } else { + SwingUtilities.invokeLater { applyDisplaySettings() } + } } fun OnKondoValueUpdated(){