Skip to content

imgui refactor - #1066

Merged
kushalkolar merged 15 commits into
ndwidgetfrom
new-hlut-cbar
Jul 27, 2026
Merged

imgui refactor#1066
kushalkolar merged 15 commits into
ndwidgetfrom
new-hlut-cbar

Conversation

@kushalkolar

@kushalkolar kushalkolar commented Jul 25, 2026

Copy link
Copy Markdown
Member
  • Replace EdgeWindow with ImguiWindow which can be located on an edge, floating, or fixed-rect windows. Can create with a single function containing UI elements decorate a function of imgui UI element calls.
  • Can append to ImguiWindow instances.
  • replace HistogramLUTTool with an imgui ImguiColorbar.
  • Revamped popup API, now ImguiPopup. Supports appending too.
  • window menu example by overriding draw() and having full control.
  • imgui docs guide and reference containing all elements with images.

Not related to imgui but made it anyways:

  • ImageGamma graphic feature.

Replace HistogramLUTTool with an imgui created one: ImguiColorbar that can also just be a colorbar. This is gives us higher performance so we don't have to create lots of docks when there are lots of images.

image

allow floating or fixed-location windows

image

decorators for add and append for ImguiWindow and ImguiPopup and easier, cleaner API to add popups/right-click menus.

# a floating window is auto-sized by imgui and can be dragged by the user
@figure.add_imgui_window(location="floating", title="floating", window_flags=imgui.WindowFlags_.none)
def floating_gui(fig):
    if imgui.button("randomize"):
        fig[0, 0]["image"].data = np.random.rand(128, 128)

For popup, can be figure, subplot, or graphic level. Can also append to the standard right click menu on a figure:

# append elements to the standard right-click menu
@figure.append_imgui_right_click()
def more_items(fig):
    imgui.separator()
    if imgui.menu_item("Autoscale all subplots", "", False)[0]:
        for subplot in fig:
            subplot.auto_scale()


# a popup set on a subplot replaces the standard menu within that subplot
@figure[0, 1].set_imgui_right_click()
def line_popup(subplot):
    imgui.text(f"subplot: {subplot.name}")
    imgui.separator()
    _, line.thickness = imgui.slider_float("thickness", line.thickness, 1.0, 20.0)
    changed, color = imgui.color_edit3("color", tuple(float(c) for c in line.colors)[:3])
    if changed:
        line.colors = (*color, 1.0)
image
# a popup can contain any imgui elements, it is not restricted to menu items
def image_processing(image):
    ui = image.metadata

    imgui.text(image.name)
    imgui.separator()

    changed_noise, ui["noise"] = imgui.slider_float("noise sigma", ui["noise"], 0.0, 100.0)
    changed_filter, ui["filter"] = imgui.checkbox("gaussian filter", ui["filter"])

    imgui.begin_disabled(not ui["filter"])
    changed_sigma, ui["sigma"] = imgui.slider_float("filter sigma", ui["sigma"], 0.1, 10.0)
    imgui.end_disabled()

    if imgui.button("reset"):
        ui.update(noise=0.0, sigma=1.0, filter=False)
        changed_noise = True

    if changed_noise or changed_filter or changed_sigma:
        data = raw[image] + np.random.normal(scale=ui["noise"], size=raw[image].shape)

        if ui["filter"]:
            data = gaussian_filter(data, sigma=ui["sigma"])

        image.data = data
image

can append to an imgui window or subplot toolbar:

# create an edge window
@figure.add_imgui_window(location="right", size=200, title="controls")
def gui(fig):
    if imgui.button("randomize"):
        fig[0, 0]["line"].data[:, 1] = np.random.rand(100)


# append more elements to the same window
@figure.append_imgui_window(location="right")
def more(fig):
    line = fig[0, 0]["line"]
    _, line.thickness = imgui.slider_float("thickness", v=line.thickness, v_min=2.0, v_max=50.0)


# append a button to the subplot toolbar that toggles axes visibility
@figure[0, 0].append_imgui_window(location="toolbar")
def toolbar_extra(subplot):
    imgui.same_line()
    _, subplot.axes.visible = imgui.checkbox(fa.ICON_FA_RULER_COMBINED, subplot.axes.visible)
    if imgui.is_item_hovered(0):
        imgui.set_tooltip("Axes visibility")
image

location can be the edge of Subplot and not just edges of a Figure

See the colorbar examples which add it to the right edge of a subplot.

LLM Disclosure: claude on ultracode setting was babysat through this, every line was reviewed, everything tested manually.

@kushalkolar kushalkolar changed the title New hlut cbar imgui refactor Jul 25, 2026
@kushalkolar

Copy link
Copy Markdown
Member Author

We have our own imgui API docs that corresponds to imgui_bundle so we don't have to refer to pyimgui and then consolidate the differences with imgui_bundle by looking at the source :D

image

@kushalkolar
kushalkolar marked this pull request as ready for review July 25, 2026 14:20
@kushalkolar
kushalkolar requested a review from clewis7 as a code owner July 25, 2026 14:20
@kushalkolar

kushalkolar commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

@FlynnOConnell

Comments on the API? You've been asking for this for ages.

Here's the imgui docs guide as an html as it currently is in the docs:
guide.html

@FlynnOConnell

Copy link
Copy Markdown
Collaborator

This is amazing. My previous widgets would be much better suited as a floating window because we want as much data visible as possible.

In the future this could be extended to allowing users to switch between floating and sticky maybe via a default right click menu for each newly created ImguiWindow. "Dock Left" "Dock Right" etc. could go in this menu as well.

For the colorbar, I think switching begin_popup_context_item -> begin_popup_context_window makes sense so that right-clicking anywhere in the widget should bring up the cmap selection choices, I know examples of users missing this functionality.

@kushalkolar

Copy link
Copy Markdown
Member Author

I'll leave the docking functionality to you once you get to UTSWMC 😆

@kushalkolar

Copy link
Copy Markdown
Member Author

changed colorbar/hlut window to bring up colormap popup if it's right clicked anywhere and not just the colorbar.

@clewis7

clewis7 commented Jul 27, 2026

Copy link
Copy Markdown
Member

No deployments on this branch???

@kushalkolar

Copy link
Copy Markdown
Member Author

No deployments on this branch???

You mean docs? yea because only branches targetting main run through CI, this targets ndwidget branch. so I tested the docs build locally.

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

Successfully merging this pull request may close these issues.

3 participants