Skip to content

Minimal docking example #268

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

Open
neurosock opened this issue Oct 21, 2024 · 2 comments
Open

Minimal docking example #268

neurosock opened this issue Oct 21, 2024 · 2 comments
Labels
faq A frequent issue, remaining opened to facilitate discoverability

Comments

@neurosock
Copy link

For fun, and to have a template, I have been trying to write a minimal docking example using hello_imgui and immapp. Here is what I came up with. Can this get even more minimal/shorter (just to show two empty panels)?

minimal_dock

Code:

from imgui_bundle import imgui, immapp, hello_imgui

class AppState:
    var0: str = "Var0"
    var1: str = "Var1"

def gui_left(state: AppState):
    imgui.button('A')

def gui_main(state: AppState):
    imgui.button('B')

def main():

    # Default settings and callbacks, geometry, ini file name, 
    # and allow dragging panels outside main window 
    run_params = hello_imgui.RunnerParams()
    run_params.app_window_params.window_title = "minimal_docking"
    run_params.app_window_params.window_geometry.size = (800, 500)
    run_params.imgui_window_params.enable_viewports = True

    # Tell HelloImGui we want a dock space (strictly required)
    run_params.imgui_window_params.default_imgui_window_type = (
        hello_imgui.DefaultImGuiWindowType.provide_full_screen_dock_space
    )

    # Don't know what this does
    #run_params.docking_params.layout_condition = hello_imgui.DockingLayoutCondition.application_start    
    
    # Create vertical split (Note that "MainDockSpace" is provided by default)
    run_params.docking_params.docking_splits = [
        hello_imgui.DockingSplit(
            initial_dock_ = "MainDockSpace",
            new_dock_ = "LeftSpace",
            direction_ = imgui.Dir_.left,
            ratio_ = 0.25,
        )
    ]

    # Define the application state
    state = AppState()

    run_params.docking_params.dockable_windows = [
        hello_imgui.DockableWindow(
            label_ = "Main",
            dock_space_name_ = "MainDockSpace",
            gui_function_ = lambda: gui_main(state),
        ),
        hello_imgui.DockableWindow(
            label_ = "Left",
            dock_space_name_ = "LeftSpace",
            gui_function_ = lambda: gui_left(state),
        ),
    ]

    # Run the app
    addons_params = immapp.AddOnsParams()
    #addons_params.with_implot = True
    immapp.run(run_params, addons_params)

if __name__ == "__main__":
    main()
@pthom pthom added the faq A frequent issue, remaining opened to facilitate discoverability label Oct 22, 2024
@pthom
Copy link
Owner

pthom commented Oct 22, 2024

Hello,

Thank you for your post. Your code is quite good, and close to the minimal setup if we want it to be a good template starting point. Removing code would make it less extensible and/or less usable as a starting point.

Now, to address the question in the code: "what does run_params.docking_params.layout_condition stand for?": by default, if you do rearrange the docks when the app is running the modified layout is preserved when restarting the app.

If you want to always restore the default layout upon restarting, uncomment this line:

    run_params.docking_params.layout_condition = hello_imgui.DockingLayoutCondition.application_start  

@neurosock
Copy link
Author

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq A frequent issue, remaining opened to facilitate discoverability
Projects
None yet
Development

No branches or pull requests

2 participants