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

Is it possible to dynamically add dockable windows. #106

Closed
eniac11 opened this issue May 4, 2023 · 6 comments
Closed

Is it possible to dynamically add dockable windows. #106

eniac11 opened this issue May 4, 2023 · 6 comments

Comments

@eniac11
Copy link

eniac11 commented May 4, 2023

I want to dynamically add imgui windows in python. I would expect something like.

# my_dockable_window in MainDockSpace
hello_imgui.get_runner_params().docking_params.dockable_windows.append(my_dockable_window)

Would create a window and show it docked in Maindockspace.

Is this possible. If it is how would I do this and should there be an demo.

PS. First ever github issue or issue in fact.

@pthom
Copy link
Owner

pthom commented May 4, 2023

Hi,

This subject was discussed previously inside HelloImGui's repository.

However, you are right a demo would help: I added a demo for this in this commit

By the way, I just opened a gallery in the discussions section of this repository. I you are inclined to post examples from your use of the library, I would be happy to see them!

@dcnieho
Copy link
Contributor

dcnieho commented Jun 3, 2023

Yes, very possible. Not by mutating the current list of windows but by replacing it. so

window_list = hello_imgui.get_runner_params().docking_params.dockable_windows
window_list.append(my_dockable_window)
hello_imgui.get_runner_params().docking_params.dockable_windows = window_list

@pthom
Copy link
Owner

pthom commented Jun 6, 2023

@eniac11 , @dcnieho : I recently added an interesting feature: the possibility to define several layouts and switch between them.

Each layout is stored in a DockingParams, and:

  • can contain a different list of windows (vector<DockableWindow>)
  • has a different spatial layout (vector<DockingSplit>)
  • remembers and restores the user modifications to this given layout
  • remembers and restores the list of Opened windows

See this video demo and explanation

Also, see the corresponding code:

@dcnieho
Copy link
Contributor

dcnieho commented Jun 14, 2023

@pthom! This looks like a really useful feature! Especially since it can track how users change the layout. I have an app that is used by multiple users, and using this i think I can use this feature to reinstate the layout from their last session after they log in. That's really nice!

some questions and things i wonder about before trying this out:

  1. the two alternative layouts you show, are they defaults you provide for imapps? If so, is there a way to switch that off? I won't need those, and extra things in the menu that my users don't need will only confuse them.
  2. How does this interacts with some settings? I run my app with restoreGeometry set to false, as i don't want people to mess up my login screen for the next user. But then now their own layout i would want to restore (programatically activate), so it would have to be stored in the ini file in the first place. If i understood you correctly, not only the restoring but also the layout tracking is only done when restoreGeometry is set to true? (Maybe my solution is to set restoreGeometry to true, but then programmatically hard-override the layout for the login screen each time upon program start.
  3. Users can create new windows in my app, and I'd like those to be restored as well. I must do this programatically somehow. Is it possible to query a layout and reveal the list of windows and importantly their names? Then i know which windows to create upon profile activation. An alternative would seem to be to always create all windows and flip their visibility. That isn't possible for me as the list of possible windows cannot be known beforehand. And is there a callback that is called on (just before) profile activation indicating what is to be created so i can do this window creation just in time? I guess i can catch it all programatically as i'm fine, but that may be needed for other use cases.

@dcnieho
Copy link
Contributor

dcnieho commented Jun 14, 2023

Note. thats me thinking before i have tried the feature. If it doesn't make sense, let me know.

@pthom
Copy link
Owner

pthom commented Jun 14, 2023

Hi Dee,

the two alternative layouts you show, are they defaults you provide for imapps?
If so, is there a way to switch that off? I won't need those, and extra things in the menu that my users
don't need will only confuse them.

Please read the example demo_docking.py
At line 469, you have

    # Set the default layout (this contains the default DockingSplits and DockableWindows)
    runner_params.docking_params = create_default_layout(app_state)
    # Add alternative layouts
    runner_params.alternative_docking_layouts = create_alternative_layouts(app_state)

What you want is to let runner_params.alternative_docking_layouts be empty. This way, no layout menu will be shown.

How does this interacts with some settings? I run my app with restoreGeometry set to false, as i don't want people
to mess up my login screen for the next user. But then now their own layout i would want to restore
(programatically activate), so it would have to be stored in the ini file in the first place.
If i understood you correctly, not only the restoring but also the layout tracking is only done when restoreGeometry is set to true?
(Maybe my solution is to set restoreGeometry to true, but then programmatically hard-override the layout for the login screen each time upon program start

May be you could call hello_imgui.run() once for the login screen, and then run it once for the rest of the app?

Users can create new windows in my app, and I'd like those to be restored as well. I must do this programatically somehow.
Is it possible to query a layout and reveal the list of windows and importantly their names? Then i know which windows to create upon profile activation.

I guess this is what it contained in runnerParams.docking_params.dockable_windows (and then ask for their name)

An alternative would seem to be to always create all windows and flip their visibility. That isn't possible for me as the list of possible windows cannot be known beforehand.

This would be the easier possibility

And is there a callback that is called on (just before) profile activation indicating what is to be created so i can do this window creation just in time?
I guess i can catch it all programatically as i'm fine, but that may be needed for other use cases.

What do you mean by profile activation?

@pthom pthom closed this as completed Nov 1, 2023
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

3 participants