diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt index 0aeace864a..04e50248a1 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/TitleBar.Linux.kt @@ -38,13 +38,11 @@ internal fun DecoratedWindowScope.TitleBarOnLinux( val viewConfig = LocalViewConfiguration.current TitleBarImpl( modifier.onPointerEvent(PointerEventType.Press, PointerEventPass.Main) { - if ( - this.currentEvent.button == PointerButton.Primary && + if (this.currentEvent.button == PointerButton.Primary && this.currentEvent.changes.any { changed -> !changed.isConsumed } ) { JBR.getWindowMove()?.startMovingTogetherWithMouse(window, MouseEvent.BUTTON1) - if ( - System.currentTimeMillis() - lastPress in + if (System.currentTimeMillis() - lastPress in viewConfig.doubleTapMinTimeMillis..viewConfig.doubleTapTimeoutMillis ) { if (state.isMaximized) { @@ -97,7 +95,14 @@ private fun TitleBarScope.CloseButton( state: DecoratedWindowState, style: TitleBarStyle = JewelTheme.defaultTitleBarStyle, ) { - ControlButton(onClick, state, style.icons.closeButton, "Close", style, style.paneCloseButtonStyle) + ControlButton( + onClick, + state, + style.icons.closeButton, + "Close", + style, + style.paneCloseButtonStyle, + ) } @Composable diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/DecoratedWindowStyling.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/DecoratedWindowStyling.kt index 005cae130e..cc15f5ac62 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/DecoratedWindowStyling.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/DecoratedWindowStyling.kt @@ -48,4 +48,6 @@ public class DecoratedWindowMetrics(public val borderWidth: Dp) { } public val LocalDecoratedWindowStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No DecoratedWindowStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No DecoratedWindowStyle provided. Have you forgotten the theme?") + } diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/TitleBarStyling.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/TitleBarStyling.kt index ab2ee27117..ca0d907f2c 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/TitleBarStyling.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/styling/TitleBarStyling.kt @@ -97,4 +97,6 @@ public class TitleBarIcons( } public val LocalTitleBarStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No TitleBarStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No TitleBarStyle provided. Have you forgotten the theme?") + } diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/Foundation.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/Foundation.kt index e634f0c5b9..94caa0c660 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/Foundation.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/Foundation.kt @@ -66,11 +66,12 @@ internal object Foundation { ID(myObjcMsgSend?.invokeLong(prepInvoke(id, selector, args)) ?: 0) /** - * Invokes the given vararg selector. Expects `NSArray arrayWithObjects:(id), ...` like signature, - * i.e. exactly one fixed argument, followed by varargs. + * Invokes the given vararg selector. Expects `NSArray arrayWithObjects:(id), ...` like signature, i.e., + * exactly one fixed argument, followed by varargs. */ public fun invokeVarArg(id: ID?, selector: Pointer?, vararg args: Any?): ID { - // c functions and objc methods have at least 1 fixed argument, we therefore need to separate + // c functions and objc methods have at least 1 fixed argument, we therefore need to + // separate // out the first argument return myFoundationLibrary?.objc_msgSend( id, diff --git a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt index d87e26b77e..0c544d6252 100644 --- a/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt +++ b/decorated-window/src/main/kotlin/org/jetbrains/jewel/window/utils/macos/MacUtil.kt @@ -74,8 +74,7 @@ internal object MacUtil { SwingUtilities.invokeLater { val window = getWindowFromJavaWindow(w) val delegate = Foundation.invoke(window, "delegate") - if ( - Foundation.invoke( + if (Foundation.invoke( delegate, "respondsToSelector:", Foundation.createSelector("updateColors"), diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalColors.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalColors.kt index 267e3157b2..6d941f6703 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalColors.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalColors.kt @@ -42,4 +42,6 @@ public class OutlineColors( } public val LocalGlobalColors: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No GlobalColors provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No GlobalColors provided. Have you forgotten the theme?") + } diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalMetrics.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalMetrics.kt index 2f4ada838d..1438c785c6 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalMetrics.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/GlobalMetrics.kt @@ -16,4 +16,6 @@ public class GlobalMetrics( } public val LocalGlobalMetrics: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No GlobalMetrics provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No GlobalMetrics provided. Have you forgotten the theme?") + } diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt index 6cf5b96b68..13490b095f 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt @@ -38,7 +38,8 @@ public interface SelectableColumnOnKeyEvent { } if (list.isNotEmpty()) { state.selectedKeys = - state.selectedKeys.toMutableList().also { selectionList -> selectionList.addAll(list) } + state.selectedKeys.toMutableList() + .also { selectionList -> selectionList.addAll(list) } } } } @@ -192,9 +193,9 @@ public interface SelectableColumnOnKeyEvent { val visibleSize = state.layoutInfo.visibleItemsInfo.size val targetIndex = min((state.lastActiveItemIndex ?: 0) + visibleSize, keys.lastIndex) val newSelectionList = - keys.subList(state.lastActiveItemIndex ?: 0, targetIndex).filterIsInstance().let { - state.selectedKeys + it.map { selectableKey -> selectableKey.key } - } + keys.subList(state.lastActiveItemIndex ?: 0, targetIndex) + .filterIsInstance() + .let { state.selectedKeys + it.map { selectableKey -> selectableKey.key } } state.selectedKeys = newSelectionList state.lastActiveItemIndex = targetIndex } diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt index 09ed9da3f5..78e7a62b4e 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt @@ -70,7 +70,8 @@ public fun SelectableLazyColumn( .onPreviewKeyEvent { event -> if (state.lastActiveItemIndex != null) { val actionHandled = - keyActions.handleOnKeyEvent(event, keys, state, selectionMode).invoke(event) + keyActions.handleOnKeyEvent(event, keys, state, selectionMode) + .invoke(event) if (actionHandled) { scope.launch { state.lastActiveItemIndex?.let { state.scrollToItem(it) } } } @@ -120,6 +121,7 @@ public fun SelectableLazyColumn( ) { index -> val itemScope = SelectableLazyItemScope(entry.key(index) in state.selectedKeys, isFocused) + if (keys.any { it.key == entry.key(index) && it is SelectableLazyListKey.Selectable }) { Box( modifier = @@ -142,6 +144,7 @@ public fun SelectableLazyColumn( is Entry.StickyHeader -> stickyHeader(entry.key, entry.contentType) { val itemScope = SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused) + if (keys.any { it.key == entry.key && it is SelectableLazyListKey.Selectable }) { Box( modifier = @@ -157,9 +160,8 @@ public fun SelectableLazyColumn( entry.content.invoke(itemScope) } } else { - SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused).apply { - entry.content.invoke(itemScope) - } + SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused) + .apply { entry.content.invoke(itemScope) } } } } diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListScope.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListScope.kt index a3a92e1062..61828cc20e 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListScope.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListScope.kt @@ -28,13 +28,14 @@ public interface SelectableLazyListScope { * Represents a list of items based on the provided parameters. * * @param count The number of items in the list. - * @param key A function that generates a unique key for each item based on its index. - * @param contentType A function that returns the content type of an item based on its index. - * Defaults to `null`. - * @param selectable A function that determines if an item is selectable based on its index. - * Defaults to `true`. - * @param itemContent The content of each individual item, specified as a composable function that - * takes the item's index as a parameter. + * @param key A function that generates a unique key for each item based on + * its index. + * @param contentType A function that returns the content type of an item + * based on its index. Defaults to `null`. + * @param selectable A function that determines if an item is selectable + * based on its index. Defaults to `true`. + * @param itemContent The content of each individual item, specified as a + * composable function that takes the item's index as a parameter. */ public fun items( count: Int, diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListState.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListState.kt index 58c2562ceb..f10c4ec496 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListState.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyListState.kt @@ -58,7 +58,11 @@ public class SelectableLazyListState( scrollOffset, ) itemIndex > visibleRange.last() -> { - lazyListState.scrollToItem(max(itemIndex - (visibleRange.size + 2), 0), animateScroll, 0) + lazyListState.scrollToItem( + index = max(itemIndex - (visibleRange.size + 2), 0), + animate = animateScroll, + scrollOffset = 0, + ) } } } @@ -68,7 +72,9 @@ public class SelectableLazyListState( public val layoutInfo: LazyListLayoutInfo get() = lazyListState.layoutInfo - /** The index of the first item that is visible */ + /** + * The index of the first item that is visible + */ public val firstVisibleItemIndex: Int get() = lazyListState.firstVisibleItemIndex @@ -81,168 +87,12 @@ public class SelectableLazyListState( get() = lazyListState.firstVisibleItemScrollOffset /** - * [InteractionSource] that will be used to dispatch drag events when this list is being dragged. - * If you want to know whether the fling (or animated scroll) is in progress, use - * [isScrollInProgress]. + * [InteractionSource] that will be used to dispatch drag events when + * this list is being dragged. If you want to know whether the fling + * (or animated scroll) is in progress, use [isScrollInProgress]. */ public val interactionSource: InteractionSource get() = lazyListState.interactionSource - - // selection handling - // fun indexOfNextSelectable(currentIndex: Int): Int? { - // if (currentIndex + 1 > internalKeys.lastIndex) return null - // for (i in currentIndex + 1..internalKeys.lastIndex) { // todo iterate with instanceOF - // if (internalKeys[i] is Key.Selectable) return i - // } - // return null - // } - // - // fun indexOfPreviousSelectable(currentIndex: Int): Int? { - // if (currentIndex - 1 < 0) return null - // for (i in currentIndex - 1 downTo 0) { - // if (internalKeys[i] is Key.Selectable) return i - // } - // return null - // } - // - // /** - // * Selects a single item at the specified index within the lazy list. - // * - // * @param itemIndex The index of the item to select. - // * @param changeFocus Whether to change the focus to the selected item. - // * @param skipScroll Whether to skip the scroll to the selected item. - // */ - // suspend fun selectSingleItem(itemIndex: Int, changeFocus: Boolean = true, skipScroll: - // Boolean = false) { - // if (changeFocus) scrollToItem(itemIndex, skipScroll = skipScroll) - // selectedIdsMap.clear() - // selectedIdsMap[keys[itemIndex]] = itemIndex - // lastSelectedIndex = itemIndex - // } - // - // /** - // * Selects a single item with the specified key within the lazy list. - // * - // * @param key The key of the item to select. - // * @param changeFocus Whether to change the focus to the selected item. - // * @param skipScroll Whether to skip the scroll to the selected item. - // */ - // suspend fun selectSingleKey(key: Any, changeFocus: Boolean = true, skipScroll: Boolean = - // false) { - // val index = internalKeys.indexOfFirst { it.key == key } - // if (index >= 0 && internalKeys[index] is Key.Selectable) selectSingleItem(index, - // changeFocus, skipScroll = skipScroll) - // lastSelectedIndex = index - // } - // - // suspend fun deselectSingleElement(itemIndex: Int, changeFocus: Boolean = true, skipScroll: - // Boolean = false) { - // if (changeFocus) scrollToItem(itemIndex, skipScroll = skipScroll) - // selectedIdsMap.remove(keys[itemIndex]) - // } - // - // suspend fun toggleSelection(itemIndex: Int, skipScroll: Boolean = false) { - // if (selectionMode == SelectionMode.None) return - // selectedIdsMap[keys[itemIndex]]?.let { - // deselectSingleElement(itemIndex) - // } ?: if (!isMultiSelectionAllowed) { - // selectSingleItem(itemIndex, skipScroll = skipScroll) - // } else { - // addElementToSelection(itemIndex, skipScroll = skipScroll) - // } - // } - // - // suspend fun toggleSelectionKey(key: Any, skipScroll: Boolean = false) { - // if (selectionMode == SelectionMode.None) return - // val index = internalKeys.indexOfFirst { it.key == key } - // if (index > 0 && internalKeys[index] is Key.Selectable) toggleSelection(index, - // skipScroll = skipScroll) - // lastSelectedIndex = index - // } - // - // suspend fun onExtendSelectionToIndex(itemIndex: Int, changeFocus: Boolean = true, - // skipScroll: Boolean = false) { - // if (selectionMode == SelectionMode.None) return - // if (!isMultiSelectionAllowed) { - // selectSingleItem(itemIndex, skipScroll = skipScroll) - // } else { - // val lastFocussed = lastSelectedIndex ?: itemIndex - // val indexInterval = if (itemIndex > lastFocussed) { - // lastFocussed..itemIndex - // } else { - // lastFocussed downTo itemIndex - // } - // addElementsToSelection(indexInterval.toList()) - // if (changeFocus) scrollToItem(itemIndex, skipScroll = skipScroll) - // } - // } - // - // @Suppress("unused") - // internal fun addKeyToSelectionMap(keyIndex: Int) { - // if (selectionMode == SelectionMode.None) return - // if (internalKeys[keyIndex] is Key.Selectable) { - // selectedIdsMap[keys[keyIndex]] = keyIndex - // } - // } - // - // suspend fun addElementToSelection(itemIndex: Int, changeFocus: Boolean = true, skipScroll: - // Boolean = false) { - // if (selectionMode == SelectionMode.None) return - // if (!isMultiSelectionAllowed) { - // selectSingleItem(itemIndex, false) - // } else { - // selectedIdsMap[keys[itemIndex]] = itemIndex - // } - // if (changeFocus) scrollToItem(itemIndex, skipScroll = skipScroll) - // lastSelectedIndex = itemIndex - // } - // - // fun deselectAll() { - // if (selectionMode == SelectionMode.None) return - // selectedIdsMap.clear() - // lastSelectedIndex = null - // } - // - // suspend fun addElementsToSelection(itemIndexes: List, itemToFocus: Int? = - // itemIndexes.lastOrNull()) { - // if (selectionMode == SelectionMode.None) return - // if (!isMultiSelectionAllowed) { - // itemIndexes.lastOrNull()?.let { selectSingleItem(it) } - // } else { - // itemIndexes.forEach { - // selectedIdsMap[keys[it]] = it - // } - // itemToFocus?.let { scrollToItem(it) } - // lastSelectedIndex = itemIndexes.lastOrNull() - // } - // } - // - // @Suppress("unused") - // suspend fun removeElementsToSelection(itemIndexes: List, itemToFocus: Int? = - // itemIndexes.lastOrNull()) { - // if (selectionMode == SelectionMode.None) return - // itemIndexes.forEach { - // selectedIdsMap.remove(keys[it]) - // } - // itemToFocus?.let { scrollToItem(it) } - // } - // - // @Suppress("Unused") - // suspend fun toggleElementsToSelection(itemIndexes: List, itemToFocus: Int? = - // itemIndexes.lastOrNull()) { - // if (selectionMode == SelectionMode.None) return - // if (!isMultiSelectionAllowed) { - // toggleSelection(itemIndexes.last()) - // } else { - // itemIndexes.forEach { index -> - // selectedIdsMap[keys[index]]?.let { - // selectedIdsMap.remove(keys[index]) - // } ?: { selectedIdsMap[keys[index]] = index } - // } - // itemToFocus?.let { scrollToItem(it) } - // lastSelectedIndex = itemIndexes.lastOrNull() - // } - // } } private suspend fun LazyListState.scrollToItem( @@ -257,10 +107,14 @@ private suspend fun LazyListState.scrollToItem( } } -/** Represents a selectable key used in a selectable lazy list. */ +/** + * Represents a selectable key used in a selectable lazy list. + */ public sealed class SelectableLazyListKey { - /** The key associated with the item. */ + /** + * The key associated with the item. + */ public abstract val key: Any /** @@ -299,16 +153,24 @@ public interface SelectableLazyItemScope : LazyItemScope { public val isActive: Boolean } -/** Specifies the selection mode for a selectable lazy list. */ +/** + * Specifies the selection mode for a selectable lazy list. + */ public enum class SelectionMode { - /** No selection is allowed. */ + /** + * No selection is allowed. + */ None, - /** Only a single item can be selected. */ + /** + * Only a single item can be selected. + */ Single, - /** Multiple items can be selected. */ + /** + * Multiple items can be selected. + */ Multiple, } diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt index 96c38e5bee..234684ad7e 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt @@ -136,7 +136,9 @@ public fun BasicLazyTree( TreeElementState.of( active = isActive, selected = isSelected, - expanded = (element as? Tree.Element.Node)?.let { it.id in treeState.openNodes } ?: false, + expanded = (element as? Tree.Element.Node) + ?.let { it.id in treeState.openNodes } + ?: false, ) val backgroundShape by remember { @@ -160,13 +162,14 @@ public fun BasicLazyTree( interactionSource = remember { MutableInteractionSource() }, indication = null, ) { - (pointerEventScopedActions as? DefaultTreeViewPointerEventAction)?.notifyItemClicked( - item = flattenedTree[index] as Tree.Element, - scope = scope, - doubleClickTimeDelayMillis = platformDoubleClickDelay.inWholeMilliseconds, - onElementClick = onElementClick, - onElementDoubleClick = onElementDoubleClick, - ) + (pointerEventScopedActions as? DefaultTreeViewPointerEventAction) + ?.notifyItemClicked( + item = flattenedTree[index] as Tree.Element, + scope = scope, + doubleClickTimeDelayMillis = platformDoubleClickDelay.inWholeMilliseconds, + onElementClick = onElementClick, + onElementDoubleClick = onElementDoubleClick, + ) treeState.delegate.lastActiveItemIndex = index }, ) { diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BuildTree.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BuildTree.kt index 7aa98c316a..bfcb47c456 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BuildTree.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BuildTree.kt @@ -45,36 +45,43 @@ public class TreeBuilder : TreeGeneratorScope { public fun build(): Tree { val elements = mutableListOf>() for (index in heads.indices) { - val previous: Tree.Element? = elements.getOrNull(index - 1)?.let { evaluatePrevious(it) } - val current = - when (val elementBuilder = heads[index]) { - is Element.Leaf -> - Tree.Element.Leaf( - data = elementBuilder.data, - depth = 0, - childIndex = index, - parent = null, - previous = previous, - next = null, - id = elementBuilder.id ?: "$index", - ) - is Element.Node -> - Tree.Element.Node( - data = elementBuilder.data, - depth = 0, - childIndex = index, - parent = null, - childrenGenerator = { parent -> generateElements(parent, elementBuilder) }, - previous = previous, - next = null, - id = elementBuilder.id ?: "$index", - ) - } + val previous: Tree.Element? = elements.getOrNull(index - 1) + ?.let { evaluatePrevious(it) } + + val current = getCurrentTreeElement(index, previous) elements.add(current) previous?.also { it.next = current } } return Tree(elements) } + + private fun getCurrentTreeElement(index: Int, previous: Tree.Element?) = + when (val elementBuilder = heads[index]) { + is Element.Leaf -> + Tree.Element.Leaf( + data = elementBuilder.data, + depth = 0, + childIndex = index, + parent = null, + previous = previous, + next = null, + id = elementBuilder.id ?: "$index", + ) + + is Element.Node -> + Tree.Element.Node( + data = elementBuilder.data, + depth = 0, + childIndex = index, + parent = null, + childrenGenerator = { parent -> + generateElements(parent, elementBuilder) + }, + previous = previous, + next = null, + id = elementBuilder.id ?: "$index", + ) + } } private fun generateElements( diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/DefaultTreeViewOnKeyEvent.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/DefaultTreeViewOnKeyEvent.kt index 81c15ff167..7779497fbe 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/DefaultTreeViewOnKeyEvent.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/DefaultTreeViewOnKeyEvent.kt @@ -69,7 +69,10 @@ public open class DefaultTreeViewOnKeyEvent( override fun onSelectChild(keys: List, state: SelectableLazyListState) { val currentKey = keys[state.lastActiveItemIndex ?: 0].key - if (currentKey in treeState.allNodes.map { it.first } && currentKey !in treeState.openNodes) { + if ( + currentKey in treeState.allNodes.map { it.first } && + currentKey !in treeState.openNodes + ) { treeState.toggleNode(currentKey) } else { super.onSelectNextItem(keys, state) diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/Tree.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/Tree.kt index a8ec6fda96..d36244a935 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/Tree.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/Tree.kt @@ -117,7 +117,9 @@ public class Tree internal constructor(public val roots: List>) { public fun close() { detachChildren() - children?.asSequence()?.filterIsInstance>()?.forEach { it.closeRecursively() } + children?.asSequence() + ?.filterIsInstance>() + ?.forEach { it.closeRecursively() } } private fun closeRecursively() { diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Activation.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Activation.kt index 8a45645b5b..b67ff3c943 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Activation.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Activation.kt @@ -30,7 +30,7 @@ import java.awt.event.WindowEvent public fun Modifier.trackWindowActivation(window: Window): Modifier = composed( - inspectorInfo = debugInspectorInfo { + debugInspectorInfo { name = "activateRoot" properties["window"] = window }, @@ -48,18 +48,14 @@ public fun Modifier.trackWindowActivation(window: Window): Modifier = } } window.addWindowListener(listener) - onDispose { - window.removeWindowListener(listener) - } - } - Modifier.modifierLocalProvider(ModifierLocalActivated) { - parentActivated + onDispose { window.removeWindowListener(listener) } } + Modifier.modifierLocalProvider(ModifierLocalActivated) { parentActivated } } public fun Modifier.trackComponentActivation(awtParent: Component): Modifier = composed( - inspectorInfo = debugInspectorInfo { + debugInspectorInfo { name = "activateRoot" properties["parent"] = awtParent }, @@ -77,30 +73,27 @@ public fun Modifier.trackComponentActivation(awtParent: Component): Modifier = } } awtParent.addFocusListener(listener) - onDispose { - awtParent.removeFocusListener(listener) - } - } - Modifier.modifierLocalProvider(ModifierLocalActivated) { - parentActivated + onDispose { awtParent.removeFocusListener(listener) } } + + Modifier.modifierLocalProvider(ModifierLocalActivated) { parentActivated } } @Stable public fun Modifier.trackActivation(): Modifier = composed( - inspectorInfo = debugInspectorInfo { - name = "trackActivation" - }, + inspectorInfo = debugInspectorInfo { name = "trackActivation" }, ) { val activatedModifierLocal = remember { ActivatedModifierLocal() } - Modifier.focusGroup().onFocusChanged { - if (it.hasFocus) { - activatedModifierLocal.childGainedFocus() - } else { - activatedModifierLocal.childLostFocus() + Modifier.focusGroup() + .onFocusChanged { + if (it.hasFocus) { + activatedModifierLocal.childGainedFocus() + } else { + activatedModifierLocal.childLostFocus() + } } - }.then(activatedModifierLocal) + .then(activatedModifierLocal) } private class ActivatedModifierLocal : ModifierLocalProvider, ModifierLocalConsumer { @@ -110,9 +103,7 @@ private class ActivatedModifierLocal : ModifierLocalProvider, ModifierL private var hasFocus: Boolean by mutableStateOf(false) override fun onModifierLocalsUpdated(scope: ModifierLocalReadScope) { - with(scope) { - parentActivated = ModifierLocalActivated.current - } + with(scope) { parentActivated = ModifierLocalActivated.current } } override val key: ProvidableModifierLocal = ModifierLocalActivated @@ -129,8 +120,7 @@ private class ActivatedModifierLocal : ModifierLocalProvider, ModifierL } } -public val ModifierLocalActivated: ProvidableModifierLocal = - modifierLocalOf { false } +public val ModifierLocalActivated: ProvidableModifierLocal = modifierLocalOf { false } public fun Modifier.onActivated( enabled: Boolean = true, diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Border.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Border.kt index fcd678e537..42f0e9c968 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Border.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/modifier/Border.kt @@ -186,10 +186,11 @@ private class BorderCache( var targetImageBitmap = imageBitmap var targetCanvas = canvas val compatibleConfig = - targetImageBitmap?.config == ImageBitmapConfig.Argb8888 || config == targetImageBitmap?.config + targetImageBitmap?.config == ImageBitmapConfig.Argb8888 || + config == targetImageBitmap?.config + @Suppress("ComplexCondition") - if ( - targetImageBitmap == null || + if (targetImageBitmap == null || targetCanvas == null || size.width > targetImageBitmap.width || size.height > targetImageBitmap.height || diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/theme/JewelTheme.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/theme/JewelTheme.kt index 5db3e67673..0e2a726f7c 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/theme/JewelTheme.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/theme/JewelTheme.kt @@ -66,15 +66,20 @@ public fun JewelTheme(theme: ThemeDefinition, content: @Composable () -> Unit) { } public val LocalContentColor: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No ContentColor provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No ContentColor provided. Have you forgotten the theme?") + } -internal val LocalIsDarkTheme = - staticCompositionLocalOf { error("No IsDarkTheme provided. Have you forgotten the theme?") } +internal val LocalIsDarkTheme: ProvidableCompositionLocal = + staticCompositionLocalOf { + error("No IsDarkTheme provided. Have you forgotten the theme?") + } -internal val LocalSwingCompatMode = staticCompositionLocalOf { - // By default, Swing compat is not enabled - false -} +internal val LocalSwingCompatMode: ProvidableCompositionLocal = + staticCompositionLocalOf { + // By default, Swing compat is not enabled + false + } public val LocalColorPalette: ProvidableCompositionLocal = staticCompositionLocalOf { @@ -86,9 +91,13 @@ public val LocalIconData: ProvidableCompositionLocal = staticComp } public val LocalTextStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No TextStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No TextStyle provided. Have you forgotten the theme?") + } -/** Overrides the dark mode for the current composition scope. */ +/** + * Overrides the dark mode for the current composition scope. + */ @Composable public fun OverrideDarkMode(isDark: Boolean, content: @Composable () -> Unit) { CompositionLocalProvider(LocalIsDarkTheme provides isDark, content = content) diff --git a/ide-laf-bridge/api/ide-laf-bridge.api b/ide-laf-bridge/api/ide-laf-bridge.api index d8a07e4fb8..8df0d285ac 100644 --- a/ide-laf-bridge/api/ide-laf-bridge.api +++ b/ide-laf-bridge/api/ide-laf-bridge.api @@ -7,6 +7,7 @@ public final class org/jetbrains/jewel/bridge/BridgeUtilsKt { public static synthetic fun createVerticalBrush-8A-3gB4$default (Ljava/util/List;FFIILjava/lang/Object;)Landroidx/compose/ui/graphics/Brush; public static final fun getDp (Lcom/intellij/util/ui/JBValue;)F public static final fun retrieveArcAsCornerSize (Ljava/lang/String;)Landroidx/compose/foundation/shape/CornerSize; + public static final fun retrieveArcAsCornerSizeOrDefault (Ljava/lang/String;Landroidx/compose/foundation/shape/CornerSize;)Landroidx/compose/foundation/shape/CornerSize; public static final fun retrieveArcAsCornerSizeWithFallbacks ([Ljava/lang/String;)Landroidx/compose/foundation/shape/CornerSize; public static final fun retrieveColorOrNull (Ljava/lang/String;)Landroidx/compose/ui/graphics/Color; public static final fun retrieveColorOrUnspecified (Ljava/lang/String;)J diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt index fe66c4407e..40bd7d86d7 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.isUnspecified import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.takeOrElse import com.intellij.ide.ui.UISettingsUtils @@ -134,6 +135,12 @@ public fun JBDimension.toDpSize(): DpSize { public fun retrieveArcAsCornerSize(key: String): CornerSize = CornerSize(retrieveIntAsDp(key) / 2) +public fun retrieveArcAsCornerSizeOrDefault(key: String, default: CornerSize): CornerSize { + val intValue = retrieveIntAsDpOrUnspecified(key) + if (intValue.isUnspecified) return default + return CornerSize(intValue / 2) +} + public fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize { for (key in keys) { val rawValue = UIManager.get(key) diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeService.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeService.kt index e51c5d5137..703e4e9c77 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeService.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeService.kt @@ -2,15 +2,9 @@ package org.jetbrains.jewel.bridge import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Density -import com.intellij.openapi.Disposable import com.intellij.openapi.components.Service import com.intellij.openapi.components.Service.Level -import com.intellij.openapi.diagnostic.thisLogger -import com.intellij.ui.NewUI -import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -23,18 +17,12 @@ import org.jetbrains.jewel.ui.ComponentStyling import kotlin.time.Duration.Companion.milliseconds @Service(Level.APP) -internal class SwingBridgeService : Disposable { - - private val logger = thisLogger() - - // TODO use constructor injection when min IJ is 232+ - private val coroutineScope: CoroutineScope = - CoroutineScope(SupervisorJob() + CoroutineName("JewelSwingBridge")) +internal class SwingBridgeService(scope: CoroutineScope) { internal val currentBridgeThemeData: StateFlow = - IntelliJApplication.lookAndFeelChangedFlow(coroutineScope) + IntelliJApplication.lookAndFeelChangedFlow(scope) .mapLatest { tryGettingThemeData() } - .stateIn(coroutineScope, SharingStarted.Eagerly, BridgeThemeData.DEFAULT) + .stateIn(scope, SharingStarted.Eagerly, BridgeThemeData.DEFAULT) private suspend fun tryGettingThemeData(): BridgeThemeData { var counter = 0 @@ -50,12 +38,6 @@ internal class SwingBridgeService : Disposable { } private suspend fun readThemeData(): BridgeThemeData { - val isIntUi = NewUI.isEnabled() - if (!isIntUi) { - // TODO return Darcula/IntelliJ Light theme instead - logger.warn("Darcula LaFs (aka \"old UI\") are not supported yet, falling back to Int UI") - } - val themeDefinition = createBridgeThemeDefinition() return BridgeThemeData( themeDefinition = createBridgeThemeDefinition(), @@ -64,10 +46,6 @@ internal class SwingBridgeService : Disposable { ) } - override fun dispose() { - coroutineScope.cancel("Disposing Application...") - } - internal data class BridgeThemeData( val themeDefinition: ThemeDefinition, val componentStyling: ComponentStyling, @@ -78,6 +56,7 @@ internal class SwingBridgeService : Disposable { val DEFAULT = run { val themeDefinition = createBridgeThemeDefinition(TextStyle.Default) + BridgeThemeData( themeDefinition = createBridgeThemeDefinition(TextStyle.Default), componentStyling = diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt index c6a4d095bd..d3fa7d91a8 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt @@ -22,9 +22,7 @@ public fun ToolWindow.addComposeTab( override val panel: ComposePanel = composePanel } - composePanel.setContent { - scope.content() - } + composePanel.setContent { scope.content() } val tabContent = contentManager.factory.createContent(composePanel, tabDisplayName, isLockable) tabContent.isCloseable = isCloseable contentManager.addContent(tabContent) diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/IntUiBridge.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/IntUiBridge.kt index d769ef790b..bf7bc407be 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/IntUiBridge.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/IntUiBridge.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.shape.CornerSize import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.graphics.isSpecified import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.DpOffset @@ -15,7 +14,6 @@ import com.intellij.ide.ui.laf.darcula.DarculaUIUtil import com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI import com.intellij.ide.ui.laf.intellij.IdeaPopupMenuUI import com.intellij.openapi.diagnostic.Logger -import com.intellij.openapi.util.registry.Registry import com.intellij.ui.JBColor import com.intellij.util.ui.DirProvider import com.intellij.util.ui.JBUI @@ -24,6 +22,7 @@ import org.jetbrains.jewel.bridge.bridgePainterProvider import org.jetbrains.jewel.bridge.createVerticalBrush import org.jetbrains.jewel.bridge.dp import org.jetbrains.jewel.bridge.readFromLaF +import org.jetbrains.jewel.bridge.retrieveArcAsCornerSizeOrDefault import org.jetbrains.jewel.bridge.retrieveArcAsCornerSizeWithFallbacks import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified import org.jetbrains.jewel.bridge.retrieveColorsOrUnspecified @@ -146,7 +145,6 @@ internal suspend fun createBridgeComponentStyling( textFieldTextStyle = retrieveTextStyle("TextField.font", "TextField.foreground"), textAreaTextStyle = retrieveTextStyle("TextArea.font", "TextArea.foreground"), dropdownTextStyle = retrieveTextStyle("ComboBox.font"), - linkTextStyle = retrieveTextStyle("Label.font"), ) @@ -188,21 +186,17 @@ internal fun createBridgeComponentStyling( } private fun readDefaultButtonStyle(): ButtonStyle { - val normalBackground = - listOf( - JBUI.CurrentTheme.Button.defaultButtonColorStart().toComposeColor(), - JBUI.CurrentTheme.Button.defaultButtonColorEnd().toComposeColor(), - ) - .createVerticalBrush() + val normalBackground = listOf( + JBUI.CurrentTheme.Button.defaultButtonColorStart().toComposeColor(), + JBUI.CurrentTheme.Button.defaultButtonColorEnd().toComposeColor(), + ).createVerticalBrush() val normalContent = retrieveColorOrUnspecified("Button.default.foreground") - val normalBorder = - listOf( - JBUI.CurrentTheme.Button.buttonOutlineColorStart(true).toComposeColor(), - JBUI.CurrentTheme.Button.buttonOutlineColorEnd(true).toComposeColor(), - ) - .createVerticalBrush() + val normalBorder = listOf( + JBUI.CurrentTheme.Button.buttonOutlineColorStart(true).toComposeColor(), + JBUI.CurrentTheme.Button.buttonOutlineColorEnd(true).toComposeColor(), + ).createVerticalBrush() val colors = ButtonColors( @@ -225,8 +219,7 @@ private fun readDefaultButtonStyle(): ButtonStyle { return ButtonStyle( colors = colors, - metrics = - ButtonMetrics( + metrics = ButtonMetrics( cornerSize = retrieveArcAsCornerSizeWithFallbacks("Button.default.arc", "Button.arc"), padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp, DarculaUIUtil.MINIMUM_HEIGHT.dp), @@ -236,40 +229,35 @@ private fun readDefaultButtonStyle(): ButtonStyle { } private fun readOutlinedButtonStyle(): ButtonStyle { - val normalBackground = - listOf( - JBUI.CurrentTheme.Button.buttonColorStart().toComposeColor(), - JBUI.CurrentTheme.Button.buttonColorEnd().toComposeColor(), - ) - .createVerticalBrush() + val normalBackground = listOf( + JBUI.CurrentTheme.Button.buttonColorStart().toComposeColor(), + JBUI.CurrentTheme.Button.buttonColorEnd().toComposeColor(), + ).createVerticalBrush() val normalContent = retrieveColorOrUnspecified("Button.foreground") - val normalBorder = - listOf( - JBUI.CurrentTheme.Button.buttonOutlineColorStart(false).toComposeColor(), - JBUI.CurrentTheme.Button.buttonOutlineColorEnd(false).toComposeColor(), - ) - .createVerticalBrush() - - val colors = - ButtonColors( - background = normalBackground, - backgroundDisabled = SolidColor(Color.Transparent), - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = normalBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("Button.disabledText"), - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - border = normalBorder, - borderDisabled = SolidColor(JBUI.CurrentTheme.Button.disabledOutlineColor().toComposeColor()), - borderFocused = SolidColor(JBUI.CurrentTheme.Button.focusBorderColor(false).toComposeColor()), - borderPressed = normalBorder, - borderHovered = normalBorder, - ) + val normalBorder = listOf( + JBUI.CurrentTheme.Button.buttonOutlineColorStart(false).toComposeColor(), + JBUI.CurrentTheme.Button.buttonOutlineColorEnd(false).toComposeColor(), + ).createVerticalBrush() + + val colors = ButtonColors( + background = normalBackground, + backgroundDisabled = SolidColor(Color.Transparent), + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = normalBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("Button.disabledText"), + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + border = normalBorder, + borderDisabled = SolidColor(JBUI.CurrentTheme.Button.disabledOutlineColor().toComposeColor()), + borderFocused = SolidColor(JBUI.CurrentTheme.Button.focusBorderColor(false).toComposeColor()), + borderPressed = normalBorder, + borderHovered = normalBorder, + ) return ButtonStyle( colors = colors, @@ -285,28 +273,22 @@ private fun readOutlinedButtonStyle(): ButtonStyle { private fun readCheckboxStyle(): CheckboxStyle { val textColor = retrieveColorOrUnspecified("CheckBox.foreground") - val colors = - CheckboxColors( - content = textColor, - contentDisabled = retrieveColorOrUnspecified("CheckBox.disabledText"), - contentSelected = textColor, - ) + val colors = CheckboxColors( + content = textColor, + contentDisabled = retrieveColorOrUnspecified("CheckBox.disabledText"), + contentSelected = textColor, + ) return CheckboxStyle( colors = colors, - metrics = - CheckboxMetrics( - checkboxSize = - DarculaCheckBoxUI().defaultIcon.let { DpSize(it.iconWidth.dp, it.iconHeight.dp) }, + metrics = CheckboxMetrics( + checkboxSize = DarculaCheckBoxUI().defaultIcon.let { DpSize(it.iconWidth.dp, it.iconHeight.dp) }, checkboxCornerSize = CornerSize(3.dp), // See DarculaCheckBoxUI#drawCheckIcon outlineSize = DpSize(15.dp, 15.dp), // Extrapolated from SVG outlineOffset = DpOffset(2.5.dp, 1.5.dp), // Extrapolated from SVG iconContentGap = 5.dp, // See DarculaCheckBoxUI#textIconGap ), - icons = - CheckboxIcons( - checkbox = bridgePainterProvider("${iconsBasePath}checkBox.svg"), - ), + icons = CheckboxIcons(checkbox = bridgePainterProvider("${iconsBasePath}checkBox.svg")), ) } @@ -325,43 +307,42 @@ private fun readChipStyle(): ChipStyle { val disabledBorder = retrieveColorOrUnspecified("Button.disabledBorderColor") val selectedBorder = retrieveColorOrUnspecified("Component.focusColor") - val colors = - ChipColors( - background = normalBackground, - backgroundDisabled = normalBackground, - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = normalBackground, - backgroundSelected = normalBackground, - backgroundSelectedDisabled = normalBackground, - backgroundSelectedPressed = normalBackground, - backgroundSelectedFocused = normalBackground, - backgroundSelectedHovered = normalBackground, - content = normalContent, - contentDisabled = normalContent, - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - contentSelected = normalContent, - contentSelectedDisabled = normalContent, - contentSelectedPressed = normalContent, - contentSelectedFocused = normalContent, - contentSelectedHovered = normalContent, - border = normalBorder, - borderDisabled = disabledBorder, - borderFocused = normalBorder, - borderPressed = normalBorder, - borderHovered = normalBorder, - borderSelected = selectedBorder, - borderSelectedDisabled = disabledBorder, - borderSelectedPressed = selectedBorder, - borderSelectedFocused = selectedBorder, - borderSelectedHovered = selectedBorder, - ) + val colors = ChipColors( + background = normalBackground, + backgroundDisabled = normalBackground, + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = normalBackground, + backgroundSelected = normalBackground, + backgroundSelectedDisabled = normalBackground, + backgroundSelectedPressed = normalBackground, + backgroundSelectedFocused = normalBackground, + backgroundSelectedHovered = normalBackground, + content = normalContent, + contentDisabled = normalContent, + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + contentSelected = normalContent, + contentSelectedDisabled = normalContent, + contentSelectedPressed = normalContent, + contentSelectedFocused = normalContent, + contentSelectedHovered = normalContent, + border = normalBorder, + borderDisabled = disabledBorder, + borderFocused = normalBorder, + borderPressed = normalBorder, + borderHovered = normalBorder, + borderSelected = selectedBorder, + borderSelectedDisabled = disabledBorder, + borderSelectedPressed = selectedBorder, + borderSelectedFocused = selectedBorder, + borderSelectedHovered = selectedBorder, + ) + return ChipStyle( colors = colors, - metrics = - ChipMetrics( + metrics = ChipMetrics( cornerSize = CornerSize(6.dp), padding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), borderWidth = 1.dp, @@ -385,49 +366,40 @@ private fun readDefaultDropdownStyle( val normalBorder = retrieveColorOrUnspecified("Component.borderColor") val focusedBorder = retrieveColorOrUnspecified("Component.focusedBorderColor") - val colors = - DropdownColors( - background = normalBackground, - backgroundDisabled = retrieveColorOrUnspecified("ComboBox.disabledBackground"), - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = normalBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("ComboBox.disabledForeground"), - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - border = normalBorder, - borderDisabled = retrieveColorOrUnspecified("Component.disabledBorderColor"), - borderFocused = focusedBorder, - borderPressed = focusedBorder, - borderHovered = normalBorder, - iconTint = Color.Unspecified, - iconTintDisabled = Color.Unspecified, - iconTintFocused = Color.Unspecified, - iconTintPressed = Color.Unspecified, - iconTintHovered = Color.Unspecified, - ) + val colors = DropdownColors( + background = normalBackground, + backgroundDisabled = retrieveColorOrUnspecified("ComboBox.disabledBackground"), + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = normalBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("ComboBox.disabledForeground"), + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + border = normalBorder, + borderDisabled = retrieveColorOrUnspecified("Component.disabledBorderColor"), + borderFocused = focusedBorder, + borderPressed = focusedBorder, + borderHovered = normalBorder, + iconTint = Color.Unspecified, + iconTintDisabled = Color.Unspecified, + iconTintFocused = Color.Unspecified, + iconTintPressed = Color.Unspecified, + iconTintHovered = Color.Unspecified, + ) val arrowWidth = DarculaUIUtil.ARROW_BUTTON_WIDTH.dp return DropdownStyle( colors = colors, - metrics = - DropdownMetrics( + metrics = DropdownMetrics( arrowMinSize = DpSize(arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp), - minSize = - DpSize( - DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, - DarculaUIUtil.MINIMUM_HEIGHT.dp, - ), + minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp), cornerSize = CornerSize(DarculaUIUtil.COMPONENT_ARC.dp), contentPadding = retrieveInsetsAsPaddingValues("ComboBox.padding"), borderWidth = DarculaUIUtil.BW.dp, ), - icons = - DropdownIcons( - chevronDown = bridgePainterProvider("general/chevron-down.svg"), - ), + icons = DropdownIcons(chevronDown = bridgePainterProvider("general/chevron-down.svg")), textStyle = dropdownTextStyle, menuStyle = menuStyle, ) @@ -438,53 +410,43 @@ private fun readUndecoratedDropdownStyle( dropdownTextStyle: TextStyle, ): DropdownStyle { val normalBackground = retrieveColorOrUnspecified("ComboBox.nonEditableBackground") - val hoverBackground = - retrieveColorOrUnspecified("MainToolbar.Dropdown.transparentHoverBackground") + val hoverBackground = retrieveColorOrUnspecified("MainToolbar.Dropdown.transparentHoverBackground") val normalContent = retrieveColorOrUnspecified("ComboBox.foreground") - val colors = - DropdownColors( - background = normalBackground, - backgroundDisabled = retrieveColorOrUnspecified("ComboBox.disabledBackground"), - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = hoverBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("ComboBox.disabledForeground"), - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - border = Color.Transparent, - borderDisabled = Color.Transparent, - borderFocused = Color.Transparent, - borderPressed = Color.Transparent, - borderHovered = Color.Transparent, - iconTint = Color.Unspecified, - iconTintDisabled = Color.Unspecified, - iconTintFocused = Color.Unspecified, - iconTintPressed = Color.Unspecified, - iconTintHovered = Color.Unspecified, - ) + val colors = DropdownColors( + background = normalBackground, + backgroundDisabled = retrieveColorOrUnspecified("ComboBox.disabledBackground"), + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = hoverBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("ComboBox.disabledForeground"), + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + border = Color.Transparent, + borderDisabled = Color.Transparent, + borderFocused = Color.Transparent, + borderPressed = Color.Transparent, + borderHovered = Color.Transparent, + iconTint = Color.Unspecified, + iconTintDisabled = Color.Unspecified, + iconTintFocused = Color.Unspecified, + iconTintPressed = Color.Unspecified, + iconTintHovered = Color.Unspecified, + ) val arrowWidth = DarculaUIUtil.ARROW_BUTTON_WIDTH.dp return DropdownStyle( colors = colors, - metrics = - DropdownMetrics( + metrics = DropdownMetrics( arrowMinSize = DpSize(arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp), - minSize = - DpSize( - DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, - DarculaUIUtil.MINIMUM_HEIGHT.dp, - ), + minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp), cornerSize = CornerSize(JBUI.CurrentTheme.MainToolbar.Dropdown.hoverArc().dp), contentPadding = JBUI.CurrentTheme.MainToolbar.Dropdown.borderInsets().toPaddingValues(), borderWidth = 0.dp, ), - icons = - DropdownIcons( - chevronDown = bridgePainterProvider("general/chevron-down.svg"), - ), + icons = DropdownIcons(chevronDown = bridgePainterProvider("general/chevron-down.svg")), textStyle = dropdownTextStyle, menuStyle = menuStyle, ) @@ -492,12 +454,8 @@ private fun readUndecoratedDropdownStyle( private fun readGroupHeaderStyle() = GroupHeaderStyle( - colors = - GroupHeaderColors( - divider = retrieveColorOrUnspecified("Separator.separatorColor"), - ), - metrics = - GroupHeaderMetrics( + colors = GroupHeaderColors(divider = retrieveColorOrUnspecified("Separator.separatorColor")), + metrics = GroupHeaderMetrics( dividerThickness = 1.dp, // see DarculaSeparatorUI indent = 1.dp, // see DarculaSeparatorUI ), @@ -505,15 +463,13 @@ private fun readGroupHeaderStyle() = private fun readHorizontalProgressBarStyle() = HorizontalProgressBarStyle( - colors = - HorizontalProgressBarColors( + colors = HorizontalProgressBarColors( track = retrieveColorOrUnspecified("ProgressBar.trackColor"), progress = retrieveColorOrUnspecified("ProgressBar.progressColor"), indeterminateBase = retrieveColorOrUnspecified("ProgressBar.indeterminateStartColor"), indeterminateHighlight = retrieveColorOrUnspecified("ProgressBar.indeterminateEndColor"), ), - metrics = - HorizontalProgressBarMetrics( + metrics = HorizontalProgressBarMetrics( cornerSize = CornerSize(100), minHeight = 4.dp, // See DarculaProgressBarUI.DEFAULT_WIDTH // See DarculaProgressBarUI.CYCLE_TIME_DEFAULT, @@ -527,51 +483,38 @@ private fun readHorizontalProgressBarStyle() = private fun readLinkStyle( linkTextStyle: TextStyle, ): LinkStyle { - val normalContent = - retrieveColorOrUnspecified("Link.activeForeground").takeOrElse { - retrieveColorOrUnspecified("Link.activeForeground") - } + val normalContent = retrieveColorOrUnspecified("Link.activeForeground") + .takeOrElse { retrieveColorOrUnspecified("Link.activeForeground") } val colors = LinkColors( content = normalContent, - contentDisabled = - retrieveColorOrUnspecified("Link.disabledForeground").takeOrElse { - retrieveColorOrUnspecified( - "Label.disabledForeground", - ) - }, + contentDisabled = retrieveColorOrUnspecified("Link.disabledForeground") + .takeOrElse { retrieveColorOrUnspecified("Label.disabledForeground") }, contentFocused = normalContent, - contentPressed = - retrieveColorOrUnspecified("Link.pressedForeground").takeOrElse { - retrieveColorOrUnspecified("link.pressed.foreground") - }, - contentHovered = - retrieveColorOrUnspecified("Link.hoverForeground").takeOrElse { - retrieveColorOrUnspecified("link.hover.foreground") - }, - contentVisited = - retrieveColorOrUnspecified("Link.visitedForeground").takeOrElse { - retrieveColorOrUnspecified("link.visited.foreground") - }, + contentPressed = retrieveColorOrUnspecified("Link.pressedForeground") + .takeOrElse { retrieveColorOrUnspecified("link.pressed.foreground") }, + contentHovered = retrieveColorOrUnspecified("Link.hoverForeground") + .takeOrElse { retrieveColorOrUnspecified("link.hover.foreground") }, + contentVisited = retrieveColorOrUnspecified("Link.visitedForeground") + .takeOrElse { retrieveColorOrUnspecified("link.visited.foreground") }, ) return LinkStyle( colors = colors, - metrics = - LinkMetrics( - focusHaloCornerSize = - CornerSize(Registry.intValue("ide.link.button.focus.round.arc", 4).dp), + metrics = LinkMetrics( + focusHaloCornerSize = retrieveArcAsCornerSizeOrDefault( + key = "ide.link.button.focus.round.arc", + default = CornerSize(4.dp), + ), textIconGap = 4.dp, iconSize = DpSize(16.dp, 16.dp), ), - icons = - LinkIcons( + icons = LinkIcons( dropdownChevron = bridgePainterProvider("general/chevron-down.svg"), externalLink = bridgePainterProvider("ide/external_link_arrow.svg"), ), - textStyles = - LinkTextStyles( + textStyles = LinkTextStyles( normal = linkTextStyle, disabled = linkTextStyle, focused = linkTextStyle, @@ -586,120 +529,94 @@ private fun readMenuStyle(): MenuStyle { val backgroundSelected = retrieveColorOrUnspecified("MenuItem.selectionBackground") val foregroundSelected = retrieveColorOrUnspecified("MenuItem.selectionForeground") - val colors = - MenuColors( - background = retrieveColorOrUnspecified("PopupMenu.background"), - border = - retrieveColorOrUnspecified("Popup.borderColor").takeOrElse { - retrieveColorOrUnspecified("Popup.Border.color") - }, - shadow = Color.Black.copy(alpha = .6f), - itemColors = - MenuItemColors( - background = retrieveColorOrUnspecified("MenuItem.background"), - backgroundDisabled = retrieveColorOrUnspecified("MenuItem.disabledBackground"), - backgroundFocused = backgroundSelected, - backgroundPressed = backgroundSelected, - backgroundHovered = backgroundSelected, - content = retrieveColorOrUnspecified("PopupMenu.foreground"), - contentDisabled = retrieveColorOrUnspecified("PopupMenu.disabledForeground"), - contentFocused = foregroundSelected, - contentPressed = foregroundSelected, - contentHovered = foregroundSelected, - iconTint = Color.Unspecified, - iconTintDisabled = Color.Unspecified, - iconTintFocused = Color.Unspecified, - iconTintPressed = Color.Unspecified, - iconTintHovered = Color.Unspecified, - separator = retrieveColorOrUnspecified("Menu.separatorColor"), - ), - ) + val colors = MenuColors( + background = retrieveColorOrUnspecified("PopupMenu.background"), + border = retrieveColorOrUnspecified("Popup.borderColor") + .takeOrElse { retrieveColorOrUnspecified("Popup.Border.color") }, + shadow = Color.Black.copy(alpha = .6f), + itemColors = MenuItemColors( + background = retrieveColorOrUnspecified("MenuItem.background"), + backgroundDisabled = retrieveColorOrUnspecified("MenuItem.disabledBackground"), + backgroundFocused = backgroundSelected, + backgroundPressed = backgroundSelected, + backgroundHovered = backgroundSelected, + content = retrieveColorOrUnspecified("PopupMenu.foreground"), + contentDisabled = retrieveColorOrUnspecified("PopupMenu.disabledForeground"), + contentFocused = foregroundSelected, + contentPressed = foregroundSelected, + contentHovered = foregroundSelected, + iconTint = Color.Unspecified, + iconTintDisabled = Color.Unspecified, + iconTintFocused = Color.Unspecified, + iconTintPressed = Color.Unspecified, + iconTintHovered = Color.Unspecified, + separator = retrieveColorOrUnspecified("Menu.separatorColor"), + ), + ) return MenuStyle( isDark = !JBColor.isBright(), colors = colors, - metrics = - MenuMetrics( + metrics = MenuMetrics( cornerSize = CornerSize(IdeaPopupMenuUI.CORNER_RADIUS.dp), menuMargin = PaddingValues(0.dp), contentPadding = PaddingValues(horizontal = 8.dp, vertical = 12.dp), offset = DpOffset(0.dp, 2.dp), shadowSize = 12.dp, borderWidth = retrieveIntAsDpOrUnspecified("Popup.borderWidth").takeOrElse { 1.dp }, - itemMetrics = - MenuItemMetrics( + itemMetrics = MenuItemMetrics( selectionCornerSize = CornerSize(JBUI.CurrentTheme.PopupMenu.Selection.ARC.dp), outerPadding = PaddingValues(horizontal = 6.dp), contentPadding = PaddingValues(horizontal = 10.dp, vertical = 4.dp), - separatorPadding = - PaddingValues( - horizontal = - retrieveIntAsDpOrUnspecified("PopupMenuSeparator.withToEdge").takeOrElse { 0.dp }, - vertical = - retrieveIntAsDpOrUnspecified("PopupMenuSeparator.stripeIndent").takeOrElse { - 0.dp - }, + separatorPadding = PaddingValues( + horizontal = retrieveIntAsDpOrUnspecified("PopupMenuSeparator.withToEdge") + .takeOrElse { 0.dp }, + vertical = retrieveIntAsDpOrUnspecified("PopupMenuSeparator.stripeIndent") + .takeOrElse { 0.dp }, ), - separatorThickness = - retrieveIntAsDpOrUnspecified("PopupMenuSeparator.stripeWidth").takeOrElse { 0.dp }, + separatorThickness = retrieveIntAsDpOrUnspecified("PopupMenuSeparator.stripeWidth") + .takeOrElse { 0.dp }, ), - submenuMetrics = - SubmenuMetrics( - offset = DpOffset(0.dp, (-8).dp), - ), - ), - icons = - MenuIcons( - submenuChevron = bridgePainterProvider("general/chevron-right.svg"), + submenuMetrics = SubmenuMetrics(offset = DpOffset(0.dp, (-8).dp)), ), + icons = MenuIcons(submenuChevron = bridgePainterProvider("general/chevron-right.svg")), ) } private fun readRadioButtonStyle(): RadioButtonStyle { val normalContent = retrieveColorOrUnspecified("RadioButton.foreground") val disabledContent = retrieveColorOrUnspecified("RadioButton.disabledText") - val colors = - RadioButtonColors( - content = normalContent, - contentHovered = normalContent, - contentDisabled = disabledContent, - contentSelected = normalContent, - contentSelectedHovered = normalContent, - contentSelectedDisabled = disabledContent, - ) + val colors = RadioButtonColors( + content = normalContent, + contentHovered = normalContent, + contentDisabled = disabledContent, + contentSelected = normalContent, + contentSelectedHovered = normalContent, + contentSelectedDisabled = disabledContent, + ) return RadioButtonStyle( colors = colors, - metrics = - RadioButtonMetrics( + metrics = RadioButtonMetrics( radioButtonSize = DpSize(19.dp, 19.dp), - iconContentGap = - retrieveIntAsDpOrUnspecified("RadioButton.textIconGap").takeOrElse { 4.dp }, - ), - icons = - RadioButtonIcons( - radioButton = bridgePainterProvider("${iconsBasePath}radio.svg"), + iconContentGap = retrieveIntAsDpOrUnspecified("RadioButton.textIconGap") + .takeOrElse { 4.dp }, ), + icons = RadioButtonIcons(radioButton = bridgePainterProvider("${iconsBasePath}radio.svg")), ) } private fun readScrollbarStyle(isDark: Boolean) = ScrollbarStyle( - colors = - ScrollbarColors( + colors = ScrollbarColors( // See ScrollBarPainter.THUMB_OPAQUE_BACKGROUND - thumbBackground = - retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.thumbColor").takeOrElse { - if (isDark) Color(0x59808080) else Color(0x33000000) - }, + thumbBackground = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.thumbColor") + .takeOrElse { if (isDark) Color(0x59808080) else Color(0x33000000) }, // See ScrollBarPainter.THUMB_OPAQUE_HOVERED_BACKGROUND - thumbBackgroundHovered = - retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.hoverThumbColor").takeOrElse { - if (isDark) Color(0x8C808080) else Color(0x80000000) - }, + thumbBackgroundHovered = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.hoverThumbColor") + .takeOrElse { if (isDark) Color(0x8C808080) else Color(0x80000000) }, ), - metrics = - ScrollbarMetrics( + metrics = ScrollbarMetrics( thumbCornerSize = CornerSize(100), thumbThickness = 8.dp, minThumbLength = 16.dp, @@ -715,35 +632,33 @@ private fun readTextAreaStyle(textStyle: TextStyle, metrics: TextFieldMetrics): val focusedBorder = DarculaUIUtil.getOutlineColor(true, true).toComposeColor() val normalCaret = retrieveColorOrUnspecified("TextArea.caretForeground") - val colors = - TextAreaColors( - background = normalBackground, - backgroundDisabled = retrieveColorOrUnspecified("TextArea.disabledBackground"), - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = normalBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("TextArea.inactiveForeground"), - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - border = normalBorder, - borderDisabled = DarculaUIUtil.getOutlineColor(false, false).toComposeColor(), - borderFocused = focusedBorder, - borderPressed = focusedBorder, - borderHovered = normalBorder, - caret = normalCaret, - caretDisabled = normalCaret, - caretFocused = normalCaret, - caretPressed = normalCaret, - caretHovered = normalCaret, - placeholder = NamedColorUtil.getInactiveTextColor().toComposeColor(), - ) + val colors = TextAreaColors( + background = normalBackground, + backgroundDisabled = retrieveColorOrUnspecified("TextArea.disabledBackground"), + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = normalBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("TextArea.inactiveForeground"), + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + border = normalBorder, + borderDisabled = DarculaUIUtil.getOutlineColor(false, false).toComposeColor(), + borderFocused = focusedBorder, + borderPressed = focusedBorder, + borderHovered = normalBorder, + caret = normalCaret, + caretDisabled = normalCaret, + caretFocused = normalCaret, + caretPressed = normalCaret, + caretHovered = normalCaret, + placeholder = NamedColorUtil.getInactiveTextColor().toComposeColor(), + ) return TextAreaStyle( colors = colors, - metrics = - TextAreaMetrics( + metrics = TextAreaMetrics( cornerSize = metrics.cornerSize, contentPadding = metrics.contentPadding, minSize = metrics.minSize, @@ -760,35 +675,33 @@ private fun readTextFieldStyle(textFieldStyle: TextStyle): TextFieldStyle { val focusedBorder = DarculaUIUtil.getOutlineColor(true, true).toComposeColor() val normalCaret = retrieveColorOrUnspecified("TextField.caretForeground") - val colors = - TextFieldColors( - background = normalBackground, - backgroundDisabled = retrieveColorOrUnspecified("TextField.disabledBackground"), - backgroundFocused = normalBackground, - backgroundPressed = normalBackground, - backgroundHovered = normalBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("TextField.inactiveForeground"), - contentFocused = normalContent, - contentPressed = normalContent, - contentHovered = normalContent, - border = normalBorder, - borderDisabled = DarculaUIUtil.getOutlineColor(false, false).toComposeColor(), - borderFocused = focusedBorder, - borderPressed = focusedBorder, - borderHovered = normalBorder, - caret = normalCaret, - caretDisabled = normalCaret, - caretFocused = normalCaret, - caretPressed = normalCaret, - caretHovered = normalCaret, - placeholder = NamedColorUtil.getInactiveTextColor().toComposeColor(), - ) + val colors = TextFieldColors( + background = normalBackground, + backgroundDisabled = retrieveColorOrUnspecified("TextField.disabledBackground"), + backgroundFocused = normalBackground, + backgroundPressed = normalBackground, + backgroundHovered = normalBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("TextField.inactiveForeground"), + contentFocused = normalContent, + contentPressed = normalContent, + contentHovered = normalContent, + border = normalBorder, + borderDisabled = DarculaUIUtil.getOutlineColor(false, false).toComposeColor(), + borderFocused = focusedBorder, + borderPressed = focusedBorder, + borderHovered = normalBorder, + caret = normalCaret, + caretDisabled = normalCaret, + caretFocused = normalCaret, + caretPressed = normalCaret, + caretHovered = normalCaret, + placeholder = NamedColorUtil.getInactiveTextColor().toComposeColor(), + ) return TextFieldStyle( colors = colors, - metrics = - TextFieldMetrics( + metrics = TextFieldMetrics( cornerSize = CornerSize(DarculaUIUtil.COMPONENT_ARC.dp), contentPadding = PaddingValues(horizontal = 9.dp, vertical = 2.dp), minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp, DarculaUIUtil.MINIMUM_HEIGHT.dp), @@ -802,38 +715,34 @@ private fun readLazyTreeStyle(): LazyTreeStyle { val normalContent = retrieveColorOrUnspecified("Tree.foreground") val selectedContent = retrieveColorOrUnspecified("Tree.selectionForeground") val selectedElementBackground = retrieveColorOrUnspecified("Tree.selectionBackground") - val inactiveSelectedElementBackground = - retrieveColorOrUnspecified("Tree.selectionInactiveBackground") - - val colors = - LazyTreeColors( - content = normalContent, - contentFocused = normalContent, - contentSelected = selectedContent, - contentSelectedFocused = selectedContent, - elementBackgroundFocused = Color.Transparent, - elementBackgroundSelected = inactiveSelectedElementBackground, - elementBackgroundSelectedFocused = selectedElementBackground, - ) + val inactiveSelectedElementBackground = retrieveColorOrUnspecified("Tree.selectionInactiveBackground") + + val colors = LazyTreeColors( + content = normalContent, + contentFocused = normalContent, + contentSelected = selectedContent, + contentSelectedFocused = selectedContent, + elementBackgroundFocused = Color.Transparent, + elementBackgroundSelected = inactiveSelectedElementBackground, + elementBackgroundSelectedFocused = selectedElementBackground, + ) val chevronCollapsed = bridgePainterProvider("general/chevron-right.svg") val chevronExpanded = bridgePainterProvider("general/chevron-down.svg") + val leftIndent = retrieveIntAsDpOrUnspecified("Tree.leftChildIndent").takeOrElse { 7.dp } + val rightIndent = retrieveIntAsDpOrUnspecified("Tree.rightChildIndent").takeOrElse { 11.dp } return LazyTreeStyle( colors = colors, - metrics = - LazyTreeMetrics( - indentSize = - retrieveIntAsDpOrUnspecified("Tree.leftChildIndent").takeOrElse { 7.dp } + - retrieveIntAsDpOrUnspecified("Tree.rightChildIndent").takeOrElse { 11.dp }, + metrics = LazyTreeMetrics( + indentSize = leftIndent + rightIndent, elementBackgroundCornerSize = CornerSize(JBUI.CurrentTheme.Tree.ARC.dp / 2), elementPadding = PaddingValues(horizontal = 12.dp), elementContentPadding = PaddingValues(4.dp), elementMinHeight = retrieveIntAsDpOrUnspecified("Tree.rowHeight").takeOrElse { 24.dp }, chevronContentGap = 2.dp, // See com.intellij.ui.tree.ui.ClassicPainter.GAP ), - icons = - LazyTreeIcons( + icons = LazyTreeIcons( chevronCollapsed = chevronCollapsed, chevronExpanded = chevronExpanded, chevronSelectedCollapsed = chevronCollapsed, @@ -845,49 +754,39 @@ private fun readLazyTreeStyle(): LazyTreeStyle { // See com.intellij.ui.tabs.impl.themes.DefaultTabTheme private fun readDefaultTabStyle(): TabStyle { val normalBackground = JBUI.CurrentTheme.DefaultTabs.background().toComposeColor() - val selectedBackground = - JBUI.CurrentTheme.DefaultTabs.underlinedTabBackground().toComposeColorOrUnspecified() + val selectedBackground = JBUI.CurrentTheme.DefaultTabs.underlinedTabBackground().toComposeColorOrUnspecified() val normalContent = retrieveColorOrUnspecified("TabbedPane.foreground") val selectedUnderline = retrieveColorOrUnspecified("TabbedPane.underlineColor") - val colors = - TabColors( - background = normalBackground, - backgroundDisabled = normalBackground, - - backgroundPressed = selectedBackground, - backgroundHovered = JBUI.CurrentTheme.DefaultTabs.hoverBackground().toComposeColor(), - backgroundSelected = selectedBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("TabbedPane.disabledForeground"), - - contentPressed = normalContent, - contentHovered = normalContent, - contentSelected = normalContent, - underline = Color.Transparent, - underlineDisabled = retrieveColorOrUnspecified("TabbedPane.disabledUnderlineColor"), - - underlinePressed = selectedUnderline, - underlineHovered = Color.Transparent, - underlineSelected = selectedUnderline, - ) + val colors = TabColors( + background = normalBackground, + backgroundDisabled = normalBackground, + backgroundPressed = selectedBackground, + backgroundHovered = JBUI.CurrentTheme.DefaultTabs.hoverBackground().toComposeColor(), + backgroundSelected = selectedBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("TabbedPane.disabledForeground"), + contentPressed = normalContent, + contentHovered = normalContent, + contentSelected = normalContent, + underline = Color.Transparent, + underlineDisabled = retrieveColorOrUnspecified("TabbedPane.disabledUnderlineColor"), + underlinePressed = selectedUnderline, + underlineHovered = Color.Transparent, + underlineSelected = selectedUnderline, + ) return TabStyle( colors = colors, - metrics = - TabMetrics( - underlineThickness = - retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight").takeOrElse { 2.dp }, + metrics = TabMetrics( + underlineThickness = retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight") + .takeOrElse { 2.dp }, tabPadding = retrieveInsetsAsPaddingValues("TabbedPane.tabInsets"), closeContentGap = 4.dp, tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp }, ), - icons = - TabIcons( - close = bridgePainterProvider("expui/general/closeSmall.svg"), - ), - contentAlpha = - TabContentAlpha( + icons = TabIcons(close = bridgePainterProvider("expui/general/closeSmall.svg")), + contentAlpha = TabContentAlpha( iconNormal = 1f, iconDisabled = 1f, iconPressed = 1f, @@ -904,49 +803,40 @@ private fun readDefaultTabStyle(): TabStyle { private fun readEditorTabStyle(): TabStyle { val normalBackground = JBUI.CurrentTheme.EditorTabs.background().toComposeColor() - val selectedBackground = - JBUI.CurrentTheme.EditorTabs.underlinedTabBackground().toComposeColorOrUnspecified() + val selectedBackground = JBUI.CurrentTheme.EditorTabs.underlinedTabBackground().toComposeColorOrUnspecified() val normalContent = retrieveColorOrUnspecified("TabbedPane.foreground") val selectedUnderline = retrieveColorOrUnspecified("TabbedPane.underlineColor") - val colors = - TabColors( - background = normalBackground, - backgroundDisabled = normalBackground, - - backgroundPressed = selectedBackground, - backgroundHovered = JBUI.CurrentTheme.EditorTabs.hoverBackground().toComposeColor(), - backgroundSelected = selectedBackground, - content = normalContent, - contentDisabled = retrieveColorOrUnspecified("TabbedPane.disabledForeground"), - - contentPressed = normalContent, - contentHovered = normalContent, - contentSelected = normalContent, - underline = Color.Transparent, - underlineDisabled = retrieveColorOrUnspecified("TabbedPane.disabledUnderlineColor"), - - underlinePressed = selectedUnderline, - underlineHovered = Color.Transparent, - underlineSelected = selectedUnderline, - ) + val colors = TabColors( + background = normalBackground, + backgroundDisabled = normalBackground, + backgroundPressed = selectedBackground, + backgroundHovered = JBUI.CurrentTheme.EditorTabs.hoverBackground().toComposeColor(), + backgroundSelected = selectedBackground, + content = normalContent, + contentDisabled = retrieveColorOrUnspecified("TabbedPane.disabledForeground"), + contentPressed = normalContent, + contentHovered = normalContent, + contentSelected = normalContent, + underline = Color.Transparent, + underlineDisabled = retrieveColorOrUnspecified("TabbedPane.disabledUnderlineColor"), + underlinePressed = selectedUnderline, + underlineHovered = Color.Transparent, + underlineSelected = selectedUnderline, + ) return TabStyle( colors = colors, - metrics = - TabMetrics( - underlineThickness = - retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight").takeOrElse { 2.dp }, + metrics = TabMetrics( + underlineThickness = retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight") + .takeOrElse { 2.dp }, tabPadding = retrieveInsetsAsPaddingValues("TabbedPane.tabInsets"), closeContentGap = 4.dp, - tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp }, - ), - icons = - TabIcons( - close = bridgePainterProvider("expui/general/closeSmall.svg"), + tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight") + .takeOrElse { 24.dp }, ), - contentAlpha = - TabContentAlpha( + icons = TabIcons(close = bridgePainterProvider("expui/general/closeSmall.svg")), + contentAlpha = TabContentAlpha( iconNormal = .7f, iconDisabled = .7f, iconPressed = 1f, @@ -961,21 +851,17 @@ private fun readEditorTabStyle(): TabStyle { ) } -private fun readCircularProgressStyle( - isDark: Boolean, -) = +private fun readCircularProgressStyle(isDark: Boolean) = CircularProgressStyle( frameTime = 125.milliseconds, - color = - retrieveColorOrUnspecified("ProgressIcon.color").takeIf { it.isSpecified } - ?: if (isDark) Color(0xFF6F737A) else Color(0xFFA8ADBD), + color = retrieveColorOrUnspecified("ProgressIcon.color") + .takeOrElse { if (isDark) Color(0xFF6F737A) else Color(0xFFA8ADBD) }, ) private fun readTooltipStyle() = TooltipStyle( metrics = TooltipMetrics.defaults(), - colors = - TooltipColors( + colors = TooltipColors( content = retrieveColorOrUnspecified("ToolTip.foreground"), background = retrieveColorOrUnspecified("ToolTip.background"), border = retrieveColorOrUnspecified("ToolTip.borderColor"), @@ -985,15 +871,13 @@ private fun readTooltipStyle() = private fun readIconButtonStyle(): IconButtonStyle = IconButtonStyle( - metrics = - IconButtonMetrics( + metrics = IconButtonMetrics( cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2), borderWidth = 1.dp, padding = PaddingValues(0.dp), minSize = DpSize(16.dp, 16.dp), ), - colors = - IconButtonColors( + colors = IconButtonColors( foregroundSelectedActivated = retrieveColorOrUnspecified("ToolWindow.Button.selectedForeground"), background = Color.Unspecified, backgroundDisabled = Color.Unspecified, diff --git a/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/IntUiTheme.kt b/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/IntUiTheme.kt index 1107cb0b7c..857983f390 100644 --- a/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/IntUiTheme.kt +++ b/int-ui/int-ui-decorated-window/src/main/kotlin/org/jetbrains/jewel/intui/window/IntUiTheme.kt @@ -16,16 +16,10 @@ public fun ComponentStyling.decoratedWindow( provide { val isDark = JewelTheme.isDark - val currentWindowStyle = windowStyle ?: if (isDark) { - DecoratedWindowStyle.dark() - } else { - DecoratedWindowStyle.light() - } - val currentTitleBarStyle = titleBarStyle ?: if (isDark) { - TitleBarStyle.dark() - } else { - TitleBarStyle.light() - } + val currentWindowStyle = windowStyle + ?: if (isDark) DecoratedWindowStyle.dark() else DecoratedWindowStyle.light() + val currentTitleBarStyle = titleBarStyle + ?: if (isDark) TitleBarStyle.dark() else TitleBarStyle.light() arrayOf( LocalDecoratedWindowStyle provides currentWindowStyle, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiMenuStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiMenuStyling.kt index 04039b5ed7..3ab4654d2a 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiMenuStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiMenuStyling.kt @@ -24,24 +24,26 @@ public fun MenuStyle.Companion.light( colors: MenuColors = MenuColors.light(), metrics: MenuMetrics = MenuMetrics.defaults(), icons: MenuIcons = MenuIcons.defaults(), -): MenuStyle = MenuStyle( - isDark = false, - colors = colors, - metrics = metrics, - icons = icons, -) +): MenuStyle = + MenuStyle( + isDark = false, + colors = colors, + metrics = metrics, + icons = icons, + ) @Composable public fun MenuStyle.Companion.dark( colors: MenuColors = MenuColors.dark(), metrics: MenuMetrics = MenuMetrics.defaults(), icons: MenuIcons = MenuIcons.defaults(), -): MenuStyle = MenuStyle( - isDark = true, - colors = colors, - metrics = metrics, - icons = icons, -) +): MenuStyle = + MenuStyle( + isDark = true, + colors = colors, + metrics = metrics, + icons = icons, + ) @Composable public fun MenuColors.Companion.light( diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/theme/IntUiTheme.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/theme/IntUiTheme.kt index a8dcc843cd..3fdde63d05 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/theme/IntUiTheme.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/theme/IntUiTheme.kt @@ -129,7 +129,6 @@ public fun ComponentStyling.dark( groupHeaderStyle = groupHeaderStyle, horizontalProgressBarStyle = horizontalProgressBarStyle, iconButtonStyle = iconButtonStyle, - lazyTreeStyle = lazyTreeStyle, linkStyle = linkStyle, menuStyle = menuStyle, @@ -180,7 +179,6 @@ public fun ComponentStyling.light( groupHeaderStyle = groupHeaderStyle, horizontalProgressBarStyle = horizontalProgressBarStyle, iconButtonStyle = iconButtonStyle, - lazyTreeStyle = lazyTreeStyle, linkStyle = linkStyle, menuStyle = menuStyle, diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt index a5659b923e..b76f83a96e 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt @@ -4,15 +4,13 @@ import org.jetbrains.skiko.SystemTheme import org.jetbrains.skiko.currentSystemTheme enum class IntUiThemes { - Light, LightWithLightHeader, Dark, SYSTEM; + Light, LightWithLightHeader, Dark, System; - fun isDark(): Boolean = if (this == SYSTEM) { - fromSystemTheme(currentSystemTheme) - } else { - this - } == Dark + fun isDark() = + (if (this == System) fromSystemTheme(currentSystemTheme) else this) == Dark - fun isLightHeader() = this == LightWithLightHeader + fun isLightHeader() = + this == LightWithLightHeader companion object { diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt index b77a402339..554d9f7256 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt @@ -37,7 +37,7 @@ fun main() { IntUiThemes.Light -> TitleBarStyle.light() IntUiThemes.LightWithLightHeader -> TitleBarStyle.lightWithLightHeader() IntUiThemes.Dark -> TitleBarStyle.dark() - IntUiThemes.SYSTEM -> if (MainViewModel.theme.isDark()) { + IntUiThemes.System -> if (MainViewModel.theme.isDark()) { TitleBarStyle.dark() } else { TitleBarStyle.light() diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/TitleBarView.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/TitleBarView.kt index 21de995ecc..e1e2ea1a97 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/TitleBarView.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/TitleBarView.kt @@ -86,14 +86,14 @@ fun DecoratedWindowScope.TitleBarView() { when (MainViewModel.theme) { IntUiThemes.Light -> Text("Switch to light theme with light header") IntUiThemes.LightWithLightHeader -> Text("Switch to dark theme") - IntUiThemes.Dark, IntUiThemes.SYSTEM -> Text("Switch to light theme") + IntUiThemes.Dark, IntUiThemes.System -> Text("Switch to light theme") } }) { IconButton({ MainViewModel.theme = when (MainViewModel.theme) { IntUiThemes.Light -> IntUiThemes.LightWithLightHeader IntUiThemes.LightWithLightHeader -> IntUiThemes.Dark - IntUiThemes.Dark, IntUiThemes.SYSTEM -> IntUiThemes.Light + IntUiThemes.Dark, IntUiThemes.System -> IntUiThemes.Light } }, Modifier.size(40.dp).padding(5.dp)) { when (MainViewModel.theme) { @@ -115,7 +115,7 @@ fun DecoratedWindowScope.TitleBarView() { StandaloneSampleIcons::class.java, ) - IntUiThemes.SYSTEM -> Icon( + IntUiThemes.System -> Icon( "icons/systemTheme@20x20.svg", "Themes", StandaloneSampleIcons::class.java, diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/WelcomeView.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/WelcomeView.kt index 5d89da89eb..b06e882457 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/WelcomeView.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/WelcomeView.kt @@ -50,10 +50,10 @@ fun WelcomeView() { ThemeSelectionChip(IntUiThemes.Light, "Light", "icons/lightTheme.svg") ThemeSelectionChip( IntUiThemes.LightWithLightHeader, - "Light(Header)", + "Light with Light Header", "icons/lightWithLightHeaderTheme.svg", ) - ThemeSelectionChip(IntUiThemes.SYSTEM, "System", "icons/systemTheme.svg") + ThemeSelectionChip(IntUiThemes.System, "System", "icons/systemTheme.svg") } } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/ComponentStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/ComponentStyling.kt index 3f4df40a3e..bd6b0ee818 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/ComponentStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/ComponentStyling.kt @@ -19,11 +19,7 @@ public interface ComponentStyling { } public fun with(styling: @Composable () -> ComponentStyling): ComponentStyling = - with( - LazyComponentStyling { - styling().styles() - }, - ) + with(LazyComponentStyling { styling().styles() }) @Composable public fun styles(): Array> diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/DefaultComponentStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/DefaultComponentStyling.kt index 3def3ec01a..10b1d93a90 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/DefaultComponentStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/DefaultComponentStyling.kt @@ -73,28 +73,29 @@ public class DefaultComponentStyling( ) : ComponentStyling { @Composable - override fun styles(): Array> = arrayOf( - LocalCheckboxStyle provides checkboxStyle, - LocalChipStyle provides chipStyle, - LocalCircularProgressStyle provides circularProgressStyle, - LocalContextMenuRepresentation provides ContextMenuRepresentation, - LocalDefaultButtonStyle provides defaultButtonStyle, - LocalDefaultDropdownStyle provides defaultDropdownStyle, - LocalDefaultTabStyle provides defaultTabStyle, - LocalDividerStyle provides dividerStyle, - LocalEditorTabStyle provides editorTabStyle, - LocalGroupHeaderStyle provides groupHeaderStyle, - LocalHorizontalProgressBarStyle provides horizontalProgressBarStyle, - LocalIconButtonStyle provides iconButtonStyle, - LocalLazyTreeStyle provides lazyTreeStyle, - LocalLinkStyle provides linkStyle, - LocalMenuStyle provides menuStyle, - LocalOutlinedButtonStyle provides outlinedButtonStyle, - LocalRadioButtonStyle provides radioButtonStyle, - LocalScrollbarStyle provides scrollbarStyle, - LocalTextAreaStyle provides textAreaStyle, - LocalTextFieldStyle provides textFieldStyle, - LocalTooltipStyle provides tooltipStyle, - LocalUndecoratedDropdownStyle provides undecoratedDropdownStyle, - ) + override fun styles(): Array> = + arrayOf( + LocalCheckboxStyle provides checkboxStyle, + LocalChipStyle provides chipStyle, + LocalCircularProgressStyle provides circularProgressStyle, + LocalContextMenuRepresentation provides ContextMenuRepresentation, + LocalDefaultButtonStyle provides defaultButtonStyle, + LocalDefaultDropdownStyle provides defaultDropdownStyle, + LocalDefaultTabStyle provides defaultTabStyle, + LocalDividerStyle provides dividerStyle, + LocalEditorTabStyle provides editorTabStyle, + LocalGroupHeaderStyle provides groupHeaderStyle, + LocalHorizontalProgressBarStyle provides horizontalProgressBarStyle, + LocalIconButtonStyle provides iconButtonStyle, + LocalLazyTreeStyle provides lazyTreeStyle, + LocalLinkStyle provides linkStyle, + LocalMenuStyle provides menuStyle, + LocalOutlinedButtonStyle provides outlinedButtonStyle, + LocalRadioButtonStyle provides radioButtonStyle, + LocalScrollbarStyle provides scrollbarStyle, + LocalTextAreaStyle provides textAreaStyle, + LocalTextFieldStyle provides textFieldStyle, + LocalTooltipStyle provides tooltipStyle, + LocalUndecoratedDropdownStyle provides undecoratedDropdownStyle, + ) } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconButton.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconButton.kt index 7f305d7880..186f5906ca 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconButton.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/IconButton.kt @@ -46,9 +46,7 @@ public fun IconButton( val buttonState = remember(interactionSource) { mutableStateOf(IconButtonState.of(enabled = enabled)) } - remember(enabled) { - buttonState.value = buttonState.value.copy(enabled = enabled) - } + remember(enabled) { buttonState.value = buttonState.value.copy(enabled = enabled) } IconButtonImpl( state = buttonState, @@ -119,7 +117,6 @@ private fun IconButtonImpl( is PressInteraction.Cancel, is PressInteraction.Release, -> buttonState = buttonState.copy(pressed = false) - is HoverInteraction.Enter -> buttonState = buttonState.copy(hovered = true) is HoverInteraction.Exit -> buttonState = buttonState.copy(hovered = false) is FocusInteraction.Focus -> buttonState = buttonState.copy(focused = true) diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/MenuManager.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/MenuManager.kt index b2e2c6d680..bd70c2b0f9 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/MenuManager.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/MenuManager.kt @@ -47,4 +47,6 @@ public class MenuManager( } public val LocalMenuManager: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No MenuManager provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No MenuManager provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt index c439157db1..d8831e976c 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt @@ -145,9 +145,9 @@ private fun RadioButtonImpl( interactionSource.interactions.collect { interaction -> when (interaction) { is PressInteraction.Press -> radioButtonState = radioButtonState.copy(pressed = true) - is PressInteraction.Cancel, - is PressInteraction.Release, - -> radioButtonState = radioButtonState.copy(pressed = false) + is PressInteraction.Cancel, is PressInteraction.Release -> { + radioButtonState = radioButtonState.copy(pressed = false) + } is HoverInteraction.Enter -> radioButtonState = radioButtonState.copy(hovered = true) is HoverInteraction.Exit -> radioButtonState = radioButtonState.copy(hovered = false) is FocusInteraction.Focus -> radioButtonState = radioButtonState.copy(focused = true) @@ -197,10 +197,12 @@ private fun RadioButtonImpl( RadioButtonImage(Modifier, radioButtonPainter, radioButtonModifier) val contentColor by colors.contentFor(radioButtonState) + val resolvedContentColor = contentColor.takeOrElse { textStyle.color } + .takeOrElse { LocalContentColor.current } + CompositionLocalProvider( LocalTextStyle provides textStyle.copy(color = contentColor.takeOrElse { textStyle.color }), - LocalContentColor provides - contentColor.takeOrElse { textStyle.color.takeOrElse { LocalContentColor.current } }, + LocalContentColor provides resolvedContentColor, ) { content() } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Tabs.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Tabs.kt index 5e87c7fbfb..092fbba072 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Tabs.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Tabs.kt @@ -146,11 +146,12 @@ internal fun TabImpl( closeActionInteractionSource.interactions.collect { interaction -> when (interaction) { is PressInteraction.Press -> closeButtonState = closeButtonState.copy(pressed = true) - is PressInteraction.Cancel, - is PressInteraction.Release, - -> + is PressInteraction.Cancel, is PressInteraction.Release -> { closeButtonState = closeButtonState.copy(pressed = false) + } + is HoverInteraction.Enter -> closeButtonState = closeButtonState.copy(hovered = true) + is HoverInteraction.Exit -> closeButtonState = closeButtonState.copy(hovered = false) } } @@ -209,7 +210,6 @@ public value class TabState(public val state: ULong) : SelectableComponentState of( selected = selected, enabled = enabled, - pressed = pressed, hovered = hovered, active = active, diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ButtonStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ButtonStyling.kt index 1e39127b4f..dae54899b0 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ButtonStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ButtonStyling.kt @@ -101,7 +101,11 @@ public class ButtonMetrics( } public val LocalDefaultButtonStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No default ButtonStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No default ButtonStyle provided. Have you forgotten the theme?") + } public val LocalOutlinedButtonStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No outlined ButtonStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No outlined ButtonStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CheckboxStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CheckboxStyling.kt index 1e583e874d..cbe3822d34 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CheckboxStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CheckboxStyling.kt @@ -69,4 +69,6 @@ public class CheckboxIcons(public val checkbox: PainterProvider) { } public val LocalCheckboxStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No CheckboxStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No CheckboxStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ChipStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ChipStyling.kt index 6d17608b19..9acc2531da 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ChipStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ChipStyling.kt @@ -143,4 +143,6 @@ public class ChipMetrics( } public val LocalChipStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No ChipStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No ChipStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CircularProgressStyle.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CircularProgressStyle.kt index 56a22ba481..7849a6ebfe 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CircularProgressStyle.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/CircularProgressStyle.kt @@ -16,4 +16,6 @@ public class CircularProgressStyle( } public val LocalCircularProgressStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No CircularProgressStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No CircularProgressStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DividerStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DividerStyling.kt index 063e3883a0..5227727b94 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DividerStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DividerStyling.kt @@ -35,4 +35,6 @@ public class DividerMetrics( } public val LocalDividerStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No DividerStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No DividerStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DropdownStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DropdownStyling.kt index ead09ae719..173a874d67 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DropdownStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/DropdownStyling.kt @@ -131,7 +131,11 @@ public class DropdownIcons(public val chevronDown: PainterProvider) { } public val LocalDefaultDropdownStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No DefaultDropdownStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No DefaultDropdownStyle provided. Have you forgotten the theme?") + } public val LocalUndecoratedDropdownStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No UndecoratedDropdownStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No UndecoratedDropdownStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/GroupHeaderStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/GroupHeaderStyling.kt index 3d85b8a0c9..9189c3a643 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/GroupHeaderStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/GroupHeaderStyling.kt @@ -35,4 +35,6 @@ public class GroupHeaderMetrics( } public val LocalGroupHeaderStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No GroupHeaderStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No GroupHeaderStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/IconButtonStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/IconButtonStyling.kt index 1819c6964e..1da42dde83 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/IconButtonStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/IconButtonStyling.kt @@ -98,4 +98,6 @@ public class IconButtonMetrics( } public val LocalIconButtonStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No IconButtonStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No IconButtonStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LazyTreeStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LazyTreeStyling.kt index f30715d418..f19b923fe8 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LazyTreeStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LazyTreeStyling.kt @@ -88,4 +88,6 @@ public class LazyTreeIcons( } public val LocalLazyTreeStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No LazyTreeStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No LazyTreeStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LinkStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LinkStyling.kt index 8d99ddd3d8..b53d68cd2c 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LinkStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/LinkStyling.kt @@ -105,4 +105,6 @@ public class LinkTextStyles( } public val LocalLinkStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No LinkStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No LinkStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/MenuStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/MenuStyling.kt index 98a1e7f7aa..1f95db5954 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/MenuStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/MenuStyling.kt @@ -147,4 +147,6 @@ public class MenuIcons(public val submenuChevron: PainterProvider) { } public val LocalMenuStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No MenuStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No MenuStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/RadioButtonStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/RadioButtonStyling.kt index 80ceaaee4e..a3eb2ba41a 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/RadioButtonStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/RadioButtonStyling.kt @@ -69,4 +69,6 @@ public class RadioButtonIcons(public val radioButton: PainterProvider) { } public val LocalRadioButtonStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No RadioButtonStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No RadioButtonStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ScrollbarStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ScrollbarStyling.kt index d022e67fe2..9a914d3cf1 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ScrollbarStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/ScrollbarStyling.kt @@ -45,4 +45,6 @@ public class ScrollbarMetrics( } public val LocalScrollbarStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No ScrollbarStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No ScrollbarStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TabStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TabStyling.kt index 3250ca7ca4..67a5a8d9b3 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TabStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TabStyling.kt @@ -74,7 +74,6 @@ public class TabColors( state.chooseValueIgnoreCompat( normal = content, disabled = contentDisabled, - pressed = contentPressed, hovered = contentHovered, active = content, @@ -89,7 +88,6 @@ public class TabColors( !state.isEnabled -> backgroundDisabled state.isPressed -> backgroundPressed state.isHovered -> backgroundHovered - state.isActive -> background state.isSelected -> backgroundSelected else -> background @@ -105,7 +103,6 @@ public class TabColors( state.chooseValueIgnoreCompat( normal = underline, disabled = underlineDisabled, - pressed = underlinePressed, hovered = underlineHovered, active = underline, @@ -140,7 +137,6 @@ public class TabContentAlpha( state.chooseValueIgnoreCompat( normal = iconNormal, disabled = iconDisabled, - pressed = iconPressed, hovered = iconHovered, active = iconNormal, @@ -157,7 +153,6 @@ public class TabContentAlpha( state.chooseValueIgnoreCompat( normal = labelNormal, disabled = labelDisabled, - pressed = labelPressed, hovered = labelHovered, active = labelNormal, @@ -186,7 +181,11 @@ private fun TabState.chooseValueIgnoreCompat( } public val LocalDefaultTabStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No LocalTabStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No LocalTabStyle provided. Have you forgotten the theme?") + } public val LocalEditorTabStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No LocalTabStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No LocalTabStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextAreaStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextAreaStyling.kt index fb13ec215b..29c96293ee 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextAreaStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextAreaStyling.kt @@ -65,4 +65,6 @@ public class TextAreaMetrics( } public val LocalTextAreaStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No TextAreaStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No TextAreaStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextFieldStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextFieldStyling.kt index 8df75afc35..9fa0d36132 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextFieldStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TextFieldStyling.kt @@ -65,4 +65,6 @@ public class TextFieldMetrics( } public val LocalTextFieldStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No TextFieldStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No TextFieldStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TooltipStyling.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TooltipStyling.kt index ac718dcbf9..d80c4b4faf 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TooltipStyling.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/styling/TooltipStyling.kt @@ -72,4 +72,6 @@ public class TooltipMetrics( } public val LocalTooltipStyle: ProvidableCompositionLocal = - staticCompositionLocalOf { error("No TooltipStyle provided. Have you forgotten the theme?") } + staticCompositionLocalOf { + error("No TooltipStyle provided. Have you forgotten the theme?") + } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/PainterHint.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/PainterHint.kt index 5e785f0bda..ff40197f58 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/PainterHint.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/PainterHint.kt @@ -35,7 +35,8 @@ public sealed interface PainterHint { @Immutable public interface SvgPainterHint : PainterHint { - override fun PainterProviderScope.canApply(): Boolean = path.substringAfterLast('.').lowercase() == "svg" + override fun PainterProviderScope.canApply(): Boolean = + path.substringAfterLast('.').lowercase() == "svg" } /** Mark this [PainterHint] just available with Bitmap images. */ @@ -55,7 +56,8 @@ public interface BitmapPainterHint : PainterHint { @Immutable public interface XmlPainterHint : PainterHint { - override fun PainterProviderScope.canApply(): Boolean = path.substringAfterLast('.').lowercase() == "xml" + override fun PainterProviderScope.canApply(): Boolean = + path.substringAfterLast('.').lowercase() == "xml" } /** diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt index de0b865516..1f3525ca4e 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt @@ -75,15 +75,13 @@ public class ResourcePainterProvider( val scope = Scope(density, basePath, classLoaders) val currentHintsProvider = LocalPainterHintsProvider.current - currentHintsProvider.priorityHints(basePath).forEach { - scope.resolveHint(it) - } - hints.forEach { - scope.resolveHint(it) - } - currentHintsProvider.hints(basePath).forEach { - scope.resolveHint(it) - } + currentHintsProvider.priorityHints(basePath) + .forEach { scope.resolveHint(it) } + + hints.forEach { scope.resolveHint(it) } + + currentHintsProvider.hints(basePath) + .forEach { scope.resolveHint(it) } val cacheKey = scope.acceptedHints.hashCode() @@ -108,20 +106,17 @@ public class ResourcePainterProvider( for (hint in scope.acceptedHints) { if (hint !is PainterPathHint) continue - scopes = scopes.flatMap { - listOfNotNull(it.apply(hint), it) - } + scopes = scopes.flatMap { listOfNotNull(it.apply(hint), it) } } - val (chosenScope, url) = scopes.firstNotNullOfOrNull { - resolveResource(it) - } ?: run { - if (inDebugMode) { - error("Resource '$basePath(${scope.acceptedHints.joinToString()})' not found") - } else { - return errorPainter + val (chosenScope, url) = scopes.firstNotNullOfOrNull { resolveResource(it) } + ?: run { + if (inDebugMode) { + error("Resource '$basePath(${scope.acceptedHints.joinToString()})' not found") + } else { + return errorPainter + } } - } val extension = basePath.substringAfterLast(".").lowercase() @@ -134,9 +129,7 @@ public class ResourcePainterProvider( for (hint in scope.acceptedHints) { if (hint !is PainterWrapperHint) continue - with(hint) { - painter = chosenScope.wrap(painter) - } + with(hint) { painter = chosenScope.wrap(painter) } } return painter @@ -182,9 +175,7 @@ public class ResourcePainterProvider( hints.forEach { hint -> if (hint !is PainterSvgPatchHint) return@forEach - with(hint) { - scope.patch(document.documentElement) - } + with(hint) { scope.patch(document.documentElement) } } return document.writeToString().byteInputStream() diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Palette.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Palette.kt index 2d5ce65f12..175fb5e788 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Palette.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Palette.kt @@ -105,8 +105,5 @@ private fun fromHexOrNull(rawColor: String, alpha: Float): Color? { } } -public fun Palette(map: Map): PainterHint = if (map.isEmpty()) { - PainterHint.None -} else { - PaletteImpl(map) -} +public fun Palette(map: Map): PainterHint = + if (map.isEmpty()) PainterHint.None else PaletteImpl(map) diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Size.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Size.kt index 4e1b6caf1e..c29f2003ae 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Size.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/Size.kt @@ -52,9 +52,6 @@ private class SizeImpl( } public fun Size(width: Int, height: Int = width): PainterHint { - require(width > 0 && height > 0) { - "Width and height must be positive" - } - + require(width > 0 && height > 0) { "Width and height must be positive" } return SizeImpl(width, height) } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/theme/JewelTheme.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/theme/JewelTheme.kt index 3f259dd977..55838e0828 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/theme/JewelTheme.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/theme/JewelTheme.kt @@ -52,11 +52,13 @@ import org.jetbrains.jewel.ui.component.styling.TextFieldStyle import org.jetbrains.jewel.ui.component.styling.TooltipStyle public val JewelTheme.Companion.colorPalette: ThemeColorPalette - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalColorPalette.current public val JewelTheme.Companion.iconData: ThemeIconData - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalIconData.current // ----------------- @@ -64,31 +66,38 @@ public val JewelTheme.Companion.iconData: ThemeIconData // ----------------- public val JewelTheme.Companion.defaultButtonStyle: ButtonStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalDefaultButtonStyle.current public val JewelTheme.Companion.outlinedButtonStyle: ButtonStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalOutlinedButtonStyle.current public val JewelTheme.Companion.checkboxStyle: CheckboxStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalCheckboxStyle.current public val JewelTheme.Companion.chipStyle: ChipStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalChipStyle.current public val JewelTheme.Companion.dividerStyle: DividerStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalDividerStyle.current public val JewelTheme.Companion.dropdownStyle: DropdownStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalDefaultDropdownStyle.current public val JewelTheme.Companion.groupHeaderStyle: GroupHeaderStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalGroupHeaderStyle.current public val JewelTheme.Companion.linkStyle: LinkStyle @@ -97,51 +106,63 @@ public val JewelTheme.Companion.linkStyle: LinkStyle get() = LocalLinkStyle.current public val JewelTheme.Companion.menuStyle: MenuStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalMenuStyle.current public val JewelTheme.Companion.horizontalProgressBarStyle: HorizontalProgressBarStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalHorizontalProgressBarStyle.current public val JewelTheme.Companion.radioButtonStyle: RadioButtonStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalRadioButtonStyle.current public val JewelTheme.Companion.scrollbarStyle: ScrollbarStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalScrollbarStyle.current public val JewelTheme.Companion.textAreaStyle: TextAreaStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalTextAreaStyle.current public val JewelTheme.Companion.textFieldStyle: TextFieldStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalTextFieldStyle.current public val JewelTheme.Companion.treeStyle: LazyTreeStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalLazyTreeStyle.current public val JewelTheme.Companion.defaultTabStyle: TabStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalDefaultTabStyle.current public val JewelTheme.Companion.editorTabStyle: TabStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalEditorTabStyle.current public val JewelTheme.Companion.circularProgressStyle: CircularProgressStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalCircularProgressStyle.current public val JewelTheme.Companion.tooltipStyle: TooltipStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalTooltipStyle.current public val JewelTheme.Companion.iconButtonStyle: IconButtonStyle - @Composable @ReadOnlyComposable + @Composable + @ReadOnlyComposable get() = LocalIconButtonStyle.current @Composable diff --git a/ui/src/test/kotlin/org/jetbrains/jewel/PainterHintTest.kt b/ui/src/test/kotlin/org/jetbrains/jewel/PainterHintTest.kt index 8f96c33328..92be9d1219 100644 --- a/ui/src/test/kotlin/org/jetbrains/jewel/PainterHintTest.kt +++ b/ui/src/test/kotlin/org/jetbrains/jewel/PainterHintTest.kt @@ -104,16 +104,16 @@ class PainterHintTest : BasicJewelUiTest() { @Test fun `override painter hint should replace path entirely`() { val basePath = "icons/github.svg" - val patchedPath = - testScope(basePath).applyPathHints(Override(mapOf("icons/github.svg" to "icons/search.svg"))) + val patchedPath = testScope(basePath) + .applyPathHints(Override(mapOf("icons/github.svg" to "icons/search.svg"))) Assert.assertEquals("icons/search.svg", patchedPath) } @Test fun `override painter hint should not replace path when not matched`() { val basePath = "icons/github.svg" - val patchedPath = - testScope(basePath).applyPathHints(Override(mapOf("icons/settings.svg" to "icons/search.svg"))) + val patchedPath = testScope(basePath) + .applyPathHints(Override(mapOf("icons/settings.svg" to "icons/search.svg"))) Assert.assertEquals(basePath, patchedPath) } @@ -186,36 +186,17 @@ class PainterHintTest : BasicJewelUiTest() { val patchedPath = testScope(basePath).applyPathHints(Stateful(state.copy(enabled = false))) Assert.assertEquals("icons/checkboxDisabled.svg", patchedPath) - testScope(basePath).applyPathHints( - Stateful( - state.copy( - enabled = false, - pressed = true, - hovered = true, - focused = true, - ), - ), - ) - .let { - Assert.assertEquals("icons/checkboxDisabled.svg", it) - } + testScope(basePath) + .applyPathHints(Stateful(state.copy(enabled = false, pressed = true, hovered = true, focused = true))) + .let { Assert.assertEquals("icons/checkboxDisabled.svg", it) } } @Test fun `stateful painter hint disabled state takes higher priority over other states`() { val basePath = "icons/checkbox.svg" val state = CheckboxState.of(toggleableState = ToggleableState.Off) - val patchedPath = - testScope(basePath).applyPathHints( - Stateful( - state.copy( - enabled = false, - pressed = true, - hovered = true, - focused = true, - ), - ), - ) + val patchedPath = testScope(basePath) + .applyPathHints(Stateful(state.copy(enabled = false, pressed = true, hovered = true, focused = true))) Assert.assertEquals("icons/checkboxDisabled.svg", patchedPath) } @@ -231,8 +212,8 @@ class PainterHintTest : BasicJewelUiTest() { fun `stateful painter hint focused state takes higher priority over pressed and hovered states`() { val basePath = "icons/checkbox.svg" val state = CheckboxState.of(toggleableState = ToggleableState.Off) - val patchedPath = - testScope(basePath).applyPathHints(Stateful(state.copy(pressed = true, hovered = true, focused = true))) + val patchedPath = testScope(basePath) + .applyPathHints(Stateful(state.copy(pressed = true, hovered = true, focused = true))) Assert.assertEquals("icons/checkboxFocused.svg", patchedPath) } @@ -248,7 +229,8 @@ class PainterHintTest : BasicJewelUiTest() { fun `stateful painter hint pressed state takes higher priority over hovered state`() { val basePath = "icons/checkbox.svg" val state = CheckboxState.of(toggleableState = ToggleableState.Off) - val patchedPath = testScope(basePath).applyPathHints(Stateful(state.copy(pressed = true, hovered = true))) + val patchedPath = testScope(basePath) + .applyPathHints(Stateful(state.copy(pressed = true, hovered = true))) Assert.assertEquals("icons/checkboxPressed.svg", patchedPath) } @@ -283,10 +265,10 @@ class PainterHintTest : BasicJewelUiTest() { - """ - .trimIndent() - val patchedSvg = - testScope("fake_icon.svg").applyPaletteHints( + """.trimIndent() + + val patchedSvg = testScope("fake_icon.svg") + .applyPaletteHints( baseSvg, Palette( mapOf( @@ -296,6 +278,7 @@ class PainterHintTest : BasicJewelUiTest() { ), ), ) + Assert.assertEquals( """ @@ -303,8 +286,7 @@ class PainterHintTest : BasicJewelUiTest() { - """ - .trimIndent(), + """.trimIndent(), patchedSvg, ) }