Skip to main content

Multi-window apps

Apps for Desktop can create/manage multiple windows using the WindowGroup interface. Simply inject it into your app to get started. The API provides access to an app's main window as well as methods for creating new windows.

package display import io.nacular.doodle.application.Application import io.nacular.doodle.core.WindowGroup import io.nacular.doodle.core.view import io.nacular.doodle.geometry.Size import io.nacular.doodle.layout.constraints.constrain import io.nacular.doodle.layout.constraints.fill //sampleStart class MyCoolApp(windows: WindowGroup): Application { init { // main window's display, same as if Display were injected windows.main.apply { title = "Main Window" // manipulate main window's display display += view {} } // create a new window windows { title = "A New Window!" size = Size(500) enabled = false resizable = false triesToAlwaysBeOnTop = true // manipulate the new window's display display += view {} display.layout = constrain(display.first(), fill) closed += { // handle window close } } } override fun shutdown() {} } //sampleEnd
tip

There's no need to inject Display if you already inject WindowGroup. That's because the injected Display is equivalent to WindowGroup.main.display

Native window menus

Apps can set up native menus for their windows. This looks a lot like working with the existing menu APIs, but it results in changes to the OS window decoration. These menus are just as interactive as the in-app ones as well, meaning they trigger events when the user interacts with them.

package display import io.nacular.doodle.controls.popupmenu.MenuBehavior.ItemInfo import io.nacular.doodle.core.Icon import io.nacular.doodle.core.Window fun example(window: Window, icon1: Icon<ItemInfo>, icon2: Icon<ItemInfo>) { //sampleStart window.menuBar { menu("Menu 1") { action("Do action 2", icon1) { /*..*/ } menu("Sub menu") { action("Do action sub", icon = icon2) { /*..*/ } separator() prompt("Some Prompt sub") { /*..*/ } } separator() prompt("Some Prompt") { /*..*/ } } menu("Menu 2") { // ... } } //sampleEnd }

Native context menus

Apps can set up native context/popup menus for their windows. The API is very similar to native menus.

package display import io.nacular.doodle.controls.popupmenu.MenuBehavior.ItemInfo import io.nacular.doodle.core.Icon import io.nacular.doodle.core.Window import io.nacular.doodle.geometry.Point fun contextMenu(window: Window, icon1: Icon<ItemInfo>, icon2: Icon<ItemInfo>) { //sampleStart window.popupMenu(at = Point()) { action("Do action 2", icon1) { /*..*/ } menu("Sub menu") { action("Do action sub", icon = icon2) { /*..*/ } separator() prompt("Some Prompt sub") { /*..*/ } } separator() prompt("Some Prompt") { /*..*/ } } //sampleEnd }