Skip to content

Commit

Permalink
Merge pull request #5 from JuliaImGui/v1.91.0
Browse files Browse the repository at this point in the history
Add more bindings and bump version
  • Loading branch information
JamesWrigley authored Sep 3, 2024
2 parents 66a810f + 5b1a338 commit a905814
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ImGuiTestEngine"
uuid = "464e2eba-0a11-4ed3-b274-413caa1a1cca"
authors = ["JamesWrigley <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
Expand All @@ -13,8 +13,8 @@ ScopedValues = "7e506255-f358-4e82-b7e4-beb19740aa63"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CImGui = "2"
CImGuiPack_jll = "0.3"
CImGui = "2,3"
CImGuiPack_jll = "0.3,0.4"
Compat = "4.15.0"
CxxWrap = "0.16.0"
DocStringExtensions = "0.9.3"
Expand Down
11 changes: 10 additions & 1 deletion docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ CurrentModule = ImGuiTestEngine
This documents notable changes in ImGuiTestEngine.jl. The format is based on
[Keep a Changelog](https://keepachangelog.com).

## Unreleased
## [v1.0.0] - 2024-09-03

This release is compatible with CImGui.jl v2 and v3.

### Added
- Bindings for [`ComboClick()`](@ref) and [`ComboClickAll()`](@ref) ([#4]).
- Bindings for [`MouseClick()`](@ref), [`MouseMove()`](@ref),
[`ItemOpen()`](@ref), [`ItemClose()`](@ref), and a helper
[`OpenAndClose()`](@ref) ([#5]).

### Changed
- [`ItemClick()`](@ref) now supports passing a `button` argument to select which
button to click ([#5]).

## [v0.1.0] - 2024-06-27

Expand Down
5 changes: 5 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ TestContext
@imcheck_noret
SetRef
GetRef
MouseClick
MouseMove
ItemOpen
ItemClose
OpenAndClose
ItemClick
ItemDoubleClick
ItemCheck
Expand Down
9 changes: 6 additions & 3 deletions src/ImGuiTestEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import DocStringExtensions: TYPEDEF, TYPEDSIGNATURES

export @register_test, @imcheck, @imcheck_noret,
SetRef, GetRef, GetWindowByRef,
ItemClick, ItemDoubleClick, ItemCheck, MenuClick,
ItemClick, ItemDoubleClick, ItemCheck, ItemOpen, ItemClose,
MenuClick,
ComboClick, ComboClickAll,
Yield
MouseClick, MouseMove,
Yield,
OpenAndClose

@compat public (Engine, EngineIO, ImGuiTest, TestRef, TestContext,
TestGroup, TestRunFlags, TestVerboseLevel, RunSpeed,
Expand Down Expand Up @@ -45,9 +48,9 @@ if !isdefined(Base, :ScopedValues)
else
import Base.ScopedValues: ScopedValue, @with
end
import CImGui as ig
include("context.jl")

import CImGui as ig
include("engine.jl")

"""
Expand Down
111 changes: 109 additions & 2 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,46 @@ Simulate a click on the reference.
end
```
"""
function ItemClick(test_ref::TestRef, ctx=nothing)
function ItemClick(test_ref::TestRef, button::ig.ImGuiMouseButton_ = ig.ImGuiMouseButton_Left, ctx=nothing)
@_default_ctx
lib.ItemClick(ctx, lib.ImGuiTestRef(test_ref))
lib.ItemClick(ctx, lib.ImGuiTestRef(test_ref), Int(button))
end

"""
$(TYPEDSIGNATURES)
Ensure an item is opened.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
ItemOpen("My menu")
end
```
"""
function ItemOpen(test_ref::TestRef, flags=0, ctx=nothing)
@_default_ctx
lib.ItemOpen(ctx, lib.ImGuiTestRef(test_ref), Int(flags))
end

"""
$(TYPEDSIGNATURES)
Ensure an item is closed.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
ItemClose("My menu")
end
```
"""
function ItemClose(test_ref::TestRef, flags=0, ctx=nothing)
@_default_ctx
lib.ItemClose(ctx, lib.ImGuiTestRef(test_ref), Int(flags))
end


"""
$(TYPEDSIGNATURES)
Expand Down Expand Up @@ -288,6 +323,41 @@ end
"""
$(TYPEDSIGNATURES)
Move the mouse to `test_ref`.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
MouseMove("My button")
end
```
"""
function MouseMove(test_ref::TestRef, ctx=nothing)
@_default_ctx
lib.MouseMove(ctx, lib.ImGuiTestRef(test_ref))
end

"""
$(TYPEDSIGNATURES)
Register a click of `button`.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
MouseClick() # LMB
MouseClick(ig.ImGuiMouseButton_Right) # RMB
end
```
"""
function MouseClick(button::ig.ImGuiMouseButton_ = ig.ImGuiMouseButton_Left, ctx=nothing)
@_default_ctx
lib.MouseClick(ctx, Int(button))
end

"""
$(TYPEDSIGNATURES)
Retrieve a `ImGuiWindow` by reference. This will return `nothing` if the window
was not found.
Expand Down Expand Up @@ -317,3 +387,40 @@ function Yield(count::Int=1, ctx=nothing)
@_default_ctx
lib.Yield(ctx, count)
end

"""
$(TYPEDSIGNATURES)
A helper function that will ensure `test_ref` is open, execute `f()`, and close
`test_ref` again. A typical use would be to open a section, run some tests, and
then close the section again (handy for re-runnable tests).
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
OpenAndClose("My section") do
# ...
end
end
```
"""
function OpenAndClose(f, test_ref::TestRef, ctx=nothing)
@_default_ctx
ItemOpen(test_ref)
f()
ItemClose(test_ref)
end

"""
$(TYPEDSIGNATURES)
Open and then close `test_ref`.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
OpenAndClose("My section")
end
```
"""
OpenAndClose(test_ref::TestRef, ctx=nothing) = OpenAndClose(Returns(nothing), test_ref, ctx)
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98"
ImGuiTestEngine = "464e2eba-0a11-4ed3-b274-413caa1a1cca"
ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
74 changes: 74 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,80 @@ end
@imcheck double_clicked
end

tree1_open = nothing
tree2_opened = false
t = @register_test(engine, "Context", "Item opening/closing")
t.GuiFunc = ctx -> begin
ig.Begin("Window")
if ig.TreeNode("Tree1")
tree1_open = true
ig.TreePop()
else
tree1_open = false
end

if ig.TreeNode("Tree2")
tree2_opened = true
ig.TreePop()
end

ig.End()
end
t.TestFunc = ctx -> begin
SetRef("Window")

@imcheck !tree1_open
ItemOpen("Tree1")
@imcheck tree1_open
ItemClose("Tree1")
@imcheck !tree1_open

@imcheck !tree2_opened
OpenAndClose("Tree2")
@imcheck tree2_opened
end

mouse_clicked = false
mouse_rightclicked = false
t = @register_test(engine, "Context", "MouseClick")
t.GuiFunc = ctx -> begin
ig.Begin("Window")

if ig.IsMouseClicked(ig.ImGuiMouseButton_Left)
mouse_clicked = true
end
if ig.IsMouseClicked(ig.ImGuiMouseButton_Right)
mouse_rightclicked = true
end

ig.End()
end
t.TestFunc = ctx -> begin
@imcheck !mouse_clicked
@imcheck !mouse_rightclicked

MouseClick()
@imcheck mouse_clicked
MouseClick(ig.ImGuiMouseButton_Right)
@imcheck mouse_rightclicked
end

is_hovered = false
t = @register_test(engine, "Context", "MouseMove")
t.GuiFunc = ctx -> begin
ig.Begin("Window")
ig.Button("Button")
is_hovered = ig.IsItemHovered()
ig.End()
end
t.TestFunc = ctx -> begin
SetRef("Window")

@imcheck !is_hovered
MouseMove("Button")
@imcheck is_hovered
end

ig.render(ctx; engine) do ; end
end
end
Expand Down

2 comments on commit a905814

@JamesWrigley
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114482

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" a90581474c2cc14b3064aed84197062a6522a11c
git push origin v0.1.1

Please sign in to comment.