From 01ffb6b7a6ade84bb737e7858031462d885f8466 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Fri, 30 Aug 2024 20:43:44 +0200 Subject: [PATCH] Add bindings for `ComboClick()` and `ComboClickAll()` --- docs/src/_changelog.md | 4 ++++ docs/src/api.md | 2 ++ src/ImGuiTestEngine.jl | 1 + src/context.jl | 34 ++++++++++++++++++++++++++++++++++ test/runtests.jl | 30 ++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/docs/src/_changelog.md b/docs/src/_changelog.md index 541d345..62d0fe1 100644 --- a/docs/src/_changelog.md +++ b/docs/src/_changelog.md @@ -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 diff --git a/docs/src/api.md b/docs/src/api.md index e4941e1..2502def 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -124,6 +124,8 @@ ItemClick ItemDoubleClick ItemCheck MenuClick +ComboClick +ComboClickAll GetWindowByRef Yield ``` diff --git a/src/ImGuiTestEngine.jl b/src/ImGuiTestEngine.jl index 4a838f7..f2007fb 100644 --- a/src/ImGuiTestEngine.jl +++ b/src/ImGuiTestEngine.jl @@ -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, diff --git a/src/context.jl b/src/context.jl index 75900fe..6f9b532 100644 --- a/src/context.jl +++ b/src/context.jl @@ -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. diff --git a/test/runtests.jl b/test/runtests.jl index e15382b..fb71ba2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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