From 1c2f2f2e766d783a6772a9dcaddffb62209073ad Mon Sep 17 00:00:00 2001 From: Row Date: Mon, 4 May 2026 12:38:47 -0300 Subject: [PATCH] Reset warm/hot state on interaction. --- examples/layouts/layouts.nim | 23 ++++++++++++++++++++++- src/silky/contexts.nim | 12 ++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/examples/layouts/layouts.nim b/examples/layouts/layouts.nim index 87e324f..4b8e38a 100644 --- a/examples/layouts/layouts.nim +++ b/examples/layouts/layouts.nim @@ -24,6 +24,9 @@ var showOverlapWindow = true behindClicked = false inFrontClicked = false + foldout1Open = false + foldout2Open = false + foldout3Open = false window.onFrame = proc() = sk.beginUI(window, window.size) @@ -34,7 +37,7 @@ window.onFrame = proc() = sk.at = vec2(x.float32 * 256, y.float32 * 256) image("testTexture", rgbx(30, 30, 30, 255)) - subWindow("Layouts", showOverlapWindow, vec2(520, 100), vec2(250, 200)): + subWindow("Layouts", showOverlapWindow, vec2(200, 100), vec2(250, 400)): text("Two overlapping buttons:") var clicked = false @@ -50,6 +53,24 @@ window.onFrame = proc() = inFrontClicked = clicked + button(if foldout1Open: "- Section A" else: "+ Section A"): + foldout1Open = not foldout1Open + if foldout1Open: + text(" Content of section A") + text(" More content here") + + button(if foldout2Open: "- Section B" else: "+ Section B"): + foldout2Open = not foldout2Open + if foldout2Open: + text(" Section B item 1") + text(" Section B item 2") + text(" Section B item 3") + + button(if foldout3Open: "- Section C" else: "+ Section C"): + foldout3Open = not foldout3Open + if foldout3Open: + text(" Section C content") + if not showOverlapWindow: if window.buttonPressed[MouseLeft]: showOverlapWindow = true diff --git a/src/silky/contexts.nim b/src/silky/contexts.nim index 9ae52a4..fe35a91 100644 --- a/src/silky/contexts.nim +++ b/src/silky/contexts.nim @@ -238,6 +238,12 @@ proc shouldShowTooltip*(sk: Silky): bool = ## Returns true when a tooltip should be shown. sk.hover and sk.mouseIdleTime >= sk.tooltipThreshold +proc resetInteractions*(sk: Silky) = + ## Clear all interaction state. + sk.interactor.hotId = -1 + sk.interactor.warmId = -1 + sk.interactor.warmLayer = -1 + proc beginUiShared*(sk: Silky, window: Window, size: IVec2) = ## Starts a frame and updates the shared UI state. when defined(profile): @@ -284,12 +290,10 @@ proc endInteractions(interactor: var Interactor) = interactor.warmLayer = -1 interactor.currentId = -1 -proc resetInteractions*(sk: Silky) = - ## Clear all interaction state. - sk.interactor.hotId = -1 - proc endUiShared*(sk: Silky) = ## Ends a frame after the backend has finished drawing. + if sk.window.buttonReleased[MouseLeft]: + sk.resetInteractions() sk.interactor.endInteractions() sk.clear() sk.popLayout()