Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion examples/layouts/layouts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/silky/contexts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
Loading