Skip to content
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

Programmatically activating widget? #3949

Open
dbr opened this issue Mar 20, 2021 · 5 comments
Open

Programmatically activating widget? #3949

dbr opened this issue Mar 20, 2021 · 5 comments

Comments

@dbr
Copy link

dbr commented Mar 20, 2021

Background

I am looking to write some unit tests for an imgui based application.

Say I have a window with some text inputs, and a "create" button. It all works, but I want to write a unit that verifies when the button is pressed that the desired action occurs.

The immediate mode methodology makes it trivially easy to pre-fill the form with my test input strings, but I'm not sure how I'd go about setting the "button id ##example has been pressed" state.

I could add additional variables to allow triggering the button being pressed, e.g

if simulate_button_click || ui.button(...) {

as discussed in #966 but I would rather not, as it clutters up the code just for testing (which adds more potential for errors)

Main question

At the end of the discussion #966 (comment) there was a comment saying

Note that there are plan for a new API to programmatically activate widgets based on their ID, but that won't be ready short-term.

I am wondering if this has come to existence yet? I had a search around and couldn't find any further mention of it (but it's a slightly hard thing to know the search terms for!)

Followup ideas

I'm imagining something very vaguely along the lines of this

let ui = imgui_context.frame();
my_widget.example_input = "test";
my_widget.render(&ui);
...
imgui_context.set_element_active("##example", true);
let ui = imgui_context.frame();
my_widget.render(&ui);
assert!(my_widget.other_thing == "button was clicked an value was test";

I'm using the imgui-rs bindings, not sure how exactly that'd translate to the original C++, but should give a rough idea as pseudo code - basically on next query I want the element with that ID to be as if the user clicked on it

My other thought was I could determine the button location and simulate a mouse click (by moving the cursor position to there and setting the mouse button as down) - this might actually be a better way to go since it exactly what I'm wanting to test, just the implementation is slightly more complex

@ocornut
Copy link
Owner

ocornut commented Mar 20, 2021

There is such an automation system see #435 but it hasn’t been made public.

@ocornut ocornut changed the title Programatically activating widget? Programmatically activating widget? Mar 30, 2021
ocornut added a commit that referenced this issue Nov 4, 2021
…ling, using nav queries. (#4449)

Not using counter/modulo anymore and special provisions to handle tab wrapping with ImGuiListClipper. Wrapping may be done better as a next-frame forwarded request.
Also one extra step toward #3949 #3985
actondev pushed a commit to actondev/imgui that referenced this issue Nov 26, 2021
…ling, using nav queries. (ocornut#4449)

Not using counter/modulo anymore and special provisions to handle tab wrapping with ImGuiListClipper. Wrapping may be done better as a next-frame forwarded request.
Also one extra step toward ocornut#3949 ocornut#3985
@ghost
Copy link

ghost commented Mar 15, 2022

@ocornut is there any update on the automation framework? Any ETA for when it will be made public?

@ocornut
Copy link
Owner

ocornut commented Mar 15, 2022

This is still being tested/iterated with selected partners and sponsors. We’re working on a license and expect to release it publicly between Q2 and Q3.

@dbr
Copy link
Author

dbr commented Dec 1, 2022

Most likely done via #435 🥳

@dbr dbr closed this as completed Dec 1, 2022
@ocornut ocornut reopened this Dec 1, 2022
@ocornut
Copy link
Owner

ocornut commented Dec 1, 2022

Yes as per your specific need Test Engine should ideally be the answer.
But I’ll reopen this issue as - and given the specific wording used in issue title - I want to also finish implementing API to do things like from dear imgui API point of view too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants