Nucleus
Windows

Dialogs and popups

Open modal dialogs with DecoratedDialog, DialogWindow, HostedDialog, or a toolkit dialog, and render Compose popups as native surfaces placed against the screen.

View as Markdown

On this page, you'll open native dialogs owned by a window and turn Compose popups, menus and tooltips into native surfaces that can leave the window.

Open a dialog

Call DecoratedDialog from a window's content:

if (showSettings) {
    DecoratedDialog(
        onCloseRequest = { showSettings = false },
        state = rememberDialogState(size = DpSize(480.dp, 320.dp)),
        title = "Settings",
    ) {
        DialogTitleBar { _ -> Text("Settings") }
        SettingsContent()
    }
}

A dialog is not resizable by default and has no minimize or maximize button. The window that opens it becomes its owner: the dialog stays above it, follows it across minimize, Spaces and workspaces, stays out of the taskbar, and closes with it.

Block the owner

While the dialog is open, the owner ignores pointer input. Activating the owner, by a click on its uncovered part, its taskbar button, Alt+Tab or toFront(), brings the dialog forward with the keyboard focus instead, so keystrokes never reach the blocked content. Stacked dialogs chain: each one takes the activation of its own owner. A dialog with visible, enabled or focusable set to false leaves the owner's activation alone.

On Windows the owner is disabled natively while the dialog is visible, like a Win32 DialogBox: its content, title bar, caption buttons and keys refuse input, and a click there beeps and flashes the dialog. Closing the dialog gives the focus back to the owner with no extra click. On macOS and Linux an in-scene blocker stops pointer input to the owner.

A dialog declared at application scope blocks pointer input in every window. For a secondary window the user can put behind its parent, open a second DecoratedWindow.

Place the dialog

A dialog centres on its owner, or on the screen when it has none. Set Dp.Unspecified on an axis of the size to fit the content (Size a window to its content). For screen selection and position providers, pass a v2 DialogState from dev.nucleusframework.window.tao.v2 (Use a dialog state).

Use the platform's title bar

DialogWindow is the dialog counterpart of Window: the platform draws its title bar and frame, and Nucleus draws no chrome. It replaces Compose Desktop's androidx.compose.ui.window.DialogWindow with an import change:

import dev.nucleusframework.application.DialogWindow

if (showSettings) {
    DialogWindow(
        onCloseRequest = { showSettings = false },
        state = rememberDialogState(size = DpSize(480.dp, 320.dp)),
        title = "Settings",
    ) {
        SettingsContent()
    }
}

It has the same owner and blocking behaviour as DecoratedDialog, and keeps Compose's defaults, so it is resizable unless you pass resizable = false. Compose's undecorated, transparent, and alwaysOnTop are not offered. A DialogTitleBar in its content shows no close button.

Use a toolkit dialog

ToolkitDialogTitle bar
Material 3dev.nucleusframework.window.material.MaterialDecoratedDialogMaterialDialogTitleBar
Material 2dev.nucleusframework.window.material2.MaterialDecoratedDialogMaterialDialogTitleBar
Jeweldev.nucleusframework.window.jewel.JewelDecoratedDialogJewelDialogTitleBar

The dialogs are extensions on NucleusApplicationScope. From a composable without a receiver:

with(LocalNucleusApplicationScope.current) {
    MaterialDecoratedDialog(onCloseRequest = onClose, title = "Confirm") {
        MaterialDialogTitleBar { _ -> Text("Confirm") }
        ConfirmContent(onClose)
    }
}

Changed in 3.0

The receiver-less AWT overloads of MaterialDecoratedDialog and JewelDecoratedDialog are gone, and the Material 2 dialog is now a NucleusApplicationScope extension. See Migrate from 2.x.

  • To let an app choose the dialog chrome for a library, call HostedDialog. See Route windows through a host.
  • Compose Desktop's AWT DialogWindow doesn't work: import dev.nucleusframework.application.DialogWindow instead. Compose's in-window Dialog, which AlertDialog uses, works in any Nucleus window.

Open popups as native surfaces

By default the window edge clips a Popup, DropdownMenu or tooltip. With nativePopupLayers = true, each popup of the window opens in its own native surface:

DecoratedWindow(onCloseRequest = ::exitApplication, nativePopupLayers = true) { /* ... */ }

HostedWindow, MaterialDecoratedWindow and JewelDecoratedWindow take the same parameter. Jewel's ListComboBox, PopupMenu, Dropdown and tooltips go through it too.

How popups meet the screenNew

  • Inside a popup, LocalWindowInfo reports the display's work area, not the owner window. Position providers flip against the screen edge, and a tall menu in a small window gets its full height.
  • The popup stays inside the work area of its display and follows the owner across monitors.
  • A Compose Dialog (with a scrim) keeps the owner window's size and does not follow the display.

Opt in a single subtree

NativePopupLayers { } gives native surfaces to the popups opened directly inside it:

NativePopupLayers {
    DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) { /* ... */ }
}

Submenus opened from a native surface need no opt-in. NativePopupLayers does nothing when the window already sets nativePopupLayers = true, when native popups are unavailable, or outside a Nucleus window. The native context menu flyout on Windows and Linux always uses it.

What's next

Was this page helpful?
Edit on GitHub

Last updated on