Emily V
02/26/2022, 5:01 PMfun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "Core Plotter v1.0.0",
state = rememberWindowState(width = 1024.dp, height = 768.dp)
) {
val menuBarActions = MenuBarActions(this@application)
val chartLogic = ChartLogic
MaterialTheme {
WindowMenuBar(menuBarActions)
GraphScreen(chartLogic)
}
}
}
Please notice MenuBarActions (which is regular Kotlin object that has the logic actions for MenuBar item clicks) that is passed to the Composable function:
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun FrameWindowScope.WindowMenuBar(actions: MenuBarActions) = MenuBar {
Menu("File") {
Item("Open recording...", onClick = { actions.openFile(window)}, shortcut = KeyShortcut(Key.O, meta = true))
Item("Save", onClick = { }, shortcut = KeyShortcut(Key.S, meta = true))
Separator()
Item("Exit", onClick = { actions.closeWindow()}, shortcut = KeyShortcut(Key.Q, meta = true))
}
Menu("Actions") {
Item("Export", onClick = { })
}
}
I’m not too happy with passing this@application to MenuBarActions constructor. I’m doing that so I can call application.exitApplication() when “Exit” is clicked. It works but is that the correct way to handle this action?