Browse Source

Codeviewer. 1.0.0-beta1

pull/1312/head
Igor Demin 3 years ago
parent
commit
6e298d69c1
  1. 6
      examples/codeviewer/android/build.gradle.kts
  2. 1
      examples/codeviewer/android/src/main/AndroidManifest.xml
  3. 4
      examples/codeviewer/build.gradle.kts
  4. 4
      examples/codeviewer/common/build.gradle.kts
  5. 4
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt
  6. 6
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt
  7. 4
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt
  8. 6
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt
  9. 7
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt
  10. 7
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt
  11. 8
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt
  12. 7
      examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt
  13. 7
      examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt
  14. 2
      examples/codeviewer/desktop/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt

6
examples/codeviewer/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
} }
android { android {
compileSdkVersion(30) compileSdkVersion(31)
defaultConfig { defaultConfig {
minSdkVersion(26) minSdkVersion(26)
targetSdkVersion(30) targetSdkVersion(31)
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
} }
@ -22,5 +22,5 @@ android {
dependencies { dependencies {
implementation(project(":common")) implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0-alpha02") implementation("androidx.activity:activity-compose:1.3.1")
} }

1
examples/codeviewer/android/src/main/AndroidManifest.xml

@ -10,6 +10,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity <activity
android:exported="true"
android:name="MainActivity" android:name="MainActivity"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>

4
examples/codeviewer/build.gradle.kts

@ -8,8 +8,8 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.0-master-build423") classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-beta1")
classpath("com.android.tools.build:gradle:4.0.1") classpath("com.android.tools.build:gradle:4.2.2")
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.5.31")) classpath(kotlin("gradle-plugin", version = "1.5.31"))
} }

4
examples/codeviewer/common/build.gradle.kts

@ -36,11 +36,11 @@ kotlin {
} }
android { android {
compileSdkVersion(30) compileSdkVersion(31)
defaultConfig { defaultConfig {
minSdkVersion(21) minSdkVersion(21)
targetSdkVersion(30) targetSdkVersion(31)
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
} }

4
examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt

@ -15,7 +15,5 @@ actual fun VerticalScrollbar(
@Composable @Composable
actual fun VerticalScrollbar( actual fun VerticalScrollbar(
modifier: Modifier, modifier: Modifier,
scrollState: LazyListState, scrollState: LazyListState
itemCount: Int,
averageItemSize: Dp
) = Unit ) = Unit

6
examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt

@ -1,6 +0,0 @@
package org.jetbrains.codeviewer.platform
import androidx.compose.runtime.Composable
@Composable
actual fun PlatformTheme(content: @Composable () -> Unit) = content()

4
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt

@ -15,7 +15,5 @@ expect fun VerticalScrollbar(
@Composable @Composable
expect fun VerticalScrollbar( expect fun VerticalScrollbar(
modifier: Modifier, modifier: Modifier,
scrollState: LazyListState, scrollState: LazyListState
itemCount: Int,
averageItemSize: Dp
) )

6
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt

@ -1,6 +0,0 @@
package org.jetbrains.codeviewer.platform
import androidx.compose.runtime.Composable
@Composable
expect fun PlatformTheme(content: @Composable () -> Unit)

7
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt

@ -6,7 +6,6 @@ import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import org.jetbrains.codeviewer.platform.HomeFolder import org.jetbrains.codeviewer.platform.HomeFolder
import org.jetbrains.codeviewer.platform.PlatformTheme
import org.jetbrains.codeviewer.ui.common.AppTheme import org.jetbrains.codeviewer.ui.common.AppTheme
import org.jetbrains.codeviewer.ui.common.Settings import org.jetbrains.codeviewer.ui.common.Settings
import org.jetbrains.codeviewer.ui.editor.Editors import org.jetbrains.codeviewer.ui.editor.Editors
@ -28,10 +27,8 @@ fun MainView() {
MaterialTheme( MaterialTheme(
colors = AppTheme.colors.material colors = AppTheme.colors.material
) { ) {
PlatformTheme { Surface {
Surface { CodeViewerView(codeViewer)
CodeViewerView(codeViewer)
}
} }
} }
} }

7
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt

@ -74,14 +74,13 @@ private fun Lines(lines: Editor.Lines, settings: Settings) = with(LocalDensity.c
Box(Modifier.fillMaxSize()) { Box(Modifier.fillMaxSize()) {
val scrollState = rememberLazyListState() val scrollState = rememberLazyListState()
val lineHeight = settings.fontSize.toDp() * 1.6f
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
state = scrollState state = scrollState
) { ) {
items(lines.size) { index -> items(lines.size) { index ->
Box(Modifier.height(lineHeight)) { Box(Modifier.height(settings.fontSize.toDp() * 1.6f)) {
Line(Modifier.align(Alignment.CenterStart), maxNum, lines[index], settings) Line(Modifier.align(Alignment.CenterStart), maxNum, lines[index], settings)
} }
} }
@ -89,9 +88,7 @@ private fun Lines(lines: Editor.Lines, settings: Settings) = with(LocalDensity.c
VerticalScrollbar( VerticalScrollbar(
Modifier.align(Alignment.CenterEnd), Modifier.align(Alignment.CenterEnd),
scrollState, scrollState
lines.size,
lineHeight
) )
} }
} }

8
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt

@ -49,23 +49,19 @@ fun FileTreeView(model: FileTree) = Surface(
with(LocalDensity.current) { with(LocalDensity.current) {
Box { Box {
val scrollState = rememberLazyListState() val scrollState = rememberLazyListState()
val fontSize = 14.sp
val lineHeight = fontSize.toDp() * 1.5f
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize().withoutWidthConstraints(), modifier = Modifier.fillMaxSize().withoutWidthConstraints(),
state = scrollState state = scrollState
) { ) {
items(model.items.size) { items(model.items.size) {
FileTreeItemView(fontSize, lineHeight, model.items[it]) FileTreeItemView(14.sp, 14.sp.toDp() * 1.5f, model.items[it])
} }
} }
VerticalScrollbar( VerticalScrollbar(
Modifier.align(Alignment.CenterEnd), Modifier.align(Alignment.CenterEnd),
scrollState, scrollState
model.items.size,
lineHeight
) )
} }
} }

7
examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt

@ -1,12 +1,10 @@
package org.jetbrains.codeviewer.platform package org.jetbrains.codeviewer.platform
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.rememberScrollbarAdapter import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
@Composable @Composable
actual fun VerticalScrollbar( actual fun VerticalScrollbar(
@ -17,13 +15,10 @@ actual fun VerticalScrollbar(
modifier modifier
) )
@OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
actual fun VerticalScrollbar( actual fun VerticalScrollbar(
modifier: Modifier, modifier: Modifier,
scrollState: LazyListState, scrollState: LazyListState
itemCount: Int,
averageItemSize: Dp
) = androidx.compose.foundation.VerticalScrollbar( ) = androidx.compose.foundation.VerticalScrollbar(
rememberScrollbarAdapter(scrollState), rememberScrollbarAdapter(scrollState),
modifier modifier

7
examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt

@ -1,7 +0,0 @@
package org.jetbrains.codeviewer.platform
import androidx.compose.desktop.DesktopMaterialTheme
import androidx.compose.runtime.Composable
@Composable
actual fun PlatformTheme(content: @Composable () -> Unit) = DesktopMaterialTheme(content = content)

2
examples/codeviewer/desktop/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt

@ -1,6 +1,5 @@
package org.jetbrains.codeviewer package org.jetbrains.codeviewer
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.res.loadImageBitmap import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.useResource import androidx.compose.ui.res.useResource
@ -9,7 +8,6 @@ import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
import org.jetbrains.codeviewer.ui.MainView import org.jetbrains.codeviewer.ui.MainView
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication( fun main() = singleWindowApplication(
title = "Code Viewer", title = "Code Viewer",
state = WindowState(width = 1280.dp, height = 768.dp), state = WindowState(width = 1280.dp, height = 768.dp),

Loading…
Cancel
Save