Skip to content

Commit cbe18f4

Browse files
committed
Remove snap guides when hud is disabled
1 parent 3e8d215 commit cbe18f4

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ object HudGuiLayout : Loadable {
7878
pendingPositions.clear()
7979
snapOverlays.clear()
8080

81-
val huds = ModuleRegistry.modules
81+
val (huds, notShown) = ModuleRegistry.modules
8282
.filterIsInstance<HudModule>()
83-
.filter { it.isEnabled }
83+
.partition { it.isEnabled }
84+
85+
notShown.forEach { SnapManager.unregisterElement(it.name) }
8486

8587
if (ClickGui.isEnabled && activeDragHudName == null && mousePressedThisFrame) {
8688
tryBeginDrag(huds)
@@ -106,17 +108,9 @@ object HudGuiLayout : Loadable {
106108
}
107109
with(hud) { buildLayout() }
108110
if (ClickGui.isEnabled) {
109-
drawHudOutline(
110-
draw = foregroundDrawList,
111-
x = windowPos.x,
112-
y = windowPos.y,
113-
w = windowSize.x,
114-
h = windowSize.y
115-
)
111+
drawHudOutline(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
116112
}
117-
val p = windowPos
118-
val s = windowSize
119-
val rect = RectF(p.x, p.y, s.x, s.y)
113+
val rect = RectF(windowPos.x, windowPos.y, windowSize.x, windowSize.y)
120114
SnapManager.registerElement(hud.name, rect)
121115
lastBounds[hud.name] = rect
122116
}

src/main/kotlin/com/lambda/gui/snap/SnapManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ object SnapManager {
5151
elementRects[id] = rect
5252
}
5353

54+
fun unregisterElement(id: String) {
55+
elementRects.remove(id)
56+
}
57+
5458
private fun addElementGuides(sourceId: String, r: RectF) {
5559
if (snapEnabled && snapToEdges) {
5660
frameGuides += SnapGuide(Guide(Guide.Orientation.Vertical, r.left, 100, Guide.Kind.ElementEdge), sourceId)

0 commit comments

Comments
 (0)