Skip to content

Commit

Permalink
Add bindings for ComboClick() and ComboClickAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley committed Aug 30, 2024
1 parent 10df990 commit 01ffb6b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ CurrentModule = ImGuiTestEngine
This documents notable changes in ImGuiTestEngine.jl. The format is based on
[Keep a Changelog](https://keepachangelog.com).

## Unreleased

### Added
- Bindings for [`ComboClick()`](@ref) and [`ComboClickAll()`](@ref) ([#4]).

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

Expand Down
2 changes: 2 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ ItemClick
ItemDoubleClick
ItemCheck
MenuClick
ComboClick
ComboClickAll
GetWindowByRef
Yield
```
1 change: 1 addition & 0 deletions src/ImGuiTestEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DocStringExtensions: TYPEDEF, TYPEDSIGNATURES
export @register_test, @imcheck, @imcheck_noret,
SetRef, GetRef, GetWindowByRef,
ItemClick, ItemDoubleClick, ItemCheck, MenuClick,
ComboClick, ComboClickAll,
Yield

@compat public (Engine, EngineIO, ImGuiTest, TestRef, TestContext,
Expand Down
34 changes: 34 additions & 0 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,40 @@ end
"""
$(TYPEDSIGNATURES)
Click on a combo box item.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
ComboClick("My combo/Item 1")
end
```
"""
function ComboClick(test_ref::TestRef, ctx=nothing)
@_default_ctx
lib.ComboClick(ctx, lib.ImGuiTestRef(test_ref))
end

"""
$(TYPEDSIGNATURES)
Click on all items in a combo box.
# Examples
```julia
@register_test(engine, "foo", "bar") do ctx
ComboClickAll("My combo")
end
```
"""
function ComboClickAll(test_ref::TestRef, ctx=nothing)
@_default_ctx
lib.ComboClickAll(ctx, lib.ImGuiTestRef(test_ref))
end

"""
$(TYPEDSIGNATURES)
Retrieve a `ImGuiWindow` by reference. This will return `nothing` if the window
was not found.
Expand Down
30 changes: 30 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,36 @@ end
@imcheck menu_item_selected
end

current_combo_item = Ref{Cint}(-1)
selected_combo_items = Int[]
t = @register_test(engine, "Context", "ComboClick/ComboClickAll")
t.GuiFunc = ctx -> begin
ig.Begin("Window")
ig.Combo("Combo1", current_combo_item, "One\0Two\0")

if ig.BeginCombo("Combo2", "")
if ig.Selectable("One")
push!(selected_combo_items, 1)
end
if ig.Selectable("Two")
push!(selected_combo_items, 2)
end

ig.EndCombo()
end
ig.End()
end
t.TestFunc = ctx -> begin
SetRef("Window")
ComboClick("Combo1/One")
@imcheck current_combo_item[] == 0
ComboClick("Combo1/Two")
@imcheck current_combo_item[] == 1

ComboClickAll("Combo2")
@imcheck selected_combo_items == [1, 2]
end

item_checked = Ref(false)
t = @register_test(engine, "Context", "ItemCheck")
t.GuiFunc = ctx -> begin
Expand Down

0 comments on commit 01ffb6b

Please sign in to comment.