Skip to content

Commit

Permalink
Fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Oct 31, 2023
1 parent 7c3ee38 commit aadeee8
Show file tree
Hide file tree
Showing 30 changed files with 254 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,77 +28,80 @@ import java.awt.event.FocusListener
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent

fun Modifier.trackWindowActivation(window: Window) = composed(
inspectorInfo = debugInspectorInfo {
name = "activateRoot"
properties["window"] = window
},
) {
var parentActivated by remember { mutableStateOf(false) }

DisposableEffect(window) {
val listener = object : WindowAdapter() {
override fun windowActivated(e: WindowEvent?) {
parentActivated = true
public fun Modifier.trackWindowActivation(window: Window): Modifier =
composed(
inspectorInfo = debugInspectorInfo {
name = "activateRoot"
properties["window"] = window
},
) {
var parentActivated by remember { mutableStateOf(false) }

DisposableEffect(window) {
val listener = object : WindowAdapter() {
override fun windowActivated(e: WindowEvent?) {
parentActivated = true
}

override fun windowDeactivated(e: WindowEvent?) {
parentActivated = false
}
}

override fun windowDeactivated(e: WindowEvent?) {
parentActivated = false
window.addWindowListener(listener)
onDispose {
window.removeWindowListener(listener)
}
}
window.addWindowListener(listener)
onDispose {
window.removeWindowListener(listener)
Modifier.modifierLocalProvider(ModifierLocalActivated) {
parentActivated
}
}
Modifier.modifierLocalProvider(ModifierLocalActivated) {
parentActivated
}
}

fun Modifier.trackComponentActivation(awtParent: Component) = composed(
inspectorInfo = debugInspectorInfo {
name = "activateRoot"
properties["parent"] = awtParent
},
) {
var parentActivated by remember { mutableStateOf(false) }

DisposableEffect(awtParent) {
val listener = object : FocusListener {
override fun focusGained(e: FocusEvent?) {
parentActivated = true
public fun Modifier.trackComponentActivation(awtParent: Component): Modifier =
composed(
inspectorInfo = debugInspectorInfo {
name = "activateRoot"
properties["parent"] = awtParent
},
) {
var parentActivated by remember { mutableStateOf(false) }

DisposableEffect(awtParent) {
val listener = object : FocusListener {
override fun focusGained(e: FocusEvent?) {
parentActivated = true
}

override fun focusLost(e: FocusEvent?) {
parentActivated = false
}
}

override fun focusLost(e: FocusEvent?) {
parentActivated = false
awtParent.addFocusListener(listener)
onDispose {
awtParent.removeFocusListener(listener)
}
}
awtParent.addFocusListener(listener)
onDispose {
awtParent.removeFocusListener(listener)
Modifier.modifierLocalProvider(ModifierLocalActivated) {
parentActivated
}
}
Modifier.modifierLocalProvider(ModifierLocalActivated) {
parentActivated
}
}

@Stable
fun Modifier.trackActivation() = composed(
inspectorInfo = debugInspectorInfo {
name = "trackActivation"
},
) {
val activatedModifierLocal = remember { ActivatedModifierLocal() }
Modifier.focusGroup().onFocusChanged {
if (it.hasFocus) {
activatedModifierLocal.childGainedFocus()
} else {
activatedModifierLocal.childLostFocus()
}
}.then(activatedModifierLocal)
}
public fun Modifier.trackActivation(): Modifier =
composed(
inspectorInfo = debugInspectorInfo {
name = "trackActivation"
},
) {
val activatedModifierLocal = remember { ActivatedModifierLocal() }
Modifier.focusGroup().onFocusChanged {
if (it.hasFocus) {
activatedModifierLocal.childGainedFocus()
} else {
activatedModifierLocal.childLostFocus()
}
}.then(activatedModifierLocal)
}

private class ActivatedModifierLocal : ModifierLocalProvider<Boolean>, ModifierLocalConsumer {

Expand Down Expand Up @@ -126,15 +129,14 @@ private class ActivatedModifierLocal : ModifierLocalProvider<Boolean>, ModifierL
}
}

val ModifierLocalActivated = modifierLocalOf {
false
}
public val ModifierLocalActivated: ProvidableModifierLocal<Boolean> =
modifierLocalOf { false }

fun Modifier.onActivated(
public fun Modifier.onActivated(
enabled: Boolean = true,
onChanged: (Boolean) -> Unit,
) = then(
if (enabled) {
): Modifier =
this then if (enabled) {
ActivateChangedModifierElement(
onChanged,
inspectorInfo = debugInspectorInfo {
Expand All @@ -144,8 +146,7 @@ fun Modifier.onActivated(
)
} else {
Modifier
},
)
}

private class ActivateChangedModifierElement(
private val onChanged: (Boolean) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package org.jetbrains.jewel.foundation.state

public interface SelectableComponentState : InteractiveComponentState {

val isSelected: Boolean
public val isSelected: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public fun ToolWindow.addComposeTab(
contentManager.addContent(tabContent)
}

interface ToolWindowScope {
public interface ToolWindowScope {

val toolWindow: ToolWindow
public val toolWindow: ToolWindow

val panel: ComposePanel
public val panel: ComposePanel
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ private fun titleBarIconButtonStyle(
IconButtonStyle(
IconButtonColors(
foregroundSelectedActivated = Color.Unspecified,
background = Color.Unspecified,
background = Color.Unspecified,
backgroundDisabled = Color.Unspecified,
backgroundSelected = Color.Unspecified,
backgroundSelectedActivated = Color.Unspecified,
backgroundSelected = Color.Unspecified,
backgroundSelectedActivated = Color.Unspecified,
backgroundFocused = Color.Unspecified,
backgroundPressed = hoveredBackground,
backgroundHovered = pressedBackground,
border = Color.Unspecified,
borderDisabled = Color.Unspecified,
borderSelected = Color.Unspecified,
borderSelectedActivated = Color.Unspecified,
borderFocused = hoveredBackground,
borderSelectedActivated = Color.Unspecified,
borderFocused = hoveredBackground,
borderPressed = pressedBackground,
borderHovered = Color.Unspecified,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,16 @@ public object IntUiDefaultTabColorsFactory {
TabColors(
background = background,
backgroundDisabled = backgroundDisabled,
backgroundFocused = backgroundFocused,
backgroundPressed = backgroundPressed,
backgroundHovered = backgroundHovered,
backgroundSelected = backgroundSelected,
content = content,
contentDisabled = contentDisabled,
contentFocused = contentFocused,
contentPressed = contentPressed,
contentHovered = contentHovered,
contentSelected = contentSelected,
underline = underline,
underlineDisabled = underlineDisabled,
underlineFocused = underlineFocused,
underlinePressed = underlinePressed,
underlineHovered = underlineHovered,
underlineSelected = underlineSelected,
Expand All @@ -122,19 +119,16 @@ public object IntUiDefaultTabColorsFactory {
TabColors(
background = background,
backgroundDisabled = backgroundDisabled,
backgroundFocused = backgroundFocused,
backgroundPressed = backgroundPressed,
backgroundHovered = backgroundHovered,
backgroundSelected = backgroundSelected,
content = content,
contentDisabled = contentDisabled,
contentFocused = contentFocused,
contentPressed = contentPressed,
contentHovered = contentHovered,
contentSelected = contentSelected,
underline = underline,
underlineDisabled = underlineDisabled,
underlineFocused = underlineFocused,
underlinePressed = underlinePressed,
underlineHovered = underlineHovered,
underlineSelected = underlineSelected,
Expand Down Expand Up @@ -166,19 +160,16 @@ public object IntUiEditorTabColorsFactory {
TabColors(
background = background,
backgroundDisabled = backgroundDisabled,
backgroundFocused = backgroundFocused,
backgroundPressed = backgroundPressed,
backgroundHovered = backgroundHovered,
backgroundSelected = backgroundSelected,
content = content,
contentDisabled = contentDisabled,
contentFocused = contentFocused,
contentPressed = contentPressed,
contentHovered = contentHovered,
contentSelected = contentSelected,
underline = underline,
underlineDisabled = underlineDisabled,
underlineFocused = underlineFocused,
underlinePressed = underlinePressed,
underlineHovered = underlineHovered,
underlineSelected = underlineSelected,
Expand All @@ -204,19 +195,16 @@ public object IntUiEditorTabColorsFactory {
TabColors(
background = background,
backgroundDisabled = backgroundDisabled,
backgroundFocused = backgroundFocused,
backgroundPressed = backgroundPressed,
backgroundHovered = backgroundHovered,
backgroundSelected = backgroundSelected,
content = content,
contentDisabled = contentDisabled,
contentFocused = contentFocused,
contentPressed = contentPressed,
contentHovered = contentHovered,
contentSelected = contentSelected,
underline = underline,
underlineDisabled = underlineDisabled,
underlineFocused = underlineFocused,
underlinePressed = underlinePressed,
underlineHovered = underlineHovered,
underlineSelected = underlineSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum class IntUiThemes {

public companion object {

public fun fromSystemTheme(systemTheme: SystemTheme) =
public fun fromSystemTheme(systemTheme: SystemTheme): IntUiThemes =
if (systemTheme == SystemTheme.LIGHT) Light else Dark
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public fun main() {
themeDefinition,
ComponentStyling.decoratedWindow(
titleBarStyle =
when (MainViewModel.theme) {
when (MainViewModel.theme) {
IntUiThemes.Light -> TitleBarStyle.light()
IntUiThemes.LightWithLightHeader -> TitleBarStyle.lightWithLightHeader()
IntUiThemes.Dark -> TitleBarStyle.dark()
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.jetbrains.jewel.ui.painter.rememberResourcePainterProvider

@Composable
@View(title = "Components", position = 1, icon = "icons/structure.svg")
fun ComponentsView() {
public fun ComponentsView() {
Row(Modifier.trackActivation().fillMaxSize().background(JewelTheme.globalColors.paneBackground)) {
ComponentsToolBar()
Divider(Orientation.Vertical)
Expand All @@ -42,7 +42,7 @@ fun ComponentsView() {
}

@Composable
fun ComponentsToolBar() {
public fun ComponentsToolBar() {
Column(Modifier.fillMaxHeight().width(40.dp)) {
ComponentsViewModel.views.forEach {
Tooltip({
Expand All @@ -62,7 +62,7 @@ fun ComponentsToolBar() {
}

@Composable
fun ComponentView(view: ViewInfo) {
public fun ComponentView(view: ViewInfo) {
Column(Modifier.fillMaxSize().padding(24.dp), verticalArrangement = Arrangement.spacedBy(24.dp)) {
Text(view.title, fontSize = 20.sp)
view.content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.awt.Desktop
import java.net.URI

@Composable
fun DecoratedWindowScope.TitleBarView() {
public fun DecoratedWindowScope.TitleBarView() {
TitleBar(Modifier.newFullscreenControls(), gradientStartColor = MainViewModel.projectColor) {
Row(Modifier.align(Alignment.Start)) {
Dropdown(Modifier.height(30.dp), menuContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.jetbrains.jewel.ui.painter.rememberResourcePainterProvider

@Composable
@View(title = "Welcome", position = 0, icon = "icons/meetNewUi.svg")
fun WelcomeView() {
public fun WelcomeView() {
Box(
Modifier.trackActivation().fillMaxSize()
.background(JewelTheme.globalColors.paneBackground)
Expand Down Expand Up @@ -74,7 +74,7 @@ fun WelcomeView() {
}

@Composable
fun ThemeSelectionChip(theme: IntUiThemes, name: String, icon: String) {
public fun ThemeSelectionChip(theme: IntUiThemes, name: String, icon: String) {
RadioButtonChip(
selected = MainViewModel.theme == theme,
onClick = { MainViewModel.theme = theme },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package org.jetbrains.jewel.samples.standalone.viewmodel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList
import org.jetbrains.jewel.samples.standalone.reflection.findViews

object ComponentsViewModel {
public object ComponentsViewModel {

val views = findViews("org.jetbrains.jewel.samples.standalone.view.component").toMutableStateList()
public val views: SnapshotStateList<ViewInfo> =
findViews("org.jetbrains.jewel.samples.standalone.view.component")
.toMutableStateList()

var currentView by mutableStateOf(views.first())
public var currentView: ViewInfo by mutableStateOf(views.first())
}
Loading

0 comments on commit aadeee8

Please sign in to comment.