Toms IMGUI Scratch notes
Examples to Dev
- How to read/write single datarefs
- How to read/write array datarefs
- How to read/write byte datarefs
- How to create a 2D popup window (imgui / hybrid?)
- probably imgui to create window, panel graphics content within?
- imgui examples of common widgets
- strategic advice
- How to create EFIS avionics?
- cockpit_device? pros/cons?
- when to panel draw? versus FBO?
- How to register/unregister a flight loop callback.
- How/when/what to initialize.
- Common things needing registration / unregistration.
- How to create a command and callback.
- Custom / Replace / Augment
-
Architectural / Structural paradigms
- dofile / require / modular isolation / XLua1/XLua2 mix
-
IMGUI Examples
- Set the font, style and size
- Draw graphics in a "canvas"
- Debugging methods / tools
18.1 demo_wnd = float_wnd_create(800, 450, 1, true)
The first two parameters specify the size of the window in boxels. Boxels are scalable pixes. If the UI scale is set to 100% in the settings, a boxel equals a pixel. However, if the user sets the UI scale to more than 100%, a boxel will be scaled to span multiple pixels. The third parameter specifies the window decoration. The following decorations are possible: 0: "X-Plane will draw no decoration for your window, and apply no automatic click handlers. The window will not stop click from passing through its bounds. This is suitable for "windows" which request, say, the full screen bounds, then only draw in a small portion of the available area." 1: "The default decoration for "native" windows, like the map. Provides a solid back- ground, as well as click handlers for resizing and dragging the window." 2: "X-Plane will draw no decoration for your window, nor will it provide resize han- dlers for your window edges, but it will stop clicks from passing through your windows bounds." 3: "Like 2, but with resizing; X-Plane will draw no decoration for your window, but it will stop clicks from passing through your windows bounds, and provide automatic mouse handlers for resizing." The last parameter configures whether you want to use imgui for the floating window. The return value is a handle to the window that can be used to configure additional things.
18.2 float_wnd_set_title(demo_wnd, "Demo Window")
This function sets the title of the window if it has a decoration. The first parameter must be a handle to a window previously created with float_wnd_create. The second parameter is the title of the window.
18.3 float_wnd_set_position(demo_wnd, 775, 650)
This function sets the initial position of the window. The first parameter must be a handle to a window previously created with float_wnd_create. The second and third parameters set the initial position of the window.
18.4 float_wnd_set_imgui_builder(demo_wnd, "build_demo")
imgui GUIs are built each frame. You will need to supply a function that is called every frame. The first parameter must be a handle to a window previously created with float_wnd_create. The second parameter must be the name of a function. Note that unlike other function in Fly- WithLua, you can only pass the name of a function here, not an arbitrary lua string. This func- tion will be called for every frame while the window is visible, so you don’t need an additional do_every_frame unless you also need to do things while the window is closed.
18.5 float_wnd_set_onclose(demo_wnd, "closed_demo")
If the window has a decoration with a close button (like decoration 1), you might need a way to know when the users closes the window. This function can be used to setup a function to be called when the user closes the window. The first parameter must be a handle to a window previously created with float_wnd_create and the second parameter must be the name of a function. Note that unlike other function in FlyWithLua, you can only pass the name of a function here, not an arbitrary lua string. This function will be called when the user closes the window. After the window is closed, its builder function will not be called again and it is illegal to use the window handle variable returned by float_wnd_create, e.g. it is illegal to set the window title after it was closed.
18.6 image_id = float_wnd_load_image(SCRIPT_DIRECTORY ..
"/imgui_demo.jpg") imgui supports drawing images, so let’s load one. The images must always be loaded globally to make sure they are only loaded once per script! imgui widgets have no state, that means we need to store states of checkboxes, radio buttons etc. globally. makeRed = false sliderVal = 0 choice = 1 angle = 0 text = ""
18.7 function build_demo(wnd, x, y)
This function is called for every frame. Use this function to create your GUI. The first parameter (wnd) is the handle of the window. It is the same handle as the one returned by float_wnd_create. It is required if you have multiple windows that use the same builder function so you know which of these windows is currently being built. The x and y parameters are the current position of the window in OpenGL coordinates, i.e. the position of the lower left corner in global screen coordinates. These coordinates are only needed for using the graphics module on top of the imgui GUI. If you only use imgui, these coordinates are not required because imgui has its own coordinate system inside the window.
18.8 function closed_demo(wnd)
This function is called when the user closes the window. Drawing or calling imgui functions is not allowed in this function as the window is already destroyed.