Skip to content

Commit af2c803

Browse files
committed
Render HUD arcs on correct y level and prevent moving elements off screen
1 parent efa9394 commit af2c803

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
207207
}
208208

209209
if (ClickGuiLayout.open && !isLocked) {
210-
drawHudCornerArcs(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
210+
drawHudCornerArcs(windowDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
211211
}
212212
val rect = RectF(windowPos.x, windowPos.y, windowSize.x, windowSize.y)
213213
SnapManager.registerElement(hud.name, rect)
@@ -262,8 +262,19 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
262262
val targetY = my - dragOffsetY
263263
val proposed = RectF(targetX, targetY, last.w, last.h)
264264
val snap = SnapManager.computeSnap(proposed, id)
265-
val finalX = targetX + snap.dx
266-
val finalY = targetY + snap.dy
265+
var finalX = targetX + snap.dx
266+
var finalY = targetY + snap.dy
267+
268+
// Clamp to viewport so the HUD cannot go off-screen
269+
val vp = ImGui.getMainViewport()
270+
val minX = vp.posX
271+
val minY = vp.posY
272+
val maxX = vp.posX + vp.sizeX - last.w
273+
val maxY = vp.posY + vp.sizeY - last.h
274+
275+
finalX = if (last.w >= vp.sizeX) minX else finalX.coerceIn(minX, maxX)
276+
finalY = if (last.h >= vp.sizeY) minY else finalY.coerceIn(minY, maxY)
277+
267278
pendingPositions[id] = finalX to finalY
268279
snapOverlays[id] = SnapVisual(snap.snapX, snap.snapY, snap.kindX, snap.kindY)
269280
}
@@ -299,22 +310,32 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
299310
val baseRadius = hudOutlineCornerRadius
300311
val rounding = if (baseRadius > 0f) baseRadius else style.windowRounding
301312
val inflate = hudOutlineCornerInflate
313+
314+
// Disable window clipping for these strokes while keeping window Z-order
315+
draw.pushClipRectFullScreen()
316+
317+
// Slightly grow the visual size so arcs feel bigger
318+
val haloRadius = (rounding + inflate + 0.5f * hudOutlineHaloThickness + 1.0f).coerceAtLeast(0f)
319+
val borderRadius = (rounding + 0.5f * hudOutlineBorderThickness + 0.75f).coerceAtLeast(0f)
320+
302321
// Soft halo corners
303322
drawCornerArcs(
304323
draw,
305324
x, y, w, h,
306-
(rounding + inflate).coerceAtLeast(0f),
325+
haloRadius,
307326
hudOutlineHaloColor.rgb,
308327
hudOutlineHaloThickness
309328
)
310329
// Crisp inner corner arcs
311330
drawCornerArcs(
312331
draw,
313332
x, y, w, h,
314-
rounding.coerceAtLeast(0f),
333+
borderRadius,
315334
hudOutlineBorderColor.rgb,
316335
hudOutlineBorderThickness
317336
)
337+
338+
draw.popClipRect()
318339
}
319340

320341
private fun drawCornerArcs(

0 commit comments

Comments
 (0)