Skip to content

Minimal docking example #268

@neurosock

Description

@neurosock

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    faqA frequent issue, remaining opened to facilitate discoverability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions