Skip to content

Commit

Permalink
Merge pull request #12 from JuliaImGui/imvec2
Browse files Browse the repository at this point in the history
Add wrapper for `MouseMoveToPos()` and bump version
  • Loading branch information
JamesWrigley authored Feb 2, 2025
2 parents 967f4c1 + 852b564 commit 2023ed2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 4 deletions.
4 changes: 2 additions & 2 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.5"
version = "0.1.6"

[deps]
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
Expand All @@ -14,7 +14,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CImGui = "2,3,4"
CImGuiPack_jll = "0.3,0.4,0.5,0.6,0.7"
CImGuiPack_jll = "0.7.1"
Compat = "4.15.0"
CxxWrap = "0.16.0"
DocStringExtensions = "0.9.3"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
ImGuiTestEngine = "464e2eba-0a11-4ed3-b274-413caa1a1cca"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
9 changes: 8 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Revise
import Documenter: Remotes, HTML, makedocs, deploydocs
import Changelog
import ImGuiTestEngine
import DocumenterInterLinks: InterLinks


# Explicitly call Revise to update changes to the docstrings
Revise.revise()
Expand All @@ -14,6 +16,10 @@ Changelog.generate(
repo="JuliaImGui/ImGuiTestEngine.jl"
)

links = InterLinks(
"CImGui" => "https://juliaimgui.github.io/ImGuiDocs.jl/cimgui/stable/"
)

makedocs(;
repo = Remotes.GitHub("JuliaImGui", "ImGuiTestEngine.jl"),
sitename = "ImGuiTestEngine",
Expand All @@ -23,7 +29,8 @@ makedocs(;
"api.md",
"changelog.md"
],
modules = [ImGuiTestEngine]
modules = [ImGuiTestEngine],
plugins = [links]
)

deploydocs(; repo="github.com/JuliaImGui/ImGuiTestEngine.jl.git")
5 changes: 5 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ CurrentModule = ImGuiTestEngine
This documents notable changes in ImGuiTestEngine.jl. The format is based on
[Keep a Changelog](https://keepachangelog.com).

## [v0.1.6] - 2025-02-01

### Added
- Bindings for [`MouseMoveToPos()`](@ref) ([#12]).

## [v0.1.5] - 2024-12-19

Patch release to actually add compat for CImGui v4 ([#9]).
Expand Down
8 changes: 8 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ same thing as `SetRef("My window")`.
te.lib.Thing(ctx, te.lib.ImGuiTestRef("my ref"))
```

For functions that take an `ImVec2` argument, create one that can be passed
to the C++ functions with the un-exported `mkImVec2()` helper function like
so:
```julia
te.lib.Thing(ctx, te.mkImVec2(x, y))
```

```@docs
TestContext
@imcheck
Expand All @@ -122,6 +129,7 @@ SetRef
GetRef
MouseClick
MouseMove
MouseMoveToPos
ItemOpen
ItemClose
OpenAndClose
Expand Down
2 changes: 1 addition & 1 deletion src/ImGuiTestEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export @register_test, @imcheck, @imcheck_noret,
ItemClick, ItemDoubleClick, ItemCheck, ItemOpen, ItemClose,
MenuClick,
ComboClick, ComboClickAll,
MouseClick, MouseMove,
MouseClick, MouseMove, MouseMoveToPos,
Yield,
OpenAndClose

Expand Down
30 changes: 30 additions & 0 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function _generate_imcheck(expr, source, with_return, kwargs...)
end
end

# Helper function to create a C++-wrapped ImVec2
mkImVec2(x, y) = lib.mkImVec2(convert(Float32, x), convert(Float32, y))

"""
@imcheck expr
Expand Down Expand Up @@ -340,6 +343,33 @@ end
"""
$(TYPEDSIGNATURES)
Move the mouse to the given position in absolute coordinates (e.g. matching
[`ig.GetMousePos()`](@extref `CImGui.GetMousePos`) and
[`ig.GetCursorScreenPos()`](@extref `CImGui.GetCursorScreenPos`)).
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
MouseMoveToPos(100, 100)
MouseMoveToPos((100, 100))
MouseMoveToPos(ig.ImVec2(100, 100))
end
```
"""
function MouseMoveToPos(x, y, ctx=nothing)
@_default_ctx
lib.MouseMoveToPos(ctx, mkImVec2(x, y))
end

"$(TYPEDSIGNATURES)"
MouseMoveToPos(pos::ig.ImVec2, ctx=nothing) = MouseMoveToPos(pos.x, pos.y, ctx)

"$(TYPEDSIGNATURES)"
MouseMoveToPos(pos::NTuple{2, Real}, ctx=nothing) = MouseMoveToPos(pos[1], pos[2], ctx)

"""
$(TYPEDSIGNATURES)
Register a click of `button`.
# Examples
Expand Down
20 changes: 20 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,26 @@ end
@imcheck is_hovered
end

mouse_pos = nothing
t = @register_test(engine, "Context", "MouseMoveToPos")
t.GuiFunc = ctx -> begin
ig.Begin("Window")

mouse_pos = ig.GetMousePos()
ig.Text("Cursor position: ($(mouse_pos.x), $(mouse_pos.y))")
ig.End()
end
t.TestFunc = ctx -> begin
SetRef("Window")

MouseMoveToPos(100, 100)
@imcheck mouse_pos.x == mouse_pos.y == 100
MouseMoveToPos(ig.ImVec2(200, 200))
@imcheck mouse_pos.x == mouse_pos.y == 200
MouseMoveToPos((300, 300))
@imcheck mouse_pos.x == mouse_pos.y == 300
end

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

2 comments on commit 2023ed2

@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/124200

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.6 -m "<description of version>" 2023ed2f0f331caed5c2ef8515d1c96a363d504e
git push origin v0.1.6

Please sign in to comment.