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. 8
      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 {
// __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")
// __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
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 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
@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(
if (state.isExpanded) Icons.Default.ArrowBack else Icons.Default.ArrowForward,
contentDescription = if (state.isExpanded) "Collapse" else "Expand",
tint = AmbientContentColor.current,
modifier = Modifier
.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
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.FontWeight
import androidx.compose.ui.text.font.fontFamily
import org.jetbrains.codeviewer.platform.font
import org.jetbrains.codeviewer.platform.Font
object Fonts {
@Composable
fun jetbrainsMono() = fontFamily(
font(
fun jetbrainsMono() = FontFamily(
Font(
"JetBrains Mono",
"jetbrainsmono_regular",
FontWeight.Normal,
FontStyle.Normal
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_italic",
FontWeight.Normal,
FontStyle.Italic
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_bold",
FontWeight.Bold,
FontStyle.Normal
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_bold_italic",
FontWeight.Bold,
FontStyle.Italic
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_extrabold",
FontWeight.ExtraBold,
FontStyle.Normal
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_extrabold_italic",
FontWeight.ExtraBold,
FontStyle.Italic
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_medium",
FontWeight.Medium,
FontStyle.Normal
),
font(
Font(
"JetBrains Mono",
"jetbrainsmono_medium_italic",
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)) {
Icon(
Icons.Default.Code,
contentDescription = null,
tint = AmbientContentColor.current.copy(alpha = 0.60f),
modifier = Modifier.align(Alignment.CenterHorizontally)
)

8
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) {
Icon(
Icons.Default.Close, tint = AmbientContentColor.current, modifier = Modifier
Icons.Default.Close,
tint = AmbientContentColor.current,
contentDescription = "Close",
modifier = Modifier
.size(24.dp)
.padding(4.dp)
.clickable {
close()
})
}
)
} else {
Box(
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.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.drawOpacity
import androidx.compose.ui.platform.AmbientDensity
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 org.jetbrains.codeviewer.platform.SelectionContainer
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) {
is FileTree.ItemType.Folder -> when {
!type.canExpand -> Unit
type.isExpanded -> Icon(Icons.Default.KeyboardArrowDown, tint = AmbientContentColor.current)
else -> Icon(Icons.Default.KeyboardArrowRight, tint = AmbientContentColor.current)
type.isExpanded -> Icon(
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) {
"kt" -> Icon(Icons.Default.Code, tint = Color(0xFF3E86A0))
"xml" -> Icon(Icons.Default.Code, tint = Color(0xFFC19C5F))
"txt" -> Icon(Icons.Default.Description, tint = Color(0xFF87939A))
"md" -> Icon(Icons.Default.Description, tint = Color(0xFF87939A))
"gitignore" -> Icon(Icons.Default.BrokenImage, tint = Color(0xFF87939A))
"gradle" -> Icon(Icons.Default.Build, tint = Color(0xFF87939A))
"kts" -> Icon(Icons.Default.Build, tint = Color(0xFF3E86A0))
"properties" -> Icon(Icons.Default.Settings, tint = Color(0xFF62B543))
"bat" -> Icon(Icons.Default.Launch, tint = Color(0xFF87939A))
else -> Icon(Icons.Default.TextSnippet, tint = Color(0xFF87939A))
"kt" -> Icon(Icons.Default.Code, contentDescription = null, tint = Color(0xFF3E86A0))
"xml" -> Icon(Icons.Default.Code, contentDescription = null, tint = Color(0xFFC19C5F))
"txt" -> Icon(Icons.Default.Description, contentDescription = null, tint = Color(0xFF87939A))
"md" -> Icon(Icons.Default.Description, contentDescription = null, tint = Color(0xFF87939A))
"gitignore" -> Icon(Icons.Default.BrokenImage, contentDescription = null, tint = Color(0xFF87939A))
"gradle" -> Icon(Icons.Default.Build, contentDescription = null, tint = Color(0xFF87939A))
"kts" -> Icon(Icons.Default.Build, contentDescription = null, tint = Color(0xFF3E86A0))
"properties" -> Icon(Icons.Default.Settings, contentDescription = null, tint = Color(0xFF62B543))
"bat" -> Icon(Icons.Default.Launch, contentDescription = null, 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.Modifier
import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.*
import org.jetbrains.codeviewer.ui.common.Settings
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 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
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font =
androidx.compose.ui.text.platform.font(name, "font/$res.ttf", weight, style)
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font =
androidx.compose.ui.text.platform.Font("font/$res.ttf", weight, style)
Loading…
Cancel
Save