Repository navigation
Handle quick clicks and keep dropdown menus inside the window #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
relh
wants to merge
4
commits into
treeform:master
Choose a base branch
from
relh:relh/coalesced-widget-clicks-20260909
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cedbf5c
Preserve clicks whose press and release arrive in one frame
relh 3b2207f
Merge remote-tracking branch 'origin/master' into relh/coalesced-widg…
relh 6c4ae95
Preserve completed clicks in press-driven widgets
relh 6efaa6c
Keep dropdown choices visible near window edges
relh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| ## Mouse event batches must not lose release activation between rendered frames. | ||
| ## Run with: nim r -d:silkyTesting tests/test_interactions.nim | ||
| import std/[options, tables] | ||
| import bumpy, silky, vmath | ||
|
|
||
| let window = newWindow(200, 200) | ||
| let sk = Silky(window: window) | ||
| let target = rect(20'f32, 20'f32, 100'f32, 40'f32) | ||
|
|
||
| proc sample(enabled = true): Interaction = | ||
| sk.beginUI(window, window.size) | ||
| result = sk.interact(target, enabled) | ||
| sk.endUi() | ||
| window.resetInputState() | ||
|
|
||
| window.moveMouse(50, 30) | ||
| discard sample() | ||
| doAssert sample() == Hovered | ||
| window.pressButton(MouseLeft) | ||
| doAssert sample() == Pressed | ||
| doAssert sample() == Held | ||
| window.releaseButton(MouseLeft) | ||
| doAssert sample() == Released | ||
| discard sample() | ||
|
|
||
| # A full click between two frames used to return Pressed and lose the release. | ||
| window.pressButton(MouseLeft) | ||
| window.releaseButton(MouseLeft) | ||
| doAssert sample() == Released | ||
| doAssert sample() == Hovered | ||
|
|
||
| window.pressButton(MouseLeft) | ||
| discard sample() | ||
| window.releaseButton(MouseLeft) | ||
| window.pressButton(MouseLeft) | ||
| doAssert sample() == Pressed | ||
| doAssert sample() == Held | ||
| window.releaseButton(MouseLeft) | ||
| doAssert sample() == Released | ||
| discard sample() | ||
|
|
||
| window.pressButton(MouseLeft) | ||
| window.releaseButton(MouseLeft) | ||
| doAssert sample(false) == Disabled | ||
|
|
||
| window.pressButton(MouseLeft) | ||
| window.moveMouse(190, 190) | ||
| window.releaseButton(MouseLeft) | ||
| doAssert sample() == ReleasedOutside | ||
| echo "Batched mouse interaction tests passed" | ||
|
|
||
| # Exercise the actual press-driven controls, using a small semantic atlas. | ||
| block: | ||
| let atlas = SilkyAtlas(size: 64) | ||
| for name in ["heart", "maximized", "minimized", "close", "scrubber.handle"]: | ||
| atlas.entries[name] = Entry(width: 16, height: 16) | ||
| let window = newWindow(240, 240) | ||
| let sk = newSilky(window, atlas) | ||
| var icons = 0 | ||
| var volume = 0'f32 | ||
| var show = true | ||
| var panel: SubWindowState | ||
| window.onFrame = proc() = | ||
| sk.beginUI(window, window.size) | ||
| sk.at = vec2(20, 20) | ||
| clickableIcon "heart", true: inc icons | ||
| sk.at = vec2(20, 60) | ||
| scrubber "batch-test", volume, 0'f32, 1'f32 | ||
| panel = sk.subWindowStart(window, "batch-window", show, | ||
| some(vec2(20, 120)), some(vec2(180, 100))) | ||
| sk.subWindowEnd(window, panel) | ||
| sk.endUi() | ||
|
|
||
| proc clickAt(x, y: int, completed: bool) = | ||
| window.moveMouse(x, y) | ||
| window.pumpFrame(sk) | ||
| window.pumpFrame(sk) | ||
| window.pressButton(MouseLeft) | ||
| if not completed: | ||
| window.pumpFrame(sk) | ||
| window.releaseButton(MouseLeft) | ||
| window.pumpFrame(sk) | ||
| window.pumpFrame(sk) | ||
|
|
||
| for completed in [false, true]: | ||
| let before = icons | ||
| clickAt(24, 24, completed) | ||
| doAssert icons == before + 1 | ||
| volume = 0 | ||
| clickAt(120, 64, completed) | ||
| doAssert volume > 0.3 and volume < 0.7 | ||
| let stopped = volume | ||
| window.moveMouse(40, 64) | ||
| window.pumpFrame(sk) | ||
| doAssert volume == stopped, "released scrubber must not keep dragging" | ||
| clickAt(24 + sk.theme.border + sk.theme.textPadding, | ||
| 124 + sk.theme.border + sk.theme.textPadding, completed) | ||
| doAssert panel.minimized | ||
| clickAt(24 + sk.theme.border + sk.theme.textPadding, | ||
| 124 + sk.theme.border + sk.theme.textPadding, completed) | ||
| doAssert not panel.minimized | ||
| echo "Press-driven widget callback tests passed" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.