-
-
Notifications
You must be signed in to change notification settings - Fork 446
locale: add translations for auth rate limiting and scrollbar settings #354
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1200292
locale: add translations for auth rate limiting and scrollbar settings
rainxchzed 9d0cf75
feat: implement optional scrollbar support desktop platform
rainxchzed 00e5fa6
locale: add translations for the "scrollbar" UI option
rainxchzed d0b485d
Update core/presentation/src/androidMain/kotlin/zed/rainxch/core/pres…
rainxchzed d08de58
fix: improve scrollbar container layout and scrolling logic
rainxchzed 725ffd8
Merge remote-tracking branch 'origin/desktop-scrollbar-impl' into des…
rainxchzed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...androidMain/kotlin/zed/rainxch/core/presentation/components/ScrollbarContainer.android.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package zed.rainxch.core.presentation.components | ||
|
|
||
| import androidx.compose.foundation.lazy.LazyListState | ||
| import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
|
|
||
| @Composable | ||
| actual fun ScrollbarContainer( | ||
| listState: LazyListState, | ||
| enabled: Boolean, | ||
| modifier: Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) { | ||
| content() | ||
| } | ||
|
|
||
| @Composable | ||
| actual fun ScrollbarContainer( | ||
| gridState: LazyStaggeredGridState, | ||
| enabled: Boolean, | ||
| modifier: Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) { | ||
| content() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...tion/src/commonMain/kotlin/zed/rainxch/core/presentation/components/ScrollbarContainer.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package zed.rainxch.core.presentation.components | ||
|
|
||
| import androidx.compose.foundation.lazy.LazyListState | ||
| import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
|
|
||
| /** | ||
| * Wraps content with a platform-appropriate scrollbar. | ||
| * On Desktop (JVM), adds a VerticalScrollbar when [enabled] is true. | ||
| * On Android, renders only the [content] (no scrollbar). | ||
| */ | ||
| @Composable | ||
| expect fun ScrollbarContainer( | ||
| listState: LazyListState, | ||
| enabled: Boolean, | ||
| modifier: Modifier = Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) | ||
|
|
||
| /** | ||
| * Overload for [LazyStaggeredGridState]. | ||
| */ | ||
| @Composable | ||
| expect fun ScrollbarContainer( | ||
| gridState: LazyStaggeredGridState, | ||
| enabled: Boolean, | ||
| modifier: Modifier = Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) |
9 changes: 9 additions & 0 deletions
9
...ation/src/commonMain/kotlin/zed/rainxch/core/presentation/locals/LocalScrollbarEnabled.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package zed.rainxch.core.presentation.locals | ||
|
|
||
| import androidx.compose.runtime.compositionLocalOf | ||
|
|
||
| /** | ||
| * CompositionLocal providing whether the scrollbar should be shown. | ||
| * Defaults to false (no scrollbar). | ||
| */ | ||
| val LocalScrollbarEnabled = compositionLocalOf { false } |
128 changes: 128 additions & 0 deletions
128
...ion/src/jvmMain/kotlin/zed/rainxch/core/presentation/components/ScrollbarContainer.jvm.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package zed.rainxch.core.presentation.components | ||
|
|
||
| import androidx.compose.foundation.LocalScrollbarStyle | ||
| import androidx.compose.foundation.ScrollbarAdapter | ||
| import androidx.compose.foundation.VerticalScrollbar | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxHeight | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.lazy.LazyListState | ||
| import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState | ||
| import androidx.compose.foundation.rememberScrollbarAdapter | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| @Composable | ||
| actual fun ScrollbarContainer( | ||
| listState: LazyListState, | ||
| enabled: Boolean, | ||
| modifier: Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) { | ||
| if (!enabled) { | ||
| content() | ||
| return | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| Box(modifier = modifier.padding(start = 8.dp)) { | ||
| val scrollbarStyle = | ||
| LocalScrollbarStyle.current.copy( | ||
| shape = RoundedCornerShape(32.dp), | ||
| unhoverColor = MaterialTheme.colorScheme.onSurface, | ||
| hoverColor = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
| content() | ||
| VerticalScrollbar( | ||
| adapter = rememberScrollbarAdapter(listState), | ||
| modifier = | ||
| Modifier | ||
| .fillMaxHeight() | ||
| .align(Alignment.CenterEnd), | ||
| style = scrollbarStyle, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| actual fun ScrollbarContainer( | ||
| gridState: LazyStaggeredGridState, | ||
| enabled: Boolean, | ||
| modifier: Modifier, | ||
| content: @Composable () -> Unit, | ||
| ) { | ||
| if (!enabled) { | ||
| content() | ||
| return | ||
| } | ||
| Box(modifier = modifier.padding(start = 8.dp)) { | ||
| val scrollbarStyle = | ||
| LocalScrollbarStyle.current.copy( | ||
| shape = RoundedCornerShape(32.dp), | ||
| unhoverColor = MaterialTheme.colorScheme.onSurface, | ||
| hoverColor = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| ) | ||
|
|
||
| content() | ||
| val adapter = remember(gridState) { StaggeredGridScrollbarAdapter(gridState) } | ||
| VerticalScrollbar( | ||
| adapter = adapter, | ||
| modifier = | ||
| Modifier | ||
| .fillMaxHeight() | ||
| .align(Alignment.CenterEnd), | ||
| style = scrollbarStyle, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Custom [ScrollbarAdapter] for [LazyStaggeredGridState] since Compose Desktop | ||
| * does not provide a built-in [rememberScrollbarAdapter] overload for staggered grids. | ||
| */ | ||
| private class StaggeredGridScrollbarAdapter( | ||
| private val gridState: LazyStaggeredGridState, | ||
| ) : ScrollbarAdapter { | ||
| override val scrollOffset: Float | ||
| get() { | ||
| val layoutInfo = gridState.layoutInfo | ||
| val firstVisible = layoutInfo.visibleItemsInfo.firstOrNull() ?: return 0f | ||
| val fraction = firstVisible.index.toFloat() / maxOf(layoutInfo.totalItemsCount, 1) | ||
| return fraction * estimatedContentSize() - firstVisible.offset.y.toFloat() | ||
| } | ||
|
|
||
| override fun maxScrollOffset(containerSize: Int): Float = (estimatedContentSize() - containerSize).coerceAtLeast(0f) | ||
|
|
||
| override suspend fun scrollTo( | ||
| containerSize: Int, | ||
| scrollOffset: Float, | ||
| ) { | ||
| val totalContent = estimatedContentSize() | ||
| val layoutInfo = gridState.layoutInfo | ||
| if (layoutInfo.totalItemsCount == 0 || totalContent <= 0f) return | ||
| val fraction = scrollOffset / totalContent | ||
| val targetIndex = | ||
| (fraction * layoutInfo.totalItemsCount) | ||
| .toInt() | ||
| .coerceIn(0, maxOf(layoutInfo.totalItemsCount - 1, 0)) | ||
| gridState.scrollToItem(targetIndex) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private fun estimatedContentSize(): Float { | ||
| val layoutInfo = gridState.layoutInfo | ||
| if (layoutInfo.totalItemsCount == 0) return 0f | ||
| val visibleItems = layoutInfo.visibleItemsInfo | ||
| if (visibleItems.isEmpty()) return 0f | ||
| val avgHeight = visibleItems.map { it.size.height }.average().toFloat() | ||
| val laneCount = | ||
| maxOf( | ||
| visibleItems.maxOf { it.lane + 1 }, | ||
| 1, | ||
| ) | ||
| val rows = (layoutInfo.totalItemsCount + laneCount - 1) / laneCount | ||
| return rows * avgHeight + layoutInfo.beforeContentPadding + layoutInfo.afterContentPadding | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.