Browse Source

Migrate to 0.3.0-build146 (codeviewer)

pull/328/head
Igor Demin 4 years ago
parent
commit
930d807306
  1. 4
      examples/codeviewer/build.gradle.kts
  2. 4
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt
  3. 2
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt
  4. 1
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt
  5. 22
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt
  6. 1
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt
  7. 16
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt
  8. 6
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt
  9. 28
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt
  10. 7
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt
  11. 4
      examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

4
examples/codeviewer/build.gradle.kts

@ -9,10 +9,10 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build141") classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build146")
classpath("com.android.tools.build:gradle:4.0.1") classpath("com.android.tools.build:gradle:4.0.1")
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.4.21")) classpath(kotlin("gradle-plugin", version = "1.4.21-2"))
} }
} }

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

@ -24,8 +24,8 @@ actual suspend fun imageFromUrl(url: String): ImageBitmap {
} }
@Composable @Composable
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font {
val context = AmbientContext.current val context = AmbientContext.current
val id = context.resources.getIdentifier(res, "font", context.packageName) val id = context.resources.getIdentifier(res, "font", context.packageName)
return androidx.compose.ui.text.font.font(id, weight, style) return androidx.compose.ui.text.font.Font(id, weight, style)
} }

2
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

@ -12,4 +12,4 @@ expect fun imageResource(res: String): ImageBitmap
expect suspend fun imageFromUrl(url: String): ImageBitmap expect suspend fun imageFromUrl(url: String): ImageBitmap
@Composable @Composable
expect fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font expect fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font

1
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt

@ -91,6 +91,7 @@ private fun ResizablePanel(
Icon( Icon(
if (state.isExpanded) Icons.Default.ArrowBack else Icons.Default.ArrowForward, if (state.isExpanded) Icons.Default.ArrowBack else Icons.Default.ArrowForward,
contentDescription = if (state.isExpanded) "Collapse" else "Expand",
tint = AmbientContentColor.current, tint = AmbientContentColor.current,
modifier = Modifier modifier = Modifier
.padding(top = 4.dp) .padding(top = 4.dp)

22
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt

@ -1,60 +1,60 @@
package org.jetbrains.codeviewer.ui.common package org.jetbrains.codeviewer.ui.common
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.font.fontFamily import org.jetbrains.codeviewer.platform.Font
import org.jetbrains.codeviewer.platform.font
object Fonts { object Fonts {
@Composable @Composable
fun jetbrainsMono() = fontFamily( fun jetbrainsMono() = FontFamily(
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_regular", "jetbrainsmono_regular",
FontWeight.Normal, FontWeight.Normal,
FontStyle.Normal FontStyle.Normal
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_italic", "jetbrainsmono_italic",
FontWeight.Normal, FontWeight.Normal,
FontStyle.Italic FontStyle.Italic
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_bold", "jetbrainsmono_bold",
FontWeight.Bold, FontWeight.Bold,
FontStyle.Normal FontStyle.Normal
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_bold_italic", "jetbrainsmono_bold_italic",
FontWeight.Bold, FontWeight.Bold,
FontStyle.Italic FontStyle.Italic
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_extrabold", "jetbrainsmono_extrabold",
FontWeight.ExtraBold, FontWeight.ExtraBold,
FontStyle.Normal FontStyle.Normal
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_extrabold_italic", "jetbrainsmono_extrabold_italic",
FontWeight.ExtraBold, FontWeight.ExtraBold,
FontStyle.Italic FontStyle.Italic
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_medium", "jetbrainsmono_medium",
FontWeight.Medium, FontWeight.Medium,
FontStyle.Normal FontStyle.Normal
), ),
font( Font(
"JetBrains Mono", "JetBrains Mono",
"jetbrainsmono_medium_italic", "jetbrainsmono_medium_italic",
FontWeight.Medium, FontWeight.Medium,

1
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt

@ -20,6 +20,7 @@ fun EditorEmptyView() = Box(Modifier.fillMaxSize()) {
Column(Modifier.align(Alignment.Center)) { Column(Modifier.align(Alignment.Center)) {
Icon( Icon(
Icons.Default.Code, Icons.Default.Code,
contentDescription = null,
tint = AmbientContentColor.current.copy(alpha = 0.60f), tint = AmbientContentColor.current.copy(alpha = 0.60f),
modifier = Modifier.align(Alignment.CenterHorizontally) modifier = Modifier.align(Alignment.CenterHorizontally)
) )

16
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt

@ -55,12 +55,16 @@ fun EditorTabView(model: Editor) = Surface(
if (close != null) { if (close != null) {
Icon( Icon(
Icons.Default.Close, tint = AmbientContentColor.current, modifier = Modifier Icons.Default.Close,
.size(24.dp) tint = AmbientContentColor.current,
.padding(4.dp) contentDescription = "Close",
.clickable { modifier = Modifier
close() .size(24.dp)
}) .padding(4.dp)
.clickable {
close()
}
)
} else { } else {
Box( Box(
modifier = Modifier modifier = Modifier

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

@ -14,10 +14,12 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.drawOpacity
import androidx.compose.ui.platform.AmbientDensity import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.selection.DisableSelection import androidx.compose.ui.selection.DisableSelection
import androidx.compose.ui.text.* import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import org.jetbrains.codeviewer.platform.SelectionContainer import org.jetbrains.codeviewer.platform.SelectionContainer
import org.jetbrains.codeviewer.platform.VerticalScrollbar import org.jetbrains.codeviewer.platform.VerticalScrollbar

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

@ -109,20 +109,24 @@ private fun FileItemIcon(modifier: Modifier, model: FileTree.Item) = Box(modifie
when (val type = model.type) { when (val type = model.type) {
is FileTree.ItemType.Folder -> when { is FileTree.ItemType.Folder -> when {
!type.canExpand -> Unit !type.canExpand -> Unit
type.isExpanded -> Icon(Icons.Default.KeyboardArrowDown, tint = AmbientContentColor.current) type.isExpanded -> Icon(
else -> Icon(Icons.Default.KeyboardArrowRight, tint = AmbientContentColor.current) Icons.Default.KeyboardArrowDown, contentDescription = null, tint = AmbientContentColor.current
)
else -> Icon(
Icons.Default.KeyboardArrowRight, contentDescription = null, tint = AmbientContentColor.current
)
} }
is FileTree.ItemType.File -> when (type.ext) { is FileTree.ItemType.File -> when (type.ext) {
"kt" -> Icon(Icons.Default.Code, tint = Color(0xFF3E86A0)) "kt" -> Icon(Icons.Default.Code, contentDescription = null, tint = Color(0xFF3E86A0))
"xml" -> Icon(Icons.Default.Code, tint = Color(0xFFC19C5F)) "xml" -> Icon(Icons.Default.Code, contentDescription = null, tint = Color(0xFFC19C5F))
"txt" -> Icon(Icons.Default.Description, tint = Color(0xFF87939A)) "txt" -> Icon(Icons.Default.Description, contentDescription = null, tint = Color(0xFF87939A))
"md" -> Icon(Icons.Default.Description, tint = Color(0xFF87939A)) "md" -> Icon(Icons.Default.Description, contentDescription = null, tint = Color(0xFF87939A))
"gitignore" -> Icon(Icons.Default.BrokenImage, tint = Color(0xFF87939A)) "gitignore" -> Icon(Icons.Default.BrokenImage, contentDescription = null, tint = Color(0xFF87939A))
"gradle" -> Icon(Icons.Default.Build, tint = Color(0xFF87939A)) "gradle" -> Icon(Icons.Default.Build, contentDescription = null, tint = Color(0xFF87939A))
"kts" -> Icon(Icons.Default.Build, tint = Color(0xFF3E86A0)) "kts" -> Icon(Icons.Default.Build, contentDescription = null, tint = Color(0xFF3E86A0))
"properties" -> Icon(Icons.Default.Settings, tint = Color(0xFF62B543)) "properties" -> Icon(Icons.Default.Settings, contentDescription = null, tint = Color(0xFF62B543))
"bat" -> Icon(Icons.Default.Launch, tint = Color(0xFF87939A)) "bat" -> Icon(Icons.Default.Launch, contentDescription = null, tint = Color(0xFF87939A))
else -> Icon(Icons.Default.TextSnippet, tint = Color(0xFF87939A)) else -> Icon(Icons.Default.TextSnippet, contentDescription = null, tint = Color(0xFF87939A))
} }
} }
} }

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

@ -9,10 +9,7 @@ import androidx.compose.runtime.Providers
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.AmbientDensity import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.*
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
import androidx.compose.ui.unit.sp
import org.jetbrains.codeviewer.ui.common.Settings import org.jetbrains.codeviewer.ui.common.Settings
private val MinFontSize = 6.sp private val MinFontSize = 6.sp
@ -46,3 +43,5 @@ fun StatusBar(settings: Settings) = Box(
} }
private fun Density.scale(scale: Float) = Density(density * scale, fontScale * scale) private fun Density.scale(scale: Float) = Density(density * scale, fontScale * scale)
private operator fun TextUnit.minus(other: TextUnit) = (value - other.value).sp
private operator fun TextUnit.div(other: TextUnit) = value / other.value

4
examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

@ -21,5 +21,5 @@ actual suspend fun imageFromUrl(url: String): ImageBitmap = withContext(Dispatch
} }
@Composable @Composable
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font = actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font =
androidx.compose.ui.text.platform.font(name, "font/$res.ttf", weight, style) androidx.compose.ui.text.platform.Font("font/$res.ttf", weight, style)
Loading…
Cancel
Save