Skip to content

Commit

Permalink
Add basic shortcuts to Standalone L1 navigation screens (#502)
Browse files Browse the repository at this point in the history
* add basic shortcuts to L1 screens

Signed-off-by: Ivan Morgillo <[email protected]>

* make linter happy

Signed-off-by: Ivan Morgillo <[email protected]>

* hoist main screen shortcuts navigation code

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: Ivan Morgillo <[email protected]>
  • Loading branch information
hamen authored Jul 29, 2024
1 parent f03989b commit c422bee
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.jetbrains.jewel.samples.standalone

import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.isAltPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.type
import androidx.compose.ui.res.ResourceLoader
import androidx.compose.ui.res.loadSvgPainter
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -22,6 +28,7 @@ import org.jetbrains.jewel.intui.window.styling.light
import org.jetbrains.jewel.intui.window.styling.lightWithLightHeader
import org.jetbrains.jewel.samples.standalone.view.TitleBarView
import org.jetbrains.jewel.samples.standalone.viewmodel.MainViewModel
import org.jetbrains.jewel.samples.standalone.viewmodel.MainViewModel.currentView
import org.jetbrains.jewel.ui.ComponentStyling
import org.jetbrains.jewel.window.DecoratedWindow
import org.jetbrains.jewel.window.styling.TitleBarStyle
Expand Down Expand Up @@ -68,11 +75,48 @@ fun main() {
onCloseRequest = { exitApplication() },
title = "Jewel standalone sample",
icon = icon,
) {
TitleBarView()
MainViewModel.currentView.content()
}
onKeyEvent = { keyEvent ->
processKeyShortcuts(
keyEvent = keyEvent,
onNavigateTo = MainViewModel::onNavigateTo,
)
},
content = {
TitleBarView()
currentView.content()
},
)
}
}
}

/*
Alt + W -> Welcome
Alt + M -> Markdown
Alt + C -> Components
*/
private fun processKeyShortcuts(
keyEvent: KeyEvent,
onNavigateTo: (String) -> Unit,
): Boolean {
if (!keyEvent.isAltPressed || keyEvent.type != KeyEventType.KeyDown) return false
return when (keyEvent.key) {
Key.W -> {
onNavigateTo("Welcome")
true
}

Key.M -> {
onNavigateTo("Markdown")
true
}

Key.C -> {
onNavigateTo("Components")
true
}

else -> false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import org.jetbrains.jewel.samples.standalone.IntUiThemes
import org.jetbrains.jewel.samples.standalone.reflection.findViews

object MainViewModel {
fun onNavigateTo(destination: String) {
currentView = views.first { viewInfo -> viewInfo.title == destination }
}

var theme: IntUiThemes by mutableStateOf(IntUiThemes.Light)

var swingCompat: Boolean by mutableStateOf(false)
Expand Down

0 comments on commit c422bee

Please sign in to comment.