Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy components revamping #109

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions core/src/main/kotlin/org/jetbrains/jewel/LazyTree.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package org.jetbrains.jewel

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.res.ResourceLoader
import org.jetbrains.jewel.foundation.lazy.SelectableLazyItemScope
import org.jetbrains.jewel.foundation.tree.BasicLazyTree
import org.jetbrains.jewel.foundation.tree.DefaultTreeViewKeyActions
import org.jetbrains.jewel.foundation.tree.KeyBindingScopedActions
import org.jetbrains.jewel.foundation.tree.InitialNodeStatus
import org.jetbrains.jewel.foundation.tree.KeyBindingActions
import org.jetbrains.jewel.foundation.tree.Tree
import org.jetbrains.jewel.foundation.tree.TreeElementState
import org.jetbrains.jewel.foundation.tree.TreeState
Expand All @@ -22,20 +21,22 @@ import org.jetbrains.jewel.styling.LazyTreeStyle
@Composable
fun <T> LazyTree(
tree: Tree<T>,
initialNodeStatus: InitialNodeStatus = InitialNodeStatus.Close(),
resourceLoader: ResourceLoader,
modifier: Modifier = Modifier,
onElementClick: (Tree.Element<T>) -> Unit,
treeState: TreeState = rememberTreeState(),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
onElementDoubleClick: (Tree.Element<T>) -> Unit = { },
keyActions: KeyBindingScopedActions = DefaultTreeViewKeyActions(treeState),
onElementDoubleClick: (Tree.Element<T>) -> Unit = {},
onSelectionChange: (List<Tree.Element<T>>) -> Unit = {},
keyActions: KeyBindingActions = DefaultTreeViewKeyActions(treeState),
style: LazyTreeStyle = IntelliJTheme.treeStyle,
nodeContent: @Composable SelectableLazyItemScope.(Tree.Element<T>) -> Unit,
nodeContent: @Composable (SelectableLazyItemScope.(Tree.Element<T>) -> Unit),
) {
val colors = style.colors
val metrics = style.metrics
BasicLazyTree(
tree = tree,
initialNodeStatus = initialNodeStatus,
onElementClick = onElementClick,
elementBackgroundFocused = colors.elementBackgroundFocused,
elementBackgroundSelectedFocused = colors.elementBackgroundSelectedFocused,
Expand All @@ -49,26 +50,25 @@ fun <T> LazyTree(
treeState = treeState,
modifier = modifier,
onElementDoubleClick = onElementDoubleClick,
interactionSource = interactionSource,
onSelectionChange = onSelectionChange,
keyActions = keyActions,
chevronContent = { elementState ->
val painterProvider = style.icons.nodeChevron(elementState.isExpanded)
val painter by painterProvider.getPainter(elementState, resourceLoader)
Icon(painter = painter, contentDescription = null)
},
nodeContent = {
CompositionLocalProvider(
LocalContentColor provides (
style.colors.contentFor(
TreeElementState.of(
isFocused,
isSelected,
false,
),
).value
.takeOrElse { LocalContentColor.current }
) {
CompositionLocalProvider(
LocalContentColor provides (
style.colors.contentFor(
TreeElementState.of(
focused = isActive,
selected = isSelected,
expanded = false,
),
) { nodeContent(it) }
},
)
).value
.takeOrElse { LocalContentColor.current }
),
) { nodeContent(it) }
}
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/jetbrains/jewel/Scrollbars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun TabStripHorizontalScrollbar(
style: ScrollbarStyle = IntelliJTheme.scrollbarStyle,
) {
val shape by remember { mutableStateOf(RoundedCornerShape(style.metrics.thumbCornerSize)) }
val hoverDurationMillis by remember { mutableStateOf(style.hoverDuration.toInt(DurationUnit.MILLISECONDS)) }
val hoverDurationMillis by remember { mutableStateOf(style.hoverDuration.inWholeMilliseconds.toInt()) }

CompositionLocalProvider(
LocalScrollbarStyle provides ComposeScrollbarStyle(
Expand Down
Loading